本文整理匯總了PHP中Doctrine\Common\DataFixtures\Executor\ORMExecutor::getReferenceRepository方法的典型用法代碼示例。如果您正苦於以下問題:PHP ORMExecutor::getReferenceRepository方法的具體用法?PHP ORMExecutor::getReferenceRepository怎麽用?PHP ORMExecutor::getReferenceRepository使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\Common\DataFixtures\Executor\ORMExecutor
的用法示例。
在下文中一共展示了ORMExecutor::getReferenceRepository方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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)));
}
示例2: testSharedFixtures
public function testSharedFixtures()
{
if (!extension_loaded('pdo_sqlite')) {
$this->markTestSkipped('Missing pdo_sqlite extension.');
}
$em = $this->getMockSqliteEntityManager();
$schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
$schemaTool->dropSchema(array());
$schemaTool->createSchema(array($em->getClassMetadata(self::TEST_ENTITY_ROLE), $em->getClassMetadata(self::TEST_ENTITY_USER)));
$purger = new ORMPurger();
$executor = new ORMExecutor($em, $purger);
$userFixture = new TestFixtures\UserFixture();
$roleFixture = new TestFixtures\RoleFixture();
$executor->execute(array($roleFixture, $userFixture), true);
$referenceRepository = $executor->getReferenceRepository();
$references = $referenceRepository->getReferences();
$this->assertEquals(2, count($references));
$roleReference = $referenceRepository->getReference('admin-role');
$this->assertTrue($roleReference instanceof Role);
$this->assertEquals('admin', $roleReference->getName());
$userReference = $referenceRepository->getReference('admin');
$this->assertTrue($userReference instanceof User);
$this->assertEquals('admin@example.com', $userReference->getEmail());
}
示例3: loadFixtures
/**
* @param array $classNames
* @param bool $force
*/
protected function loadFixtures(array $classNames, $force = false)
{
if (!$force) {
$classNames = array_filter($classNames, function ($value) {
return !in_array($value, self::$loadedFixtures);
});
if (!$classNames) {
return;
}
}
self::$loadedFixtures = array_merge(self::$loadedFixtures, $classNames);
$loader = $this->getFixtureLoader($classNames);
$fixtures = array_values($loader->getFixtures());
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$executor = new ORMExecutor($em, new ORMPurger($em));
$executor->execute($fixtures, true);
self::$referenceRepository = $executor->getReferenceRepository();
$this->postFixtureLoad();
}
示例4: get
public function get($reference)
{
$this->loadEntities();
return $this->executor->getReferenceRepository()->getReference($reference);
}