public function setup()
 {
     $this->dm = $this->createDocumentManager();
     $this->session = $this->dm->getPhpcrSession();
     $this->workspace = $this->dm->getPhpcrSession()->getWorkspace();
     $this->metadata = $this->dm->getClassMetadata('Doctrine\\Tests\\Models\\Translation\\Article');
 }
Ejemplo n.º 2
0
 public function setUp()
 {
     $this->dm = $this->createDocumentManager(array(__DIR__));
     $this->node = $this->resetFunctionalNode($this->dm);
     $class = $this->dm->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $class->mappings['groups']['cascade'] = ClassMetadata::CASCADE_PERSIST;
     $class = $this->dm->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsGroup');
     $class->mappings['users']['cascade'] = ClassMetadata::CASCADE_PERSIST;
     $class = $this->dm->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsArticle');
     $class->mappings['user']['cascade'] = ClassMetadata::CASCADE_PERSIST;
 }
Ejemplo n.º 3
0
 public function setUp()
 {
     $this->dm = $this->createDocumentManager();
     $this->dm->setLocaleChooserStrategy(new LocaleChooser($this->localePrefs, 'en'));
     $this->node = $this->resetFunctionalNode($this->dm);
     $this->dm->clear();
     $this->session = $this->dm->getPhpcrSession();
     $this->metadata = $this->dm->getClassMetadata($this->class);
     $this->doc = new Article();
     $this->doc->id = '/functional/' . $this->testNodeName;
     $this->doc->author = 'John Doe';
     $this->doc->topic = 'Some interesting subject';
     $this->doc->setText('Lorem ipsum...');
     $this->doc->setSettings(array());
     $this->doc->assoc = array('key' => 'value');
 }
 /**
  * @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);
     }
 }
 /**
  * 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);
 }
Ejemplo n.º 6
0
 private function getFullVersionedNodePath($document)
 {
     $path = $this->getDocumentId($document);
     $metadata = $this->dm->getClassMetadata(get_class($document));
     if ($metadata->versionable !== 'full') {
         throw new \InvalidArgumentException(sprintf("The document at '%s' is not full versionable", $path));
     }
     $node = $this->session->getNode($path);
     $node->addMixin('mix:versionable');
     return $path;
 }
Ejemplo n.º 7
0
 private function getVersionedNodePath($document)
 {
     $path = $this->getDocumentId($document);
     $metadata = $this->dm->getClassMetadata(get_class($document));
     if (!$metadata->versionable) {
         throw new InvalidArgumentException(sprintf("The document at path '%s' is not versionable", $path));
     }
     $node = $this->session->getNode($path);
     $mixin = $metadata->versionable === 'simple' ? 'mix:simpleVersionable' : 'mix:versionable';
     if (!$node->isNodeType($mixin)) {
         $node->addMixin($mixin);
     }
     return $path;
 }
Ejemplo n.º 8
0
 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);
 }
 /**
  * @dataProvider invalidIdProvider
  *
  * @expectedException \Doctrine\ODM\PHPCR\Mapping\MappingException
  *
  * @param string $class fqn of a class with invalid mapping
  */
 public function testInvalidId($class)
 {
     $this->dm->getClassMetadata($class);
 }