当前位置: 首页>>代码示例>>PHP>>正文


PHP DocumentManager::getRepository方法代码示例

本文整理汇总了PHP中Doctrine\ODM\PHPCR\DocumentManager::getRepository方法的典型用法代码示例。如果您正苦于以下问题:PHP DocumentManager::getRepository方法的具体用法?PHP DocumentManager::getRepository怎么用?PHP DocumentManager::getRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ODM\PHPCR\DocumentManager的用法示例。


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

示例1: load

 /**
  * Load meta object by provided type and parameters.
  *
  * @MetaLoaderDoc(
  *     description="Article Loader loads articles from Content Repository",
  *     parameters={
  *         contentPath="SINGLE|required content path",
  *         slug="SINGLE|required content slug",
  *         pageName="COLLECTiON|name of Page for required articles"
  *     }
  * )
  *
  * @param string $type         object type
  * @param array  $parameters   parameters needed to load required object type
  * @param int    $responseType response type: single meta (LoaderInterface::SINGLE) or collection of metas (LoaderInterface::COLLECTION)
  *
  * @return Meta|Meta[]|bool false if meta cannot be loaded, a Meta instance otherwise
  */
 public function load($type, $parameters, $responseType = LoaderInterface::SINGLE)
 {
     $article = null;
     if (empty($parameters)) {
         $parameters = [];
     }
     if ($responseType === LoaderInterface::SINGLE) {
         if (array_key_exists('contentPath', $parameters)) {
             $article = $this->dm->find('SWP\\ContentBundle\\Document\\Article', $parameters['contentPath']);
         } elseif (array_key_exists('slug', $parameters)) {
             $article = $this->dm->getRepository('SWP\\ContentBundle\\Document\\Article')->findOneBy(array('slug' => $parameters['slug']));
         }
         if (!is_null($article)) {
             return new Meta($this->rootDir . '/Resources/meta/article.yml', $article);
         }
     } elseif ($responseType === LoaderInterface::COLLECTION) {
         if (array_key_exists('pageName', $parameters)) {
             $page = $this->em->getRepository('SWP\\ContentBundle\\Model\\Page')->getByName($parameters['pageName'])->getOneOrNullResult();
             if ($page) {
                 $articlePages = $this->em->getRepository('SWP\\ContentBundle\\Model\\PageContent')->getForPage($page)->getResult();
                 $articles = [];
                 foreach ($articlePages as $articlePage) {
                     $article = $this->dm->find('SWP\\ContentBundle\\Document\\Article', $articlePage->getContentPath());
                     if (!is_null($article)) {
                         $articles[] = new Meta($this->rootDir . '/Resources/meta/article.yml', $article);
                     }
                 }
                 return $articles;
             }
         }
     }
     return false;
 }
开发者ID:copyfun,项目名称:web-renderer,代码行数:51,代码来源:ArticleLoader.php

示例2: testResetEvents

 public function testResetEvents()
 {
     $page = new CmsPage();
     $page->title = "my-page";
     $pageContent = new CmsPageContent();
     $pageContent->id = 1;
     $pageContent->content = "long story";
     $pageContent->formatter = "plaintext";
     $page->content = $pageContent;
     $this->dm->persist($page);
     $this->assertEquals(serialize(array('id' => $pageContent->id)), $page->content);
     $this->dm->flush();
     $this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\CmsPageContent', $page->content);
     // This is required as the originalData in the UnitOfWork doesn’t set the node of the Document
     $this->dm->clear();
     $pageLoaded = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsPage')->find($page->id);
     $pageLoaded->title = "my-page-changed";
     $this->assertEquals('my-page-changed', $pageLoaded->title);
     $this->dm->flush();
     $this->assertEquals('my-page', $pageLoaded->title);
     $pageLoaded->content = $pageContent;
     $this->dm->persist($pageLoaded);
     $this->dm->flush();
     $this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\CmsPageContent', $page->content);
 }
开发者ID:nikophil,项目名称:cmf-tests,代码行数:25,代码来源:EventManagerResetTest.php

示例3: testGetByIdsFilter

 public function testGetByIdsFilter()
 {
     $qb = $this->dm->getRepository('Doctrine\\Bundle\\PHPCRBundle\\Tests\\Resources\\Document\\TestDocument')->createQueryBuilder('e');
     $qb->where()->eq()->field('e.text')->literal('thiswillnotmatch');
     $loader = new PhpcrOdmQueryBuilderLoader($qb, $this->dm);
     $documents = $loader->getEntitiesByIds('id', array('/test/doc'));
     $this->assertCount(0, $documents);
 }
开发者ID:xabbuh,项目名称:DoctrinePHPCRBundle,代码行数:8,代码来源:PhpcrOdmQueryBuilderLoaderTest.php

示例4: testFiltered

 public function testFiltered()
 {
     $qb = $this->dm->getRepository('Doctrine\\Bundle\\PHPCRBundle\\Tests\\Resources\\Document\\TestDocument')->createQueryBuilder('e');
     $qb->where()->eq()->field('e.text')->literal('thiswillnotmatch');
     $formBuilder = $this->createFormBuilder($this->referrer);
     $formBuilder->add('single', $this->legacy ? 'phpcr_document' : 'Doctrine\\Bundle\\PHPCRBundle\\Form\\Type\\DocumentType', array('class' => 'Doctrine\\Bundle\\PHPCRBundle\\Tests\\Resources\\Document\\TestDocument', 'query_builder' => $qb));
     $html = $this->renderForm($formBuilder);
     $this->assertContains('<select id="form_single" name="form[single]"', $html);
     $this->assertNotContains('<option', $html);
 }
开发者ID:xabbuh,项目名称:DoctrinePHPCRBundle,代码行数:10,代码来源:DocumentTypeTest.php

示例5: load

 /**
  * {@inheritdoc}
  */
 public function load($sitemap)
 {
     $documentsCollection = $this->manager->getRepository('nvbooster\\StarterBundle\\Document\\SeoContent')->findAll();
     $documents = array();
     foreach ($documentsCollection as $document) {
         /* @var $document SeoContent */
         if (count($document->getRoutes())) {
             $documents[] = $document;
         }
     }
     return $documents;
 }
开发者ID:nvbooster,项目名称:StarterBundle,代码行数:15,代码来源:SeoContentLoader.php

示例6: testRepositoryQuery

 /**
  * @dataProvider queryRepositoryStatements
  */
 public function testRepositoryQuery($statement, $rowCount)
 {
     if ($rowCount == -1) {
         // magic to tell this is an invalid query
         $this->setExpectedException('PHPCR\\Query\\InvalidQueryException');
     }
     $repository = $this->dm->getRepository($this->type);
     $query = $repository->createQuery($statement, \PHPCR\Query\QueryInterface::JCR_SQL2);
     $this->assertInstanceOf('Doctrine\\ODM\\PHPCR\\Query\\Query', $query);
     $result = $query->execute();
     $this->assertCount($rowCount, $result);
 }
开发者ID:steffenbrem,项目名称:phpcr-odm,代码行数:15,代码来源:QuerySql2Test.php

示例7: generate

 /**
  * @param object $document
  * @param ClassMetadata $cm
  * @param DocumentManager $dm
  * @return string
  */
 public function generate($document, ClassMetadata $cm, DocumentManager $dm)
 {
     $repository = $dm->getRepository($cm->name);
     if (!$repository instanceof RepositoryIdInterface) {
         throw new \RuntimeException("ID could not be determined. Make sure the that the Repository '" . get_class($repository) . "' implements RepositoryIdInterface");
     }
     $id = $repository->generateId($document);
     if (!$id) {
         throw new \RuntimeException("ID could not be determined. Repository was unable to generate an ID");
     }
     return $id;
 }
开发者ID:nicam,项目名称:phpcr-odm,代码行数:18,代码来源:RepositoryIdGenerator.php

示例8: generate

 /**
  * Use a repository that implements RepositoryIdGenerator to generate the id.
  *
  * {@inheritDoc}
  */
 public function generate($document, ClassMetadata $class, DocumentManager $dm, $parent = null)
 {
     if (null === $parent) {
         $parent = $class->parentMapping ? $class->getFieldValue($document, $class->parentMapping) : null;
     }
     $repository = $dm->getRepository($class->name);
     if (!$repository instanceof RepositoryIdInterface) {
         throw new IdException("ID could not be determined. Make sure the that the Repository '" . ClassUtils::getClass($repository) . "' implements RepositoryIdInterface");
     }
     $id = $repository->generateId($document, $parent);
     if (!$id) {
         throw new IdException("ID could not be determined. Repository was unable to generate an ID");
     }
     return $id;
 }
开发者ID:nikophil,项目名称:cmf-tests,代码行数:20,代码来源:RepositoryIdGenerator.php

示例9: __construct

 /**
  * Construct a PHPCR-ODM Query Builder Loader.
  *
  * @param QueryBuilder|\Closure $queryBuilder
  * @param DocumentManager       $manager
  * @param string                $class
  */
 public function __construct($queryBuilder, DocumentManager $manager = null, $class = null)
 {
     // If a query builder was passed, it must be a closure or QueryBuilder
     // instance
     if (!($queryBuilder instanceof QueryBuilder || $queryBuilder instanceof \Closure)) {
         throw new UnexpectedTypeException($queryBuilder, 'Doctrine\\Common\\Persistence\\ObjectManager or \\Closure');
     }
     if ($queryBuilder instanceof \Closure) {
         $queryBuilder = $queryBuilder($manager->getRepository($class));
         if (!$queryBuilder instanceof QueryBuilder) {
             throw new UnexpectedTypeException($queryBuilder, 'Doctrine\\Common\\Persistence\\ObjectManager');
         }
     }
     $this->manager = $manager;
     $this->queryBuilder = $queryBuilder;
 }
开发者ID:xabbuh,项目名称:DoctrinePHPCRBundle,代码行数:23,代码来源:PhpcrOdmQueryBuilderLoader.php

示例10: testFindOneBy

 public function testFindOneBy()
 {
     $user1 = new CmsUser();
     $user1->username = "beberlei";
     $user1->status = "active";
     $user1->name = "Benjamin";
     $user2 = new CmsUser();
     $user2->username = "lsmith";
     $user2->status = "active";
     $user2->name = "Lukas";
     $this->dm->persist($user1);
     $this->dm->persist($user2);
     $this->dm->flush();
     $users1 = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findOneBy(array('username' => 'beberlei'));
     $this->assertEquals($user1->username, $users1->username);
     $users2 = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findOneBy(array('username' => 'obama'));
     $this->assertEquals(null, $users2);
 }
开发者ID:steffenbrem,项目名称:phpcr-odm,代码行数:18,代码来源:DocumentRepositoryTest.php

示例11: findOneBy

 protected function findOneBy($class, Request $request, $options)
 {
     if (!$options['mapping']) {
         $keys = $request->attributes->keys();
         $options['mapping'] = $keys ? array_combine($keys, $keys) : array();
     }
     foreach ($options['exclude'] as $exclude) {
         unset($options['mapping'][$exclude]);
     }
     if (!$options['mapping']) {
         return false;
     }
     $criteria = array();
     $metadata = $this->manager->getClassMetadata($class);
     foreach ($options['mapping'] as $attribute => $field) {
         if ($metadata->hasField($field) || $metadata->hasAssociation($field) && $metadata->isSingleValuedAssociation($field)) {
             $criteria[$field] = $request->attributes->get($attribute);
         }
     }
     if (!$criteria) {
         return false;
     }
     return $this->manager->getRepository($class)->findOneBy($criteria);
 }
开发者ID:Cohros,项目名称:KnowledgeBase,代码行数:24,代码来源:PHPCRParamConverter.php

示例12: findOneBy

 /**
  * {@inheritDoc}
  */
 public function findOneBy($class, array $criteria = array())
 {
     return $this->dm->getRepository($class)->findOneBy($criteria);
 }
开发者ID:Aaike,项目名称:SonataDoctrinePhpcrAdminBundle,代码行数:7,代码来源:ModelManager.php

示例13: getPostRepo

 protected function getPostRepo()
 {
     return $this->dm->getRepository('Symfony\\Cmf\\Bundle\\BlogBundle\\Document\\Post');
 }
开发者ID:symfony-cmf,项目名称:blog-bundle,代码行数:4,代码来源:BlogController.php

示例14: verifyProducts

 private function verifyProducts()
 {
     $tasks = $this->documentManager->getRepository('\\Hautelook\\AliceBundle\\Tests\\SymfonyApp\\TestBundle\\Document\\Task')->findAll();
     $this->assertCount(10, $tasks);
 }
开发者ID:ronanguilloux,项目名称:AliceBundle,代码行数:5,代码来源:DoctrinePHPCRFixturesTest.php

示例15: listGreetingsAction

 public function listGreetingsAction()
 {
     $greetings = $this->documentManager->getRepository('ZfPhpcrOdmSample\\Document\\Greeting')->getDocumentsByQuery($this->documentManager->getRepository('ZfPhpcrOdmSample\\Document\\Greeting')->createQuery('SELECT * FROM [nt:unstructured]', QueryInterface::JCR_SQL2));
     return array('greetings' => $greetings);
 }
开发者ID:ocramius,项目名称:zfphpcrodmsample,代码行数:5,代码来源:DocumentManagerController.php


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