本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例12: findOneBy
/**
* {@inheritDoc}
*/
public function findOneBy($class, array $criteria = array())
{
return $this->dm->getRepository($class)->findOneBy($criteria);
}
示例13: getPostRepo
protected function getPostRepo()
{
return $this->dm->getRepository('Symfony\\Cmf\\Bundle\\BlogBundle\\Document\\Post');
}
示例14: verifyProducts
private function verifyProducts()
{
$tasks = $this->documentManager->getRepository('\\Hautelook\\AliceBundle\\Tests\\SymfonyApp\\TestBundle\\Document\\Task')->findAll();
$this->assertCount(10, $tasks);
}
示例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);
}