本文整理汇总了PHP中Doctrine\ODM\PHPCR\DocumentManager类的典型用法代码示例。如果您正苦于以下问题:PHP DocumentManager类的具体用法?PHP DocumentManager怎么用?PHP DocumentManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DocumentManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: createMenuNode
/**
* @return a Navigation instance with the specified information
*/
protected function createMenuNode(DocumentManager $dm, $parent, $name, $label, $content, $uri = null, $route = null)
{
if (!$parent instanceof MenuNode && !$parent instanceof Menu) {
$menuNode = new Menu();
} else {
$menuNode = new MenuNode();
}
$menuNode->setParent($parent);
$menuNode->setName($name);
$dm->persist($menuNode);
// do persist before binding translation
if (null !== $content) {
$menuNode->setContent($content);
} else {
if (null !== $uri) {
$menuNode->setUri($uri);
} else {
if (null !== $route) {
$menuNode->setRoute($route);
}
}
}
if (is_array($label)) {
foreach ($label as $locale => $l) {
$menuNode->setLabel($l);
$dm->bindTranslation($menuNode, $locale);
}
} else {
$menuNode->setLabel($label);
}
return $menuNode;
}
开发者ID:reyostallenberg,项目名称:PiccoloStandard,代码行数:35,代码来源:LoadMenuData.php
示例2: __construct
/**
* Constructor
*
* @param SessionInterface $session
* @param DocumentManager $dm
*/
public function __construct(SessionInterface $session = null, DocumentManager $dm = null)
{
if (!$session && $dm) {
$session = $dm->getPhpcrSession();
}
parent::__construct($session);
$this->dm = $dm;
}
开发者ID:nikophil,项目名称:cmf-tests,代码行数:14,代码来源:DocumentManagerHelper.php
示例3: validateClassName
/**
* @param DocumentManager
* @param object $document
* @param string $className
* @throws \InvalidArgumentException
*/
public function validateClassName(DocumentManager $dm, $document, $className)
{
if (!$document instanceof $className) {
$class = $dm->getClassMetadata(get_class($document));
$path = $class->getIdentifierValue($document);
$msg = "Doctrine metadata mismatch! Requested type '{$className}' type does not match type '" . get_class($document) . "' stored in the metadata at path '{$path}'";
throw new \InvalidArgumentException($msg);
}
}
开发者ID:richardmiller,项目名称:phpcr-odm,代码行数:15,代码来源:DocumentClassMapper.php
示例4: setUp
public function setUp()
{
$this->dm = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock();
$this->dm->expects($this->once())->method('find')->will($this->returnValue(new \stdClass()));
$this->defaultModelManager = $this->getMockBuilder('Sonata\\DoctrinePHPCRAdminBundle\\Model\\ModelManager')->disableOriginalConstructor()->getMock();
$this->translator = $this->getMockBuilder('Symfony\\Component\\Translation\\TranslatorInterface')->disableOriginalConstructor()->getMock();
$this->assetHelper = $this->getMockBuilder('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper')->disableOriginalConstructor()->getMock();
$this->pool = $this->getMockBuilder('Sonata\\AdminBundle\\Admin\\Pool')->disableOriginalConstructor()->getMock();
}
开发者ID:Aaike,项目名称:SonataDoctrinePhpcrAdminBundle,代码行数:9,代码来源:PhpcrOdmTreeTest.php
示例5: createPage
/**
* @return Page instance with the specified information
*/
protected function createPage(DocumentManager $manager, $parent, $name, $label, $title, $body)
{
$page = new Page();
$page->setPosition($parent, $name);
$page->setLabel($label);
$page->setTitle($title);
$page->setBody($body);
$manager->persist($page);
return $page;
}
开发者ID:nikophil,项目名称:cmf-tests,代码行数:13,代码来源:LoadPageData.php
示例6: createRepository
/**
* Create a new repository instance for a document class.
*
* @param DocumentManager $documentManager The DocumentManager instance.
* @param string $documentName The name of the document.
*
* @return \Doctrine\Common\Persistence\ObjectRepository
*/
protected function createRepository(DocumentManager $documentManager, $documentName)
{
$metadata = $documentManager->getClassMetadata($documentName);
$repositoryClassName = $metadata->customRepositoryClassName;
if ($repositoryClassName === null) {
$configuration = $documentManager->getConfiguration();
$repositoryClassName = $configuration->getDefaultRepositoryClassName();
}
return new $repositoryClassName($documentManager, $metadata);
}
开发者ID:nikophil,项目名称:cmf-tests,代码行数:18,代码来源:DefaultRepositoryFactory.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: mkdir
/**
* @param DocumentManager $dm
* @param $path
* @param $name
*
* @return bool|Directory
*/
public static function mkdir(DocumentManager $dm, $path, $name)
{
$dirname = self::cleanPath($path, $name);
if ($dm->find(null, $dirname)) {
return false;
}
$dir = new Directory();
$dir->setName($name);
$dir->setId($dirname);
$dm->persist($dir);
$dm->flush();
return $dir;
}
开发者ID:selfclose,项目名称:dos-cernel-bundle,代码行数:20,代码来源:ManagerHelper.php
示例9: buildName
protected function buildName($document, ClassMetadata $class, DocumentManager $dm, $parent, $name)
{
// get the id of the parent document
$id = $dm->getUnitOfWork()->getDocumentId($parent);
if (!$id) {
throw IdException::parentIdCouldNotBeDetermined($document, $class->parentMapping, $parent);
}
// edge case parent is root
if ('/' === $id) {
$id = '';
}
return $id . '/' . $name;
}
开发者ID:nikophil,项目名称:cmf-tests,代码行数:13,代码来源:ParentIdGenerator.php
示例10: createGuesser
/**
* Create the guesser for this test.
*
* @return GuesserInterface
*/
protected function createGuesser()
{
$this->registry = $this->getMockBuilder('\\Doctrine\\Bundle\\PHPCRBundle\\ManagerRegistry')->disableOriginalConstructor()->getMock();
$this->manager = $this->getMockBuilder('\\Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock();
$this->metadata = $this->getMockBuilder('\\Doctrine\\ODM\\PHPCR\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
$this->registry->expects($this->any())->method('getManagerForClass')->with($this->equalTo('Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Unit\\Sitemap\\LastModifiedGuesserTest'))->will($this->returnValue($this->manager));
$this->manager->expects($this->any())->method('getClassMetadata')->with($this->equalTo('Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Unit\\Sitemap\\LastModifiedGuesserTest'))->will($this->returnValue($this->metadata));
$this->metadata->expects($this->any())->method('getMixins')->will($this->returnValue(array('mix:lastModified')));
$this->metadata->expects($this->any())->method('getFieldNames')->will($this->returnValue(array('lastModified')));
$this->metadata->expects($this->any())->method('getFieldMapping')->with($this->equalTo('lastModified'))->will($this->returnValue(array('property' => 'jcr:lastModified')));
$this->metadata->expects($this->any())->method('getFieldValue')->with($this->equalTo($this), $this->equalTo('lastModified'))->will($this->returnValue(new \DateTime('2016-07-06', new \DateTimeZone('Europe/Berlin'))));
return new LastModifiedGuesser($this->registry);
}
开发者ID:symfony-cmf,项目名称:seo-bundle,代码行数:18,代码来源:LastModifiedGuesserTest.php
示例11: resetFunctionalNode
public function resetFunctionalNode(DocumentManager $dm)
{
$session = $dm->getPhpcrSession();
$root = $session->getNode('/');
if ($root->hasNode('functional')) {
$root->getNode('functional')->remove();
$session->save();
}
$node = $root->addNode('functional');
$session->save();
$dm->clear();
return $node;
}
开发者ID:nikophil,项目名称:cmf-tests,代码行数:13,代码来源:PHPCRFunctionalTestCase.php
示例12: setUp
protected function setUp()
{
if (!interface_exists('Doctrine\\Common\\Persistence\\ManagerRegistry')) {
$this->markTestSkipped('Doctrine Common is not present');
}
if (!class_exists('Doctrine\\ODM\\PHPCR\\DocumentManager')) {
$this->markTestSkipped('Doctrine PHPCR is not present');
}
$this->registry = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ManagerRegistry')->disableOriginalConstructor()->getMock();
$this->manager = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock();
$this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->manager));
$this->repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository', array('customQueryBuilderCreator', 'createQueryBuilder', 'find', 'findAll', 'findBy', 'findOneBy', 'getClassName'));
$this->manager->expects($this->any())->method('getRepository')->with($this->objectClass)->will($this->returnValue($this->repository));
}
开发者ID:anteros,项目名称:FOSElasticaBundle,代码行数:14,代码来源:ElasticaToModelTransformerTest.php
示例13: createAction
public function createAction()
{
// bind form to page model
$page = new Page();
$this->form->bind($this->request, $page);
if ($this->form->isValid()) {
try {
// path for page
$parent = $this->form->get('parent')->getData();
$path = $parent . '/' . $page->name;
// save page
$this->dm->persist($page, $path);
$this->dm->flush();
// redirect with message
$this->request->getSession()->setFlash('notice', 'Page created!');
return $this->redirect($this->generateUrl('admin'));
} catch (HTTPErrorException $e) {
$path = new PropertyPath('name');
$this->form->addError(new DataError('Name already in use.'), $path->getIterator());
}
}
return $this->render('SandboxAdminBundle:Admin:create.html.twig', array('form' => $this->form));
}
开发者ID:regisg27,项目名称:cmf-sandbox,代码行数:32,代码来源:DefaultController.php
示例14: 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
示例15: 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
示例16: 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
示例17: renderArticleLocale
/**
* @param \ServerGrove\KbBundle\Document\Article $article
* @param string $locale
* @return string
*/
public function renderArticleLocale(Article $article, $locale)
{
try {
$active = $this->manager->findTranslation(get_class($article), $article->getId(), $locale, false)->getIsActive();
} catch (\InvalidArgumentException $e) {
$active = false;
}
$this->manager->refresh($article);
return $this->twig->renderBlock('article_locale', array('active' => $active, 'locale' => $locale, 'locale_name' => Locale::getDisplayLanguage($locale)));
}
开发者ID:Cohros,项目名称:KnowledgeBase,代码行数:15,代码来源:ArticleExtension.php
示例18: testReferenceOneDifferentTargetDocuments
public function testReferenceOneDifferentTargetDocuments()
{
$ref1 = new RefType1TestObj();
$ref1->id = '/functional/ref1';
$ref1->name = 'Ref1';
$ref2 = new RefType2TestObj();
$ref2->id = '/functional/ref2';
$ref2->name = 'Ref2';
$this->dm->persist($ref1);
$this->dm->persist($ref2);
$referer1 = new ReferenceOneObj();
$referer1->id = '/functional/referer1';
$referer1->reference = $ref1;
$this->dm->persist($referer1);
$referer2 = new ReferenceOneObj();
$referer2->id = '/functional/referer2';
$referer2->reference = $ref2;
$this->dm->persist($referer2);
$this->dm->flush();
$this->dm->clear();
$referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer1');
$this->assertTrue($referer->reference instanceof RefType1TestObj);
$referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer2');
$this->assertTrue($referer->reference instanceof RefType2TestObj);
}
开发者ID:steffenbrem,项目名称:phpcr-odm,代码行数:25,代码来源:TargetDocumentTest.php
示例19: getContentId
/**
* {@inheritDoc}
*/
public function getContentId($content)
{
if (!is_object($content)) {
return null;
}
try {
return $this->documentManager->getUnitOfWork()->getDocumentId($content);
} catch (\Exception $e) {
return null;
}
}
开发者ID:symfony-cmf,项目名称:routing-extra-bundle,代码行数:14,代码来源:ContentRepository.php
示例20: testMigrator
public function testMigrator()
{
$this->migrator->migrate('/test/page');
$this->migrator->migrate('/test/page/foo');
$res = $this->dm->find(null, '/test/page');
$this->assertNotNull($res);
$this->assertEquals('Test', $res->getTitle());
$res = $this->dm->find(null, '/test/page/foo');
$this->assertNotNull($res);
$this->assertEquals('Foobar', $res->getTitle());
}
开发者ID:creatiombe,项目名称:SimpleCmsBundle,代码行数:11,代码来源:PageTest.php
注:本文中的Doctrine\ODM\PHPCR\DocumentManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论