Created
May 5, 2018 23:00
-
-
Save FadelChafai/8b8369b41756358fe5d2ade697a2c0e7 to your computer and use it in GitHub Desktop.
Zend Expressive AND Doctrine Migrations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
chdir(dirname(__DIR__)); | |
require 'vendor/autoload.php'; | |
/** | |
* Self-called anonymous function that creates its own scope and keep the global namespace clean. | |
*/ | |
return call_user_func(function () { | |
/** @var \Interop\Container\ContainerInterface \$container */ | |
$container = require 'config/container.php'; | |
/** @var \Doctrine\ORM\EntityManager $entityManager */ | |
$entityManager = $container->get(\Doctrine\ORM\EntityManager::class); | |
$migrationsConfiguration = $container->get('config')['doctrine']['migrations_configuration']['orm_default']; | |
$configuration = new \Doctrine\DBAL\Migrations\Configuration\Configuration($entityManager->getConnection()); | |
$configuration->setMigrationsDirectory($migrationsConfiguration['directory']); | |
$configuration->setName($migrationsConfiguration['name']); | |
$configuration->setMigrationsNamespace($migrationsConfiguration['namespace']); | |
$configuration->setMigrationsTableName($migrationsConfiguration['table']); | |
$configuration->createMigrationTable(); | |
return new \Symfony\Component\Console\Helper\HelperSet([ | |
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($entityManager), | |
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($entityManager->getConnection()), | |
'configuration' => new \Doctrine\DBAL\Migrations\Tools\Console\Helper\ConfigurationHelper($entityManager->getConnection(), $configuration) | |
]); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'dependencies' => [ | |
'factories' => [ | |
\Doctrine\ORM\EntityManager::class => \ContainerInteropDoctrine\EntityManagerFactory::class, | |
], | |
], | |
'doctrine' => [ | |
'driver' => [ | |
'orm_default' => [ | |
'class' => \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain::class, | |
'drivers' => [], | |
], | |
], | |
'migrations_configuration' => [ | |
'orm_default' => [ | |
'directory' => 'data/Migrations', | |
'name' => 'Doctrine Database Migrations', | |
'namespace' => 'Migrations', | |
'table' => 'migrations' | |
], | |
], | |
], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySqlDriver; | |
return [ | |
'doctrine' => [ | |
'connection' => [ | |
'orm_default' => [ | |
'driverClass' => PDOMySqlDriver::class, | |
'params' => [ | |
'host' => 'localhost', | |
'user' => 'root', | |
'password' => '12345', | |
'dbname' => 'expressive', | |
'charset' => 'utf8', | |
'port' => 3307 | |
], | |
], | |
], | |
], | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment