Skip to content

Instantly share code, notes, and snippets.

@basz
Last active January 22, 2016 15:14
Show Gist options
  • Select an option

  • Save basz/48325ad4015e46041132 to your computer and use it in GitHub Desktop.

Select an option

Save basz/48325ad4015e46041132 to your computer and use it in GitHub Desktop.
make vendor/bin/doctrine work with zend-expressive
/**
* A alternative to the above;
* ./vendor/bin/doctrine.php won't work, but you can add more commands shown as here with the migration tasks
*/
// ./bin/doctrine.php
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Interop\Container\ContainerInterface;
$autoloadFiles = [
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/../../../autoload.php'
];
foreach ($autoloadFiles as $autoloadFile) {
if (file_exists($autoloadFile)) {
require_once $autoloadFile;
}
}
/** @var ContainerInterface $container */
$container = require 'config/container.php';
$commands = [
'doctrine.migrations_cmd.diff',
'doctrine.migrations_cmd.execute',
'doctrine.migrations_cmd.generate',
'doctrine.migrations_cmd.latest',
'doctrine.migrations_cmd.migrate',
'doctrine.migrations_cmd.status',
'doctrine.migrations_cmd.version',
];
foreach ($commands as $key => $command) {
if ($container->has($command)) {
$commands[$key] = $container->get($command);
}
}
$managerRegistry = $container->get('Doctrine\Common\Persistence\ManagerRegistry');
$entityManager = $managerRegistry->getManager(getenv('ENTITY_MANAGER_NAME') ?: 'orm_default');
$helperSet = ConsoleRunner::createHelperSet($entityManager);
$helperSet->set(new \Symfony\Component\Console\Helper\QuestionHelper(), 'dialog');
$application = ConsoleRunner::createApplication($helperSet, $commands);
$application->run();
// ./config/cli-config.php
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Interop\Container\ContainerInterface;
use Zend\Expressive\Application;
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
/** @var ContainerInterface $container */
$container = require 'config/container.php';
$entityManager = $container->get('doctrine.entitymanager.orm_default');
return ConsoleRunner::createHelperSet($entityManager);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment