composer.json
{ "minimum-stability": "dev", "require": { "php": ">=5.3.3", "silex/silex": "1.*", "taluu/doctrine-orm-provider": "1.0.*" }, "config": { "bin-dir": "bin" } }
composer install
app/src
, or any other to choose from. Following the pattern (which, by the way, can be established, which I did not do), I called src
.index.php
: // index.php <?php $app = require __DIR__.'/src/app.php'; $app->run();
// src/app.php <?php require __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); $app['debug'] = true; require __DIR__.'/registers.php'; require __DIR__.'/controllers.php'; return $app;
// src/registers.php <?php use Doctrine\Common\Cache\ApcCache; use Doctrine\Common\Cache\ArrayCache; $app->register(new Silex\Provider\DoctrineServiceProvider(), array( 'db.options' => array(// DBAL : http://silex.sensiolabs.org/doc/providers/doctrine.html 'driver' => 'pdo_mysql', 'dbname' => 'silex_test', 'host' => '127.0.0.1', 'user' => 'root', 'password' => 'root', 'charset' => 'utf8' ) )); $app->register(new Nutwerk\Provider\DoctrineORMServiceProvider(), array( 'db.orm.proxies_dir' => __DIR__.'/../cache/doctrine/proxy', 'db.orm.proxies_namespace' => 'DoctrineProxy', 'db.orm.cache' => !$app['debug'] && extension_loaded('apc') ? new ApcCache() : new ArrayCache(), 'db.orm.auto_generate_proxies' => true, 'db.orm.entities' => array(array( 'type' => 'annotation', // Entity 'path' => __DIR__, // , 'namespace' => 'TestApp\Entity', // )), ));
src/TestApp
and src/TestApp/Entity
bin
.cli-config.php
configure cli-config.php
. Initially, this file is in vendor/doctrine/orm/tools/sandbox
, copy from there to bin
. And now remove everything except the creation of $helpers
. // bin/cli-config.php <?php $app = require __DIR__.'/../src/app.php'; $em = $app['db.orm.em']; $helpers = new Symfony\Component\Console\Helper\HelperSet(array( 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em) ));
$app['db.orm.em']
$configFile = getcwd() . DIRECTORY_SEPARATOR . 'bin/cli-config.php'; // 21
// bin/console #!/usr/bin/env php <?php require 'cli-config.php'; include('doctrine.php');
./bin/console [command_name]
Source: https://habr.com/ru/post/173955/
All Articles