Skip to content

Instantly share code, notes, and snippets.

@szagot
Forked from argentinaluiz/composer.json
Created July 29, 2016 12:02
Show Gist options
  • Save szagot/9bf2daaf93e2856626da7da75fac7d2c to your computer and use it in GitHub Desktop.
Save szagot/9bf2daaf93e2856626da7da75fac7d2c to your computer and use it in GitHub Desktop.
Doctrine configuration for Zend-Expressive
....
"zendframework/zend-stdlib": "~2.7.0",
"zendframework/zend-servicemanager": "~2.7.3",
"doctrine/doctrine-orm-module": "0.10.0",
....
.....
'aliases' => [
'configuration' => 'config', //Doctrine needs a service called Configuration
],
....
<?php
use Zend\Stdlib\ArrayUtils;
use DoctrineModule\Version;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\DialogHelper;
use Symfony\Component\Console\Helper\QuestionHelper;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
$vendorPath = __DIR__ . '/../../vendor';
$doctrineModuleConfig = require_once $vendorPath . '/doctrine/doctrine-module/config/module.config.php';
$doctrineModuleConfig['dependencies'] = $doctrineModuleConfig['service_manager'];
unset($doctrineModuleConfig['service_manager']);
unset($doctrineModuleConfig['dependencies']['factories']['doctrine.cli']);
$doctrineModuleConfig['dependencies']['factories']['doctrine.cli'] = function(\Interop\Container\ContainerInterface $container){
$cli = new Application;
$cli->setName('DoctrineModule Command Line Interface');
$cli->setVersion(Version::VERSION);
$cli->setHelperSet(new HelperSet);
$cli->setCatchExceptions(true);
$cli->setAutoExit(false);
$commands = array(
'doctrine.dbal_cmd.runsql',
'doctrine.dbal_cmd.import',
'doctrine.orm_cmd.clear_cache_metadata',
'doctrine.orm_cmd.clear_cache_result',
'doctrine.orm_cmd.clear_cache_query',
'doctrine.orm_cmd.schema_tool_create',
'doctrine.orm_cmd.schema_tool_update',
'doctrine.orm_cmd.schema_tool_drop',
'doctrine.orm_cmd.ensure_production_settings',
'doctrine.orm_cmd.convert_d1_schema',
'doctrine.orm_cmd.generate_repositories',
'doctrine.orm_cmd.generate_entities',
'doctrine.orm_cmd.generate_proxies',
'doctrine.orm_cmd.convert_mapping',
'doctrine.orm_cmd.run_dql',
'doctrine.orm_cmd.validate_schema',
'doctrine.orm_cmd.info',
);
if (class_exists('Doctrine\\DBAL\\Migrations\\Version')) {
$commands = ArrayUtils::merge(
$commands,
array(
'doctrine.migrations_cmd.execute',
'doctrine.migrations_cmd.generate',
'doctrine.migrations_cmd.migrate',
'doctrine.migrations_cmd.status',
'doctrine.migrations_cmd.version',
'doctrine.migrations_cmd.diff',
'doctrine.migrations_cmd.latest',
)
);
}
$cli->addCommands(array_map(array($container, 'get'), $commands));
/* @var $entityManager \Doctrine\ORM\EntityManager */
$entityManager = $container->get('doctrine.entitymanager.orm_default');
$helperSet = $cli->getHelperSet();
if (class_exists('Symfony\Component\Console\Helper\QuestionHelper')) {
$helperSet->set(new QuestionHelper(), 'dialog');
} else {
$helperSet->set(new DialogHelper(), 'dialog');
}
$helperSet->set(new ConnectionHelper($entityManager->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($entityManager), 'em');
return $cli;
};
$doctrineOrmModuleConfig = require_once $vendorPath . '/doctrine/doctrine-orm-module/config/module.config.php';
$doctrineOrmModuleConfig['dependencies'] = $doctrineOrmModuleConfig['service_manager'];
unset($doctrineOrmModuleConfig['service_manager']);
return ArrayUtils::merge($doctrineModuleConfig, $doctrineOrmModuleConfig);
<?php
ini_set('display_errors', true);
chdir(__DIR__);
require 'vendor/autoload.php';
/** @var \Interop\Container\ContainerInterface $container */
$container = require 'config/container.php';
/** @var \Zend\Expressive\Application $app */
$app = $container->get(\Zend\Expressive\Application::class);
$cli = $app->getContainer()->get('doctrine.cli');
exit($cli->run());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment