public function setUp()
 {
     $this->dm = $this->db('PHPCR')->getOm();
     $this->db('PHPCR')->purgeRepository(true);
     $this->db('PHPCR')->createTestNode();
     $rootDocument = $this->dm->find(null, '/test');
     $document = new Generic();
     $document->setNodeName('foo');
     $document->setParentDocument($rootDocument);
     $this->dm->persist($document);
     $document = new Generic();
     $document->setNodeName('bar');
     $document->setParentDocument($rootDocument);
     $this->dm->persist($document);
     $this->dm->flush();
     $this->repositoryRegistry = $this->container->get('cmf_resource.registry');
 }
 /**
  * {@inheritdoc}
  */
 public function createAutoRoute($uri, $contentDocument, $autoRouteTag)
 {
     $basePath = $this->baseRoutePath;
     $document = $parentDocument = $this->dm->find(null, $basePath);
     if (null === $parentDocument) {
         throw new \RuntimeException(sprintf('The "route_basepath" configuration points to a non-existant path "%s".', $basePath));
     }
     $segments = preg_split('#/#', $uri, null, PREG_SPLIT_NO_EMPTY);
     $headName = array_pop($segments);
     foreach ($segments as $segment) {
         $basePath .= '/' . $segment;
         $document = $this->dm->find(null, $basePath);
         if (null === $document) {
             $document = new Generic();
             $document->setParent($parentDocument);
             $document->setNodeName($segment);
             $this->dm->persist($document);
         }
         $parentDocument = $document;
     }
     $path = $basePath . '/' . $headName;
     $existingDocument = $this->dm->find(null, $path);
     if ($existingDocument) {
         if ($existingDocument instanceof Generic) {
             return $this->migrateGenericToAutoRoute($existingDocument, $contentDocument, $autoRouteTag, AutoRouteInterface::TYPE_PRIMARY);
         }
         throw new \RuntimeException(sprintf('Encountered existing PHPCR-ODM document at path "%s" of class "%s", the route tree should ' . 'contain only instances of AutoRouteInterface.', $path, get_class($existingDocument)));
     }
     $headRoute = new $this->autoRouteFqcn();
     $headRoute->setContent($contentDocument);
     $headRoute->setName($headName);
     $headRoute->setParent($document);
     $headRoute->setAutoRouteTag($autoRouteTag);
     $headRoute->setType(AutoRouteInterface::TYPE_PRIMARY);
     return $headRoute;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function createAutoRoute($uri, $contentDocument, $autoRouteTag)
 {
     $path = $this->baseRoutePath;
     $document = $parentDocument = $this->dm->find(null, $path);
     if (null === $parentDocument) {
         throw new \RuntimeException(sprintf('The "route_basepath" configuration points to a non-existant path "%s".', $path));
     }
     $segments = preg_split('#/#', $uri, null, PREG_SPLIT_NO_EMPTY);
     $headName = array_pop($segments);
     foreach ($segments as $segment) {
         $path .= '/' . $segment;
         $document = $this->dm->find(null, $path);
         if (null === $document) {
             $document = new Generic();
             $document->setParent($parentDocument);
             $document->setNodeName($segment);
             $this->dm->persist($document);
         }
         $parentDocument = $document;
     }
     $headRoute = new $this->autoRouteFqcn();
     $headRoute->setContent($contentDocument);
     $headRoute->setName($headName);
     $headRoute->setParent($document);
     $headRoute->setAutoRouteTag($autoRouteTag);
     $headRoute->setType(AutoRouteInterface::TYPE_PRIMARY);
     return $headRoute;
 }