本文整理汇总了PHP中Doctrine\Common\DataFixtures\Executor\ORMExecutor::setLogger方法的典型用法代码示例。如果您正苦于以下问题:PHP ORMExecutor::setLogger方法的具体用法?PHP ORMExecutor::setLogger怎么用?PHP ORMExecutor::setLogger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\DataFixtures\Executor\ORMExecutor
的用法示例。
在下文中一共展示了ORMExecutor::setLogger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$emName = $input->getOption('em');
$emName = $emName ? $emName : 'default';
$emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName);
$em = $this->container->get($emServiceName);
$dirOrFile = $input->getOption('fixtures');
if ($dirOrFile) {
$paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
} else {
$paths = array();
foreach ($this->application->getKernel()->getBundles() as $bundle) {
$paths[] = $bundle->getPath() . '/DataFixtures/ORM';
}
}
$loader = new DataFixturesLoader($this->container);
foreach ($paths as $path) {
if (is_dir($path)) {
$loader->loadFromDirectory($path);
}
}
$fixtures = $loader->getFixtures();
$purger = new ORMPurger($em);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
$executor->execute($fixtures, $input->getOption('append'));
}
示例2: execute
/**
* Executes the current command.
*
* This method is not abstract because you can use this class
* as a concrete class. In this case, instead of defining the
* execute() method, you set the code to execute by passing
* a Closure to the setCode() method.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return null|int null or 0 if everything went fine, or an error code
*
* @throws LogicException When this abstract method is not implemented
*
* @see setCode()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion('All data in User table will be purged before inserting default data.
Are you sure you want to continue?', false);
if (!$helper->ask($input, $output, $question)) {
return;
}
try {
$loader = new Loader();
$loader->loadFromDirectory(__DIR__ . '/../fixtures');
$fixtures = $loader->getFixtures();
$purger = new ORMPurger($this->em);
$executor = new ORMExecutor($this->em, $purger);
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
$executor->execute($fixtures);
$output->writeln('Default users have been successfully loaded!');
return 0;
} catch (\Exception $e) {
$output->writeLn("That's bad. An Error occurred: <error>{$e->getMessage()}</error>");
return 1;
}
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$emName = $input->getOption('em');
$emName = $emName ? $emName : 'default';
$emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName);
if (!$this->getContainer()->has($emServiceName)) {
throw new InvalidArgumentException(sprintf('Could not find an entity manager configured with the name "%s". Check your ' . 'application configuration to configure your Doctrine entity managers.', $emName));
}
$em = $this->getContainer()->get($emServiceName);
$dirOrFile = $input->getOption('fixtures');
if ($dirOrFile) {
$paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
} else {
$paths = array();
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
$paths[] = $bundle->getPath() . '/DataFixtures/ORM';
}
}
$loader = new DataFixturesLoader($this->getContainer());
foreach ($paths as $path) {
if (is_dir($path)) {
$loader->loadFromDirectory($path);
}
}
$fixtures = $loader->getFixtures();
if (!$fixtures) {
throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
}
$purger = new ORMPurger($em);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
$executor->execute($fixtures, $input->getOption('append'));
}
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getEntityManager();
if ($input->isInteractive() && !$input->getOption('append')) {
if (!$this->askConfirmation($input, $output, '<question>Careful, database will be purged. Do you want to continue y/N ?</question>', false)) {
return;
}
}
$app = $this->getApp();
$path = $app->getApplicationBase($app->getAppNamespace()) . '/DataFixture';
$loader = new DataFixturesLoader();
$loader->loadFromDirectory($path);
$fixtures = $loader->getFixtures();
if (!$fixtures) {
throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- {$path}"));
}
foreach ($fixtures as $fixture) {
if ($fixture instanceof ContainerAwareInterface) {
$fixture->setContainer($this->getContainer());
}
}
$purger = new ORMPurger($em);
if ($input->getOption('truncate-only')) {
$purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
$purger->purge();
exit(0);
}
$purger->setPurgeMode($input->getOption('truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
$executor->execute($fixtures, $input->getOption('append'));
}
示例5: execute
/**
* Executes the current command.
*
* This method is not abstract because you can use this class
* as a concrete class. In this case, instead of defining the
* execute() method, you set the code to execute by passing
* a Closure to the setCode() method.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return null|int null or 0 if everything went fine, or an error code
*
* @throws LogicException When this abstract method is not implemented
*
* @see setCode()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (empty($this->fixtures)) {
$output->writeln('No fixtures found.');
return -1;
}
$loader = new Loader();
foreach ($this->fixtures as $fixture) {
$loader->addFixture($fixture);
}
$purger = new ORMPurger($this->em);
$executor = new ORMExecutor($this->em, $purger);
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getHelper('question');
$question = new ConfirmationQuestion('WARNING! Database will be purged before loading initialization data. Do you want to continue?', false);
if (!$questionHelper->ask($input, $output, $question)) {
$output->writeln('CMS initialization has been CANCELED!');
return;
}
try {
$executor->execute($loader->getFixtures());
$output->writeln('Basic CMS data has been SUCCESSFULLY loaded!');
return 0;
} catch (\Exception $e) {
$output->writeLn("That's bad. An Error occurred: <error>{$e->getMessage()}</error>");
return -1;
}
}
示例6: execute
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$app = $this->getApplication()->getApp();
$em = $app['em'];
$dirOrFile = $input->getOption('fixtures');
if ($dirOrFile) {
$paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
} else {
$paths = isset($app['em.fixtures']) ? $app['em.fixtures'] : array();
}
$loader = new Loader();
foreach ($paths as $path) {
if (is_dir($path)) {
$loader->loadFromDirectory($path);
}
}
$fixtures = $loader->getFixtures();
if (!$fixtures) {
throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
}
$purger = new ORMPurger($em);
$purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
$executor->execute($fixtures, $input->getOption('append'));
}
示例7: populateTestAction
/**
* Napolni podatke iz Fixtures
*/
public function populateTestAction()
{
$logger = function ($message) {
echo $message . PHP_EOL;
};
$em = $this->serviceLocator->get("\\Doctrine\\ORM\\EntityManager");
$config = new Config($this->serviceLocator->get('config'));
$loader = new Loader();
$fixtures = isset($config->test_fixtures) ? $config->test_fixtures : [];
$fixturename = $this->params('fixturename');
if (!empty($fixturename)) {
foreach ($fixtures as $dir) {
$loader->loadFromFile($dir . '/' . $fixturename . 'Fixture.php');
/**
* če je dependent naj ne izvede nobenega
*/
if (count($loader->getFixtures()) > 1) {
throw new \InvalidArgumentException('Loadanih več fixtur-jev -verjetno zaradi dependencies. Kot parameter možen le fixture brez odvisnosti.');
}
}
} else {
foreach ($fixtures as $dir) {
$loader->loadFromDirectory($dir);
}
}
$executor = new ORMExecutor($em);
$executor->setLogger($logger);
$executor->execute($loader->getFixtures(), true);
}
示例8: loadFixtures
private function loadFixtures(OutputInterface $output, EntityManager $em, array $loaded)
{
$logger = function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
};
$executor = new ORMExecutor($em);
$paths = [];
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
$paths[] = $bundle->getPath() . '/Fixture';
}
$loader = new DataFixturesLoader($this->getContainer());
foreach ($paths as $path) {
if (is_dir($path)) {
$loader->loadFromDirectory($path);
}
}
$env = $this->getContainer()->getParameter('kernel.environment');
$output->writeln("Loading <comment>fixtures</comment>...");
$has = array_map(function (Fixture $fixture) {
return $fixture->getName();
}, $loaded);
$fixtures = array_filter($loader->getFixtures(), function (FixtureInterface $fixture) use($has) {
return !in_array(get_class($fixture), $has);
});
if (!$fixtures) {
$output->writeln(" Could not find any new <comment>fixtures</comment> to load..");
return [];
}
$executor->setLogger($logger);
$executor->execute($fixtures, true);
return $fixtures;
}
示例9: execute
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->container = $this->getContainer();
$output->writeln("<comment>Updating...</comment>\n");
$em = $this->container->get('doctrine.orm.entity_manager');
$loader = new ContainerAwareLoader($this->container);
$loader->loadFromDirectory($input->getOption('fixtures'));
$purger = new ORMPurger($em);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
$executor->execute($loader->getFixtures(), true);
}
示例10: applyFixtures
/**
* Loads the data fixtures passed as array.
*
* @param array $fixtureClasses
* @param callable $executorLogFunction
*
* @throws \InvalidArgumentException If the fixture class does not exist.
*/
public function applyFixtures(array $fixtureClasses, callable $executorLogFunction = null)
{
$loader = new Loader();
foreach ($fixtureClasses as $fixtureClass) {
if (!class_exists($fixtureClass)) {
throw new \InvalidArgumentException(sprintf('Fixture class "%s" does not exist!', $fixtureClass));
}
$loader->addFixture(new $fixtureClass());
}
$purger = new ORMPurger($this->entityManager);
$executor = new ORMExecutor($this->entityManager, $purger);
if (null !== $executorLogFunction) {
$executor->setLogger($executorLogFunction);
}
$executor->execute($loader->getFixtures());
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Loading demo data ...');
$container = $this->getContainer();
$loader = new ContainerAwareLoader($container);
foreach ($container->get('kernel')->getBundles() as $bundle) {
if (is_dir($path = $bundle->getPath() . '/DataFixtures/Demo')) {
$loader->loadFromDirectory($path);
}
}
$executor = new ORMExecutor($container->get('doctrine.orm.entity_manager'));
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
$executor->execute($loader->getFixtures(), true);
}
示例12: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var $doctrine \Doctrine\Common\Persistence\ManagerRegistry */
$doctrine = $this->getContainer()->get('doctrine');
$em = $doctrine->getManager($input->getOption('em'));
if ($input->isInteractive() && !$input->getOption('append')) {
$dialog = $this->getHelperSet()->get('dialog');
if (!$dialog->askConfirmation($output, '<question>Careful, database will be purged. Do you want to continue Y/N ?</question>', false)) {
return;
}
}
$dirOrFile = $input->getOption('fixtures');
if ($dirOrFile) {
$paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
} else {
$paths = array();
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
$paths[] = $bundle->getPath() . '/DataFixtures/ORM';
}
}
$loader = new DataFixturesLoader($this->getContainer());
foreach ($paths as $path) {
if (is_dir($path)) {
$loader->loadFromDirectory($path);
}
}
$fixtures = $loader->getFixtures();
if (!$fixtures) {
throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
}
$purger = new ORMPurger($em);
$purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
$executor->execute($fixtures, $input->getOption('append'));
// Serialize reference repository to a file. So fixtures will be accessible by names inside functional tests.
$referenceRepositoryFile = $this->getContainer()->getParameter('fixtures.reference_repository_path');
$serializedReferenceRepository = (new FixtureReferenceRepositorySerializer())->serialize($executor->getReferenceRepository());
file_put_contents($referenceRepositoryFile, $serializedReferenceRepository);
$output->writeln(sprintf('<info>Reference repository saved to:</info> <comment>%s</comment>', realpath($referenceRepositoryFile)));
}
示例13: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->em;
if ($input->isInteractive() && !$input->getOption('append')) {
$dialog = $this->getHelperSet()->get('dialog');
if (!$dialog->askConfirmation($output, '<question>Careful, database will be purged. Do you want to continue Y/N ?</question>', false)) {
return;
}
}
$dirOrFile = $input->getOption('fixtures');
if ($dirOrFile) {
$paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
} else {
$paths = array();
foreach (glob(APPPATH . 'modules/*/fixtures', GLOB_ONLYDIR) as $m) {
$paths[] = $m;
}
}
$loader = new Loader();
foreach ($paths as $path) {
if (is_dir($path)) {
$loader->loadFromDirectory($path);
}
}
$fixtures = $loader->getFixtures();
if (!$fixtures) {
throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
}
$purger = new ORMPurger($em);
// $purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
$executor->execute($fixtures, $input->getOption('append'));
}
示例14: processFixtures
/**
* Process fixtures
*
* @param InputInterface $input
* @param OutputInterface $output
* @param array $fixtures
*/
protected function processFixtures(InputInterface $input, OutputInterface $output, $fixtures)
{
$output->writeln(sprintf('Loading "%s" data fixtures ...', $this->getTypeOfFixtures($input)));
$executor = new ORMExecutor($this->getContainer()->get('doctrine.orm.entity_manager'));
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
$executor->execute($fixtures, true);
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var $doctrine \Doctrine\Common\Persistence\ManagerRegistry */
$doctrine = $this->getContainer()->get('doctrine');
$em = $doctrine->getManager($input->getOption('em'));
if ($input->isInteractive() && !$input->getOption('append')) {
if (!$this->askConfirmation($input, $output, '<question>Careful, database will be purged. Do you want to continue y/N ?</question>', false)) {
return;
}
}
if ($input->getOption('shard')) {
if (!$em->getConnection() instanceof PoolingShardConnection) {
throw new \LogicException(sprintf("Connection of EntityManager '%s' must implement shards configuration.", $input->getOption('em')));
}
$em->getConnection()->connect($input->getOption('shard'));
}
$dirOrFile = $input->getOption('fixtures');
if ($dirOrFile) {
$paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
} else {
$paths = array();
foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
$paths[] = $bundle->getPath() . '/DataFixtures/ORM';
}
}
$loader = new DataFixturesLoader($this->getContainer());
foreach ($paths as $path) {
if (is_dir($path)) {
$loader->loadFromDirectory($path);
} elseif (is_file($path)) {
$loader->loadFromFile($path);
}
}
$fixtures = $loader->getFixtures();
if (!$fixtures) {
throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
}
$purger = new ORMPurger($em);
$purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
$executor->execute($fixtures, $input->getOption('append'), $input->getOption('multiple-transactions'));
}