PHPackages                             tebru/dynamo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tebru/dynamo

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tebru/dynamo
============

Generates PHP classes from an interface based on doctrine annotations

v0.3.3(10y ago)026.8k21MITPHPPHP &gt;= 5.4

Since Aug 17Pushed 8y ago1 watchersCompare

[ Source](https://github.com/tebru/dynamo)[ Packagist](https://packagist.org/packages/tebru/dynamo)[ RSS](/packages/tebru-dynamo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (9)Versions (12)Used By (1)

[![Build Status](https://camo.githubusercontent.com/57e7b251fffc4d9f7d765a690f9800049e2bb8aba55f23e880fc08e2939cbc33/68747470733a2f2f7472617669732d63692e6f72672f74656272752f64796e616d6f2e7376673f6272616e63683d76302e312e30)](https://travis-ci.org/tebru/dynamo)[![Coverage Status](https://camo.githubusercontent.com/5bf09a0c0e47c773f0a426599deca66af36c937621525b3f7a58835c3ef03618/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f74656272752f64796e616d6f2f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/tebru/dynamo?branch=master)

Dynamo
======

[](#dynamo)

This library allows you to take an interface annotated with Doctrine annotations and generate a class. It handles all of the parsing, and provides events to hook into in order to create the method body based on the annotations.

Installation
------------

[](#installation)

```
composer require tebru/dynamo
```

Usage
-----

[](#usage)

Create a new generator object using the builder

```
$generator = \Tebru\Dynamo\Generator::builder()
    ->namespacePrefix('My\Custom\Library')
    ->setCacheDir('path/to/cache/vendor-name')
    ->build();
```

There are many different options to use with the builder, however, for most all cases, the defaults outside of the namespace prefix and cache dir will be fine.

The namespace prefix is required in order to get around class name conflicts. The generator uses the full interface name plus the prefix as the generated class name. The prefix defaults to `Dynamo`.

The cache directory defaults to `/system/dir/dynamo`

After you have a generator, you can pass your interface name into it and it will create a file in your cache directory

```
$generator->createAndWrite(MyInterface::class);
```

Events
------

[](#events)

It's essential to subscribe to at least the `MethodEvent` as it is what allows you to add a method body to the method. The `MethodModel` and `AnnotationCollection` are available on the event.

The two other events are `StartEvent` and `EndEvent`, both of which provide access to the `ClassModel`.

```
$eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$eventDispatcher->addListener(new MethodListener());

$generator = \Tebru\Dynamo\Generator::builder()
    ->namespacePrefix('My\Custom\Library')
    ->setCacheDir('path/to/cache/vendor-name')
    ->setEventDispatcher($eventDispatcher)
    ->build();
```

Sample listener
---------------

[](#sample-listener)

Here is a skeleton of a method listener

```
