This handler is used by default, if an objectType is specified for a route part in the routing configuration: - name: 'Some route for xyz entities' uriPattern: '{xyz}' routeParts: 'xyz': objectType: 'Some\Package\Domain\Model\Xyz'
또한 보기: Neos\Flow\Mvc\Routing\ObjectPathMapping
상속: extends DynamicRoutePart
 /**
  * @test
  * @expectedException \Neos\Flow\Mvc\Exception\InfiniteLoopException
  */
 public function resolveValueThrowsInfiniteLoopExceptionIfNoUniquePathSegmentCantBeFound()
 {
     $object = new \stdClass();
     $this->mockPersistenceManager->expects($this->atLeastOnce())->method('getIdentifierByObject')->with($object)->will($this->returnValue('TheIdentifier'));
     $this->mockPersistenceManager->expects($this->atLeastOnce())->method('getObjectByIdentifier')->with('TheIdentifier')->will($this->returnValue($object));
     $this->mockObjectPathMappingRepository->expects($this->once())->method('findOneByObjectTypeUriPatternAndIdentifier')->with('stdClass', 'SomeUriPattern', 'TheIdentifier')->will($this->returnValue(null));
     $existingObjectPathMapping = new ObjectPathMapping();
     $existingObjectPathMapping->setObjectType('stdClass');
     $existingObjectPathMapping->setUriPattern('SomeUriPattern');
     $existingObjectPathMapping->setPathSegment('The/Path/Segment');
     $existingObjectPathMapping->setIdentifier('AnotherIdentifier');
     $this->identityRoutePart->expects($this->once())->method('createPathSegmentForObject')->with($object)->will($this->returnValue('The/Path/Segment'));
     $this->mockObjectPathMappingRepository->expects($this->atLeastOnce())->method('findOneByObjectTypeUriPatternAndPathSegment')->will($this->returnValue($existingObjectPathMapping));
     $this->identityRoutePart->setObjectType('stdClass');
     $this->identityRoutePart->setUriPattern('SomeUriPattern');
     $this->identityRoutePart->_call('resolveValue', $object);
 }
예제 #2
0
 /**
  * Iterates through all segments in $this->uriPattern and creates
  * appropriate RoutePart instances.
  *
  * @return void
  * @throws InvalidRoutePartHandlerException
  * @throws InvalidUriPatternException
  */
 public function parse()
 {
     if ($this->isParsed || $this->uriPattern === null || $this->uriPattern === '') {
         return;
     }
     $this->routeParts = [];
     $currentRoutePartIsOptional = false;
     if (substr($this->uriPattern, -1) === '/') {
         throw new InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" ends with a slash, which is not allowed. You can put the trailing slash in brackets to make it optional.', 1234782997);
     }
     if ($this->uriPattern[0] === '/') {
         throw new InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" starts with a slash, which is not allowed.', 1234782983);
     }
     $matches = [];
     preg_match_all(self::PATTERN_EXTRACTROUTEPARTS, $this->uriPattern, $matches, PREG_SET_ORDER);
     /** @var $lastRoutePart RoutePartInterface */
     $lastRoutePart = null;
     foreach ($matches as $match) {
         $routePartType = empty($match['dynamic']) ? self::ROUTEPART_TYPE_STATIC : self::ROUTEPART_TYPE_DYNAMIC;
         $routePartName = $match['content'];
         if (!empty($match['optionalStart'])) {
             if ($lastRoutePart !== null && $lastRoutePart->isOptional()) {
                 throw new InvalidUriPatternException('the URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains successive optional Route sections, which is not allowed.', 1234562050);
             }
             $currentRoutePartIsOptional = true;
         }
         $routePart = null;
         switch ($routePartType) {
             case self::ROUTEPART_TYPE_DYNAMIC:
                 if ($lastRoutePart instanceof DynamicRoutePartInterface) {
                     throw new InvalidUriPatternException('the URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains successive Dynamic Route Parts, which is not allowed.', 1218446975);
                 }
                 if (isset($this->routePartsConfiguration[$routePartName]['handler'])) {
                     $routePart = $this->objectManager->get($this->routePartsConfiguration[$routePartName]['handler']);
                     if (!$routePart instanceof DynamicRoutePartInterface) {
                         throw new InvalidRoutePartHandlerException(sprintf('routePart handlers must implement "%s" in route "%s"', DynamicRoutePartInterface::class, $this->getName()), 1218480972);
                     }
                 } elseif (isset($this->routePartsConfiguration[$routePartName]['objectType'])) {
                     $routePart = new IdentityRoutePart();
                     $routePart->setObjectType($this->routePartsConfiguration[$routePartName]['objectType']);
                     if (isset($this->routePartsConfiguration[$routePartName]['uriPattern'])) {
                         $routePart->setUriPattern($this->routePartsConfiguration[$routePartName]['uriPattern']);
                     }
                 } else {
                     $routePart = new DynamicRoutePart();
                 }
                 $routePartDefaultValue = ObjectAccess::getPropertyPath($this->defaults, $routePartName);
                 if ($routePartDefaultValue !== null) {
                     $routePart->setDefaultValue($routePartDefaultValue);
                 }
                 break;
             case self::ROUTEPART_TYPE_STATIC:
                 $routePart = new StaticRoutePart();
                 if ($lastRoutePart !== null && $lastRoutePart instanceof DynamicRoutePartInterface) {
                     /** @var DynamicRoutePartInterface $lastRoutePart */
                     $lastRoutePart->setSplitString($routePartName);
                 }
         }
         $routePart->setName($routePartName);
         if ($currentRoutePartIsOptional) {
             $routePart->setOptional(true);
             if ($routePart instanceof DynamicRoutePartInterface && !$routePart->hasDefaultValue()) {
                 throw new InvalidRouteSetupException(sprintf('There is no default value specified for the optional route part "{%s}" of route "%s", but all dynamic optional route parts need a default.', $routePartName, $this->getName()), 1477140679);
             }
         }
         $routePart->setLowerCase($this->lowerCase);
         if (isset($this->routePartsConfiguration[$routePartName]['options'])) {
             $routePart->setOptions($this->routePartsConfiguration[$routePartName]['options']);
         }
         if (isset($this->routePartsConfiguration[$routePartName]['toLowerCase'])) {
             $routePart->setLowerCase($this->routePartsConfiguration[$routePartName]['toLowerCase']);
         }
         $this->routeParts[] = $routePart;
         if (!empty($match['optionalEnd'])) {
             if (!$currentRoutePartIsOptional) {
                 throw new InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains an unopened optional section.', 1234564495);
             }
             $currentRoutePartIsOptional = false;
         }
         $lastRoutePart = $routePart;
     }
     if ($currentRoutePartIsOptional) {
         throw new InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains an unterminated optional section.', 1234563922);
     }
     $this->isParsed = true;
 }