當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ORMExecutor::getReferenceRepository方法代碼示例

本文整理匯總了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)));
 }
開發者ID:ruslan-polutsygan,項目名稱:dev-bundle,代碼行數:43,代碼來源:LoadDataFixturesDoctrineCommand.php

示例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());
 }
開發者ID:Dren-x,項目名稱:mobit,代碼行數:24,代碼來源:ORMExecutorSharedFixtureTest.php

示例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();
 }
開發者ID:nmallare,項目名稱:platform,代碼行數:23,代碼來源:WebTestCase.php

示例4: get

 public function get($reference)
 {
     $this->loadEntities();
     return $this->executor->getReferenceRepository()->getReference($reference);
 }
開發者ID:argentinaluiz,項目名稱:jsdoctrine,代碼行數:5,代碼來源:LoadFixture.php


注:本文中的Doctrine\Common\DataFixtures\Executor\ORMExecutor::getReferenceRepository方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。