• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP DataFixtures\Loader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Doctrine\Common\DataFixtures\Loader的典型用法代码示例。如果您正苦于以下问题:PHP Loader类的具体用法?PHP Loader怎么用?PHP Loader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Loader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:ifigenija,项目名称:server,代码行数:32,代码来源:InstallController.php


示例2: 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'));
 }
开发者ID:NightWarriorbg,项目名称:zaralab-api,代码行数:34,代码来源:LoadDatafixturesCommand.php


示例3: 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;
     }
 }
开发者ID:blitzik,项目名称:CMS,代码行数:43,代码来源:DefaultDataCommand.php


示例4: adminRefreshDatabaseAction

 public function adminRefreshDatabaseAction(Request $request, Application $app)
 {
     $conn = $app['db'];
     $em = $app['doctrine.orm.entity_manager'];
     $params = $conn->getParams();
     $name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
     try {
         $conn->getSchemaManager()->dropDatabase($name);
         $conn->getSchemaManager()->createDatabase($name);
         $conn->close();
     } catch (\Exception $e) {
         return 1;
     }
     $classes = [];
     foreach ($app['authbucket_oauth2.model'] as $class) {
         $classes[] = $em->getClassMetadata($class);
     }
     PersistentObject::setObjectManager($em);
     $tool = new SchemaTool($em);
     $tool->dropSchema($classes);
     $tool->createSchema($classes);
     $purger = new ORMPurger();
     $executor = new ORMExecutor($em, $purger);
     $loader = new Loader();
     $loader->loadFromDirectory(__DIR__ . '/../DataFixtures/ORM');
     $executor->execute($loader->getFixtures());
     return $app->redirect($app['url_generator']->generate('index'));
 }
开发者ID:miguelbemartin,项目名称:oauth2-php,代码行数:28,代码来源:DefaultController.php


示例5: setUp

 /**
  * Initializes the database (once).
  *
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Doctrine\ORM\ORMException
  * @throws \Doctrine\ORM\Tools\ToolsException
  */
 protected function setUp()
 {
     if (null === static::$_conn) {
         $dbPath = __DIR__ . '/../../../db.sqlite';
         if (file_exists($dbPath)) {
             unlink($dbPath);
         }
         $params = ['driver' => 'pdo_sqlite', 'path' => $dbPath];
         static::$_conn = DriverManager::getConnection($params);
         static::$_conn->getConfiguration()->setSQLLogger(null);
     }
     if (null === static::$_em) {
         $paths = [__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/ORM/Resources/mapping'];
         $isDevMode = true;
         $config = Setup::createXMLMetadataConfiguration($paths, $isDevMode);
         $em = EntityManager::create(static::$_conn, $config);
         $classes = [];
         foreach (static::$_classes as $class) {
             array_push($classes, $em->getClassMetadata($class));
         }
         $schemaTool = new SchemaTool($em);
         $schemaTool->dropSchema($classes);
         $schemaTool->createSchema($classes);
         // Load fixtures
         $loader = new Loader();
         $loader->loadFromDirectory(__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/Fixtures');
         $purger = new ORMPurger();
         $executor = new ORMExecutor($em, $purger);
         $executor->execute($loader->getFixtures());
         static::$_em = $em;
     }
 }
开发者ID:ekyna,项目名称:commerce,代码行数:39,代码来源:DatabaseTestCase.php


示例6: 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;
     }
 }
开发者ID:blitzik,项目名称:CMS,代码行数:48,代码来源:LoadBasicDataCommand.php


示例7: 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'));
 }
开发者ID:digitas,项目名称:digex-core,代码行数:31,代码来源:LoadDataFixturesDoctrineCommand.php


示例8: testGetFixture

 public function testGetFixture()
 {
     $loader = new Loader();
     $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php');
     $fixture = $loader->getFixture(MyFixture1::class);
     $this->assertInstanceOf(MyFixture1::class, $fixture);
 }
开发者ID:doctrine,项目名称:data-fixtures,代码行数:7,代码来源:LoaderTest.php


示例9: loadFixtures

 private function loadFixtures()
 {
     $loader = new Loader();
     $loader->addFixture(new LoadAchievementData());
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->manager, $purger);
     $executor->execute($loader->getFixtures());
 }
开发者ID:Kafei59,项目名称:bound,代码行数:8,代码来源:PTest.php


示例10: loadWholeFixtures

 private function loadWholeFixtures()
 {
     $loader = new Loader();
     $loader->addFixture(new LoadItems());
     $purger = new ORMPurger($this->getEntityManager());
     $executor = new ORMExecutor($this->getEntityManager(), $purger);
     $executor->execute($loader->getFixtures());
 }
开发者ID:lzakrzewski,项目名称:tests-with-database-examples,代码行数:8,代码来源:FixturesLoadingTest.php


示例11: loadFixtures

 protected function loadFixtures()
 {
     $loader = new Loader();
     $loader->addFixture(new DataFixtures());
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->app['orm.em'], $purger);
     $executor->execute($loader->getFixtures());
 }
开发者ID:nawrasg,项目名称:tvguide,代码行数:8,代码来源:WebTestCase.php


示例12: loadFixture

 /**
  * Load the given fixture
  *
  * @param \Doctrine\Common\DataFixtures\FixtureInterface $fixture
  */
 protected function loadFixture(FixtureInterface $fixture)
 {
     $loader = new Loader();
     $loader->addFixture($fixture);
     $purger = new ORMPurger();
     $executor = new ORMExecutor(static::$em, $purger);
     $executor->execute($loader->getFixtures());
 }
开发者ID:leapt,项目名称:core-bundle,代码行数:13,代码来源:DoctrineORMPaginatorTest.php


示例13: loadFixtures

 protected function loadFixtures()
 {
     $loader = new Loader();
     $loader->loadFromDirectory(__DIR__ . '/Fixtures');
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->entityManager, $purger);
     $executor->execute($loader->getFixtures());
 }
开发者ID:Hikariii,项目名称:doctrine-extensions,代码行数:8,代码来源:SetupTest.php


示例14: tearDown

 protected function tearDown()
 {
     $loader = new Loader();
     $loader->loadFromFile('src/PadelTFG/GeneralBundle/DataFixtures/ORM/SponsorTest/SponsorTestRemove.php');
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->em, $purger);
     $executor->execute($loader->getFixtures(), true);
     $this->em->close();
 }
开发者ID:albertoml,项目名称:padelTFG,代码行数:9,代码来源:SponsorControllerAPITest.php


示例15: doLoadFixtures

 /** @before */
 public function doLoadFixtures()
 {
     $loader = new Loader();
     foreach ($this->loadFixtures() as $fixture) {
         $loader->addFixture($fixture);
     }
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->em, $purger);
     $executor->execute($loader->getFixtures());
 }
开发者ID:bitecodes,项目名称:doctrine-filter,代码行数:11,代码来源:LoadFixtures.php


示例16: execute

 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $loader = new Loader();
     $executor = new ORMExecutor($this->em, new ORMPurger());
     $loader->loadFromDirectory($this->mainDir);
     foreach ($this->dirs as $dir) {
         $loader->loadFromDirectory($dir);
     }
     $executor->execute($loader->getFixtures(), true);
 }
开发者ID:phprest,项目名称:phprest-service-orm,代码行数:16,代码来源:Append.php


示例17: fire

 /**
  * @inheritdoc
  */
 public function fire()
 {
     $loader = new Loader();
     $this->info('Loading fixtures ...');
     $loader->loadFromDirectory($this->option('path'));
     $fixtures = $loader->getFixtures();
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->getEntityManager(), $purger);
     $executor->execute($fixtures, $this->option('append'));
     $this->info('Fixtures loaded!');
 }
开发者ID:simonbowen,项目名称:lumen-doctrine,代码行数:14,代码来源:FixturesLoadCommand.php


示例18: beforeScen

 /**
  * Загружаем необходимые фикстуры перед выполнением сценария
  *
  * @BeforeScenario
  */
 public function beforeScen()
 {
     $loader = new Loader();
     $loader->addFixture(new \Application\Bundle\UserBundle\DataFixtures\ORM\LoadUserData());
     /** @var $em \Doctrine\ORM\EntityManager */
     $em = $this->kernel->getContainer()->get('doctrine')->getManager();
     $purger = new ORMPurger();
     $executor = new ORMExecutor($em, $purger);
     $executor->purge();
     $executor->execute($loader->getFixtures());
 }
开发者ID:jekakm,项目名称:fwdays,代码行数:16,代码来源:FeatureContext.php


示例19: execute

 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $loader = new Loader();
     $loader->loadFromDirectory($this->mainDir);
     foreach ($this->dirs as $dir) {
         $loader->loadFromDirectory($dir);
     }
     foreach ($loader->getFixtures() as $fixtureName => $fixture) {
         $output->writeln($fixtureName);
     }
 }
开发者ID:phprest,项目名称:phprest-service-orm,代码行数:17,代码来源:Get.php


示例20: setUp

 public function setUp()
 {
     parent::setUp();
     $this->createDb();
     $loader = new FixtureLoader();
     $loader->addFixture(new TestFixture());
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->getEntityManager(), $purger);
     $executor->execute($loader->getFixtures());
     $this->element = new DoctrineEntityElement('foo', array('object_manager' => $this->getEntityManager(), 'target_class' => 'DoctrineORMModuleTest\\Assets\\Entity\\Test'));
 }
开发者ID:ashimidashajia,项目名称:zendstore,代码行数:11,代码来源:DoctrineEntityTest.php



注:本文中的Doctrine\Common\DataFixtures\Loader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Executor\ORMExecutor类代码示例发布时间:2022-05-23
下一篇:
PHP Collections\Criteria类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap