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


PHP DocumentManager::getMetadataFactory方法代碼示例

本文整理匯總了PHP中Doctrine\ODM\PHPCR\DocumentManager::getMetadataFactory方法的典型用法代碼示例。如果您正苦於以下問題:PHP DocumentManager::getMetadataFactory方法的具體用法?PHP DocumentManager::getMetadataFactory怎麽用?PHP DocumentManager::getMetadataFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ODM\PHPCR\DocumentManager的用法示例。


在下文中一共展示了DocumentManager::getMetadataFactory方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setUp

 public function setUp()
 {
     if (!class_exists('Jackalope\\Factory', true)) {
         $this->markTestSkipped('The Node needs to be properly mocked/stubbed. Remove dependency to Jackalope');
     }
     $this->factory = new Factory();
     $this->session = $this->getMock('Jackalope\\Session', array(), array($this->factory), '', false);
     $this->objectManager = $this->getMock('Jackalope\\ObjectManager', array(), array($this->factory), '', false);
     $this->type = 'Doctrine\\Tests\\ODM\\PHPCR\\UoWUser';
     $this->dm = DocumentManager::create($this->session);
     $this->uow = new UnitOfWork($this->dm);
     $cmf = $this->dm->getMetadataFactory();
     $metadata = new ClassMetadata($this->type);
     $metadata->initializeReflection($cmf->getReflectionService());
     $metadata->mapId(array('fieldName' => 'id', 'id' => true));
     $metadata->idGenerator = ClassMetadata::GENERATOR_TYPE_ASSIGNED;
     $metadata->mapField(array('fieldName' => 'username', 'type' => 'string'));
     $cmf->setMetadataFor($this->type, $metadata);
 }
開發者ID:nikophil,項目名稱:cmf-tests,代碼行數:19,代碼來源:UnitOfWorkTest.php

示例2: hasMetadata

 /**
  * Returns true is the model has some metadata.
  *
  * @param string $class
  *
  * @return boolean
  */
 public function hasMetadata($class)
 {
     return $this->dm->getMetadataFactory()->hasMetadataFor($class);
 }
開發者ID:Aaike,項目名稱:SonataDoctrinePhpcrAdminBundle,代碼行數:11,代碼來源:ModelManager.php

示例3: createDocument

 /**
  * Create a document given class, data and the doc-id and revision
  *
  * Supported hints are
  * - refresh: reload the fields from the database
  * - locale: use this locale instead of the one from the annotation or the default
  * - fallback: whether to try other languages or throw a not found
  *      exception if the desired locale is not found. defaults to true if
  *      not set and locale is not given either.
  *
  * @param null|string $className
  * @param \PHPCR\NodeInterface $node
  * @param array $hints
  * @return object
  */
 public function createDocument($className, $node, array &$hints = array())
 {
     $requestedClassName = $className;
     $className = $this->documentClassMapper->getClassName($this->dm, $node, $className);
     $class = $this->dm->getClassMetadata($className);
     $documentState = array();
     $nonMappedData = array();
     $id = $node->getPath();
     // second param is false to get uuid rather than dereference reference properties to node instances
     $properties = $node->getPropertiesValues(null, false);
     foreach ($class->fieldMappings as $fieldName => $mapping) {
         if (isset($properties[$mapping['name']])) {
             if ($mapping['multivalue']) {
                 $collection = $properties[$mapping['name']] instanceof Collection ? $properties[$mapping['name']] : new ArrayCollection((array) $properties[$mapping['name']]);
                 $documentState[$fieldName] = new MultivaluePropertyCollection($collection);
                 $this->multivaluePropertyCollections[] = $documentState[$fieldName];
             } else {
                 $documentState[$fieldName] = $properties[$mapping['name']];
             }
         }
     }
     if ($class->node) {
         $documentState[$class->node] = $node;
     }
     if ($class->nodename) {
         $documentState[$class->nodename] = $node->getName();
     }
     if ($class->identifier) {
         $documentState[$class->identifier] = $node->getPath();
     }
     // collect uuids of all referenced nodes and get them all within one single call
     // they will get cached so you have more performance when they are accessed later
     $refNodeUUIDs = array();
     foreach ($class->associationsMappings as $assocOptions) {
         if (!$node->hasProperty($assocOptions['fieldName'])) {
             continue;
         }
         if ($assocOptions['type'] & ClassMetadata::MANY_TO_ONE) {
             $refNodeUUIDs[] = $node->getProperty($assocOptions['fieldName'])->getString();
         } elseif ($assocOptions['type'] & ClassMetadata::MANY_TO_MANY) {
             foreach ($node->getProperty($assocOptions['fieldName'])->getString() as $uuid) {
                 $refNodeUUIDs[] = $uuid;
             }
         }
     }
     if (count($refNodeUUIDs) > 0) {
         // ensure that the given nodes are in the in memory cache
         $this->session->getNodesByIdentifier($refNodeUUIDs);
     }
     // initialize inverse side collections
     foreach ($class->associationsMappings as $assocName => $assocOptions) {
         if ($assocOptions['type'] & ClassMetadata::MANY_TO_ONE) {
             // TODO figure this one out which collection should be used
             if (!$node->hasProperty($assocOptions['fieldName'])) {
                 continue;
             }
             // get the already cached referenced node
             $referencedNode = $node->getPropertyValue($assocOptions['fieldName']);
             $referencedClass = isset($assocOptions['targetDocument']) ? $this->dm->getMetadataFactory()->getMetadataFor(ltrim($assocOptions['targetDocument'], '\\'))->name : null;
             $proxy = $referencedClass ? $this->createProxy($referencedNode->getPath(), $referencedClass) : $this->createProxyFromNode($referencedNode);
             $documentState[$class->associationsMappings[$assocName]['fieldName']] = $proxy;
         } elseif ($assocOptions['type'] & ClassMetadata::MANY_TO_MANY) {
             if (!$node->hasProperty($assocOptions['fieldName'])) {
                 continue;
             }
             // get the already cached referenced nodes
             $proxyNodes = $node->getPropertyValue($assocOptions['fieldName']);
             if (!is_array($proxyNodes)) {
                 throw new PHPCRException('Expected referenced nodes passed as array.');
             }
             $referencedDocs = array();
             foreach ($proxyNodes as $referencedNode) {
                 $referencedClass = isset($assocOptions['targetDocument']) ? $this->dm->getMetadataFactory()->getMetadataFor(ltrim($assocOptions['targetDocument'], '\\'))->name : null;
                 $proxy = $referencedClass ? $this->createProxy($referencedNode->getPath(), $referencedClass) : $this->createProxyFromNode($referencedNode);
                 $referencedDocs[] = $proxy;
             }
             if (count($referencedDocs) > 0) {
                 $collection = new ReferenceManyCollection(new ArrayCollection($referencedDocs), true);
                 $documentState[$class->associationsMappings[$assocName]['fieldName']] = $collection;
             }
         }
     }
     if ($class->parentMapping && $node->getDepth() > 0) {
         // do not map parent to self if we are at root
         $documentState[$class->parentMapping] = $this->createProxyFromNode($node->getParent());
//.........這裏部分代碼省略.........
開發者ID:nicam,項目名稱:phpcr-odm,代碼行數:101,代碼來源:UnitOfWork.php

示例4: __construct

 /**
  * Initializes a new instance of the <tt>ProxyFactory</tt> class that is
  * connected to the given <tt>DocumentManager</tt>.
  *
  * @param DocumentManager $documentManager The DocumentManager the new factory works for.
  * @param string          $proxyDir        The directory to use for the proxy classes. It must exist.
  * @param string          $proxyNamespace  The namespace to use for the proxy classes.
  * @param boolean         $autoGenerate    Whether to automatically generate proxy classes.
  */
 public function __construct(DocumentManager $documentManager, $proxyDir, $proxyNamespace, $autoGenerate = false)
 {
     parent::__construct(new ProxyGenerator($proxyDir, $proxyNamespace), $documentManager->getMetadataFactory(), $autoGenerate);
     $this->documentManager = $documentManager;
     $this->proxyNamespace = $proxyNamespace;
 }
開發者ID:nikophil,項目名稱:cmf-tests,代碼行數:15,代碼來源:ProxyFactory.php

示例5: __construct

 public function __construct(DocumentManager $dm, QueryObjectModelFactoryInterface $qomf)
 {
     $this->qomf = $qomf;
     $this->mdf = $dm->getMetadataFactory();
     $this->dm = $dm;
 }
開發者ID:nikophil,項目名稱:cmf-tests,代碼行數:6,代碼來源:BuilderConverterPhpcr.php


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