Exemplo n.º 1
0
 /**
  * Use the parent field together with an auto generated name to generate the id
  *
  * {@inheritDoc}
  */
 public function generate($document, ClassMetadata $class, DocumentManagerInterface $dm, $parent = null)
 {
     if (null === $parent) {
         $parent = $class->parentMapping ? $class->getFieldValue($document, $class->parentMapping) : null;
     }
     $id = $class->getFieldValue($document, $class->identifier);
     if (empty($id) && null === $parent) {
         throw IdException::noIdNoParent($document, $class->parentMapping);
     }
     if (empty($parent)) {
         return $id;
     }
     try {
         $parentNode = $dm->getNodeForDocument($parent);
         $existingNames = (array) $parentNode->getNodeNames();
     } catch (RepositoryException $e) {
         // this typically happens while cascading persisting documents
         $existingNames = array();
     }
     $name = NodeHelper::generateAutoNodeName($existingNames, $dm->getPhpcrSession()->getWorkspace()->getNamespaceRegistry()->getNamespaces(), '', '');
     return $this->buildName($document, $class, $dm, $parent, $name);
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function addNodeAutoNamed($nameHint = null, $primaryNodeTypeName = null)
 {
     $name = NodeHelper::generateAutoNodeName($this->nodes, $this->session->getWorkspace()->getNamespaceRegistry()->getNamespaces(), 'jcr', $nameHint);
     return $this->addNode($name, $primaryNodeTypeName);
 }
Exemplo n.º 3
0
 /**
  * @dataProvider invalidHints
  * @expectedException \PHPCR\RepositoryException
  */
 public function testGenerateAutoNodeNameInvalid($hint)
 {
     NodeHelper::generateAutoNodeName($this->usedNames, $this->namespaces, 'a', $hint);
 }