public function run() { $entityManager = null; if (is_array($_SERVER['argv'])) { foreach ($_SERVER['argv'] as $key => $value) { if (substr($value, 0, 5) === '--em=') { $entityManager = substr($value, 5); unset($_SERVER['argv'][$key]); if (is_int($_SERVER['argc'])) { $_SERVER['argc']--; } break; } } } $commands = $this->container->getDoctrine()->getCommands(); $helperSet = $this->container->getDoctrine()->getHelperSet($entityManager); if (!$helperSet instanceof HelperSet) { foreach ($GLOBALS as $helperSetCandidate) { if ($helperSetCandidate instanceof HelperSet) { $helperSet = $helperSetCandidate; break; } } } ConsoleRunner::run($helperSet, $commands); }
public function route_model() { // GET ENTITY MANAGER $em = $this->doctrine->getEntityManager(); // CALL CONSOLE RUNNER $helperSet = 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))); // GET CONSOLE RUNNER return \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet); }
public function actionIndex() { /** * @var $em \Doctrine\ORM\EntityManager */ $em = ApplicationConsole::app()->db->doctrine; $helperSet = new HelperSet(['db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em)]); //unset($_SERVER['argv'][0]); unset($_SERVER['argv'][1]); $_SERVER['argv'] = array_values($_SERVER['argv']); \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet); }
public function indexAction() { if ($this->getRequest() instanceof ConsoleRequest) { $params = $this->params()->fromRoute(); switch ($params['api']) { case 'doctrine': global $argv; array_shift($argv); // index.php array_shift($argv); // external $_SERVER['argv'] = $argv; $helperSet = ConsoleRunner::createHelperSet($this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager')); ConsoleRunner::run($helperSet, array()); break; default: return 'Could not find an option for external tool: ' . $params['api']; } return ''; } return new ViewModel(); }
public function actionIndex() { unset($_SERVER['argv'][1]); $option = '--' . \yii\console\Application::OPTION_APPCONFIG . '='; foreach ($_SERVER['argv'] as $key => $param) { if (strpos($param, $option) === 0) { $keyToUnset = $key; break; } } if (isset($keyToUnset)) { unset($_SERVER['argv'][$keyToUnset]); unset($keyToUnset); } // Currently, symfony application uses a deprecated class (DialogHelper). // Don't throw an exception. $currentLevel = error_reporting(); error_reporting($currentLevel ^ E_USER_DEPRECATED); $doctrine = $this->getDoctrineComponent(); $entityManager = $doctrine->getEntityManager(); $helperSet = ConsoleRunner::createHelperSet($entityManager); $result = ConsoleRunner::run($helperSet); return $result; }
<?php require_once '../../Library/Doctrine/Common/ClassLoader.php'; $classLoader = new \Doctrine\Common\ClassLoader('Doctrine'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'Doctrine'); $classLoader->register(); $configFile = getcwd() . DIRECTORY_SEPARATOR . 'cli-config.php'; $helperSet = null; if (file_exists($configFile)) { if (!is_readable($configFile)) { trigger_error('Configuration file [' . $configFile . '] does not have read permission.', E_ERROR); } require $configFile; foreach ($GLOBALS as $helperSetCandidate) { if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) { $helperSet = $helperSetCandidate; break; } } } $helperSet = $helperSet ?: new \Symfony\Component\Console\Helper\HelperSet(); \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet);
@(include_once __DIR__ . '/../vendor/autoload.php') || @(include_once __DIR__ . '/../../../autoload.php'); $directories = array(getcwd(), getcwd() . DIRECTORY_SEPARATOR . 'config'); $configFile = null; foreach ($directories as $directory) { $configFile = $directory . DIRECTORY_SEPARATOR . 'cli-config.php'; if (file_exists($configFile)) { break; } } if (!file_exists($configFile)) { ConsoleRunner::printCliConfigTemplate(); exit(1); } if (!is_readable($configFile)) { echo 'Configuration file [' . $configFile . '] does not have read permission.' . "\n"; exit(1); } Type::overrideType(Type::DATETIME, Database::getUTCDateTimeTypeClass()); Type::addType('json', 'Sonata\\Doctrine\\Types\\JsonType'); $commands = array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()); $helperSet = (require $configFile); if (!$helperSet instanceof HelperSet) { foreach ($GLOBALS as $helperSetCandidate) { if ($helperSetCandidate instanceof HelperSet) { $helperSet = $helperSetCandidate; break; } } } \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet, $commands);
<?php //doctrine-cli.php use Symfony\Component\Console\Helper\HelperSet, Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper, Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper, Doctrine\ORM\Tools\Console\ConsoleRunner; use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\EntityManager; use Doctrine\Common\ClassLoader; require_once "vendor/autoload.php"; require_once "../Models/Entity/AbstractEntity.php"; $loader = new ClassLoader("Entity", "models"); $loader->register(); $dbParams = array('driver' => 'pdo_mysql', 'user' => 'oringo_fdd', 'password' => 'atitudinefdd', 'host' => 'localhost', 'dbname' => 'oringo_neo', 'charset' => "utf8"); $path = array('../../NeoMvc/Models/Entity'); $config = Setup::createAnnotationMetadataConfiguration($path, true); $config->setProxyDir("../../NeoMvc/Proxy"); $config->setProxyNamespace("Proxy"); //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); $em = EntityManager::create($dbParams, $config); $helperSet = new HelperSet(array('em' => new EntityManagerHelper($em), 'conn' => new ConnectionHelper($em->getConnection()))); ConsoleRunner::run($helperSet);
<?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 LGPL. For more information, see * <http://www.doctrine-project.org>. */ define('PATH_ROOT', __DIR__ . '/../../../../'); require_once PATH_ROOT . 'vendor/autoload.php'; require_once __DIR__ . DIRECTORY_SEPARATOR . 'cli-config.php'; $oConsole = \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager); \Doctrine\ORM\Tools\Console\ConsoleRunner::run($oConsole);
<?php $app = (require_once __DIR__ . '/bootstrap.php'); use Doctrine\ORM\Tools\Console\ConsoleRunner; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\DialogHelper; use Doctrine\DBAL\Migrations\Tools\Console\Command; use Doctrine\DBAL\Migrations\Configuration\Configuration; use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; use Symfony\Component\Console\Application as SymfonyApplication; $helpers['em'] = new EntityManagerHelper($app['orm.em']); $helpers['dialog'] = new DialogHelper(); $helperSet = new HelperSet($helpers); $commands = array(new Command\DiffCommand(), new Command\ExecuteCommand(), new Command\GenerateCommand(), new Command\MigrateCommand(), new Command\StatusCommand(), new Command\VersionCommand()); $application = new SymfonyApplication(); $config = new Configuration($app['db']); $config->setName('Skel Migration'); $config->setMigrationsDirectory(__DIR__ . '/data/DoctrineMigrations'); $config->setMigrationsNamespace('Application\\Migrations'); $config->setMigrationsTableName('migration_version'); foreach ($commands as $command) { if ($command instanceof Command\AbstractCommand) { $command->setMigrationConfiguration($config); } $application->add($command); } ConsoleRunner::run($helperSet, $application->all());
break; } } $directories = [getcwd(), getcwd() . DIRECTORY_SEPARATOR . 'config']; $configFile = null; foreach ($directories as $directory) { $configFile = $directory . DIRECTORY_SEPARATOR . 'cli-config.php'; if (file_exists($configFile)) { break; } } if (!file_exists($configFile)) { ConsoleRunner::printCliConfigTemplate(); exit(1); } if (!is_readable($configFile)) { echo 'Configuration file [' . $configFile . '] does not have read permission.' . "\n"; exit(1); } $commands = []; $helperSet = (require $configFile); if (!$helperSet instanceof HelperSet) { foreach ($GLOBALS as $helperSetCandidate) { if ($helperSetCandidate instanceof HelperSet) { $helperSet = $helperSetCandidate; break; } } } ConsoleRunner::run($helperSet, $commands);
/** * Run doctrine console tool. */ public function run() { $helperSet = $this->getConsoleHelperSet(); ConsoleRunner::run($helperSet, $this->getConsoleCommands($helperSet)); }
<?php require_once __DIR__ . '/vendor/autoload.php'; $isDevMode = true; $config = \Doctrine\ORM\Tools\Setup::createXMLMetadataConfiguration(array(__DIR__ . '/xml'), $isDevMode); $params = (include __DIR__ . '/db-params.php'); $em = \Doctrine\ORM\EntityManager::create($params, $config); $db = $em->getConnection(); $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em), 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($db), 'dialog' => new \Symfony\Component\Console\Helper\DialogHelper())); spl_autoload_register(function ($name) { $fn = __DIR__ . "/entities/{$name}.php"; if (is_readable($fn)) { require_once $fn; } }); \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet, array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()));
#!/usr/bin/env php <?php use Doctrine\ORM\Tools\Console\ConsoleRunner; require_once __DIR__ . '/../vendor/autoload.php'; $dbConfig = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../src'], true, null, null, false); $conn = array('driver' => 'pdo_sqlite', 'path' => __DIR__ . '/../data/db.sqlite'); $entityManager = \Doctrine\ORM\EntityManager::create($conn, $dbConfig); $helper = ConsoleRunner::createHelperSet($entityManager); ConsoleRunner::run($helper);
$doctrine_orm = new Doctrine_ORM($database_group); // add console helpers $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($doctrine_orm->getEntityManager()->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($doctrine_orm->getEntityManager()))); // create and run Symfony Console application $cli = new Symfony\Component\Console\Application('Kohana Doctrine Command Line Interface</info>' . PHP_EOL . '<comment>use --database-group to specifify another group from database.php (defaut: default)</comment>' . PHP_EOL . '<info>Doctrine', \Doctrine\ORM\Version::VERSION); $cli->setCatchExceptions(true); // Register All Doctrine Commands \Doctrine\ORM\Tools\Console\ConsoleRunner::addCommands($cli); // Adding own helpers foreach (Kohana::$config->load('doctrine')->get('console_helpers', array()) as $alias => $helper) { $helperSet->set($helper); } // Set helperSet $cli->setHelperSet($helperSet); // Run with helperset and add own commands \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet, Kohana::$config->load('doctrine')->get('console_commands', array())); /** * init from configured paths * @param type $system * @param type $application * @param type $modules */ function initLikeIndex($system, $application, $modules) { if (!$system || !$application || !$modules) { // your installation paths (needed to run CLI) if (file_exists(__DIR__ . '/../../../../application/')) { $system = realpath(__DIR__ . '/../../../kohana/system/'); $application = realpath(__DIR__ . '/../../../../application/'); } else { $system = realpath(__DIR__ . '/../../../system/');
<?php use Zend\Loader\AutoloaderFactory, Zend\Config\Config, Zend\Loader\ModuleAutoloader, Zend\Module\Manager as ModuleManager, Zend\Module\ManagerOptions, Zend\Mvc\Bootstrap, Zend\Mvc\Application, Doctrine\ORM\Tools\Console\ConsoleRunner, Symfony\Component\Console\Helper\HelperSet, Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; ini_set('display_errors', true); error_reporting(-1); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array(realpath(__DIR__ . '/../library'), realpath(__DIR__ . '/../library/ZendFramework/library'), get_include_path()))); require_once 'Zend/Loader/AutoloaderFactory.php'; AutoloaderFactory::factory(array('Zend\\Loader\\StandardAutoloader' => array())); $appConfig = new Config(include __DIR__ . '/../configs/application.config.php'); $moduleLoader = new ModuleAutoloader($appConfig['module_paths']); $moduleLoader->register(); $moduleManager = new ModuleManager($appConfig['modules'], new ManagerOptions($appConfig['module_manager_options'])); $bootstrap = new Bootstrap($moduleManager); $application = new Application(); $bootstrap->bootstrap($application); $locator = $application->getLocator(); ConsoleRunner::run(new HelperSet(array('em' => new EntityManagerHelper($locator->get('doctrine')->getEntityManager()))));