コード例 #1
0
 public function testGetSet()
 {
     $uriContext = new UriContext($this->subjectObject, '/uri/', array('default1' => 'value1'), array('token'), array('conflict'), 'fr');
     // locales
     $this->assertEquals('fr', $uriContext->getLocale());
     /// uri
     $this->assertEquals(null, $uriContext->getUri());
     $uriContext->setUri('/foo/bar');
     $this->assertEquals('/foo/bar', $uriContext->getUri());
     // subject object
     $this->assertEquals($this->subjectObject, $uriContext->getSubjectObject());
     // auto route
     $uriContext->setAutoRoute($this->autoRoute);
     $this->assertEquals($this->autoRoute, $uriContext->getAutoRoute());
     // the translated subject should be initially set as the original subject
     $this->assertSame($this->subjectObject, $uriContext->getTranslatedSubjectObject());
     $transSubject = new \stdClass();
     $uriContext->setTranslatedSubjectObject($transSubject);
     $this->assertSame($transSubject, $uriContext->getTranslatedSubjectObject());
     // uri schema
     $this->assertEquals('/uri/', $uriContext->getUriSchema());
     // token provider configs
     $this->assertEquals(array('token'), $uriContext->getTokenProviderConfigs());
     // conflict resolver configs
     $this->assertEquals(array('conflict'), $uriContext->getConflictResolverConfig());
     // defaults
     $this->assertEquals(array('default1' => 'value1'), $uriContext->getDefaults());
 }
コード例 #2
0
 public function testGetSet()
 {
     $uriContext = new UriContext($this->subjectObject, 'fr');
     // locales
     $this->assertEquals('fr', $uriContext->getLocale());
     /// uri
     $this->assertEquals(null, $uriContext->getUri());
     $uriContext->setUri('/foo/bar');
     $this->assertEquals('/foo/bar', $uriContext->getUri());
     // subject object
     $this->assertEquals($this->subjectObject, $uriContext->getSubjectObject());
     // auto route
     $uriContext->setAutoRoute($this->autoRoute);
     $this->assertEquals($this->autoRoute, $uriContext->getAutoRoute());
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function resolveConflict(UriContext $uriContext)
 {
     $this->inc = 0;
     $uri = $uriContext->getUri();
     $candidateUri = $this->incrementUri($uri);
     while ($route = $this->adapter->findRouteForUri($candidateUri, $uriContext)) {
         $candidateUri = $this->incrementUri($uri);
     }
     return $candidateUri;
 }
コード例 #4
0
 /**
  * {@inheritDoc}
  */
 public function resolveConflict(UriContext $uriContext)
 {
     $uri = $uriContext->getUri();
     throw new Exception\ExistingUriException(sprintf('There already exists an auto route for URL "%s" and the system is configured ' . 'to throw this exception in this case. Alternatively you can choose to use a ' . 'different strategy, for example, auto incrementation. Please refer to the ' . 'documentation for more information.', $uri));
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function createAutoRoute(UriContext $uriContext, $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('#/#', $uriContext->getUri(), 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;
 }