breenie / silex-doctrine-migrations-provider

A doctrine migrations provider for Silex and Pimple
MIT License
21 stars 11 forks source link

silex-doctrine-migrations-provider

A doctrine migrations service provider for Silex 2.x or Pimple 3.x.

Installation

Install the provider through Composer:

composer require kurl/silex-doctrine-migrations-provider

Usage

Parameters

These are the configuration parameters you could configure for the provider:

Services

The service provider registers the following services which you could use:

There are also a few other services which the provider uses internally and they are exposed so you could extend or override them with the lazy loading of Pimple:

You can register the provider and configure it like so:

<?php

$app->register(
    new \Kurl\Silex\Provider\DoctrineMigrationsProvider(),
    array(
        'migrations.directory' => __DIR__ . '/../path/to/migrations',
        'migrations.name' => 'Acme Migrations',
        'migrations.namespace' => 'Acme\Migrations',
        'migrations.table_name' => 'acme_migrations',
    )
);

Silex

You can pass an optional instance of Symfony\Component\Console\Application to the constructor of the provider. Alternatively you can set the instance of your Console application to $app['console']. If the provider can find the Console application instance it is able to register the commands and helper set for you.

The provider implements `Silex\Api\BootableProviderInterface, so if you use the provider with Silex, booting the application would register the commands for you:

<?php

$console = new \Symfony\Component\Console\Application();

$app->register(
    new \Kurl\Silex\Provider\DoctrineMigrationsProvider($console),
    array(
        'migrations.directory' => __DIR__ . '/../path/to/migrations',
        'migrations.namespace' => 'Acme\Migrations',
    )
);

$app->boot();
$console->run();

Pimple

If you use the provider with Pimple without using Silex, then you'd need to register the helper set and the commands to your Console application yourself. This is made very easy by the provider as it already registered all the needed services:

<?php

$console = new \Symfony\Component\Console\Application();

$app->register(
    new \Kurl\Silex\Provider\DoctrineMigrationsProvider(),
    array(
        'migrations.directory' => __DIR__ . '/../path/to/migrations',
        'migrations.namespace' => 'Acme\Migrations',
    )
);

// Register helper set and commands from the `DoctrineMigrationsProvider`
$console->setHelperSet($app['migrations.em_helper_set']);
$console->addCommands($app['migrations.commands']);

$console->run();

Code coverage reports

$ bin/phpunit --coverage-html build/coverage --coverage-clover build/logs/clover.xml --log-junit build/logs/phpunit.xml

That was it!