/**
  * {@inheritdoc}
  *
  * @param object $element
  * @param string $propertyPath
  * @return mixed
  */
 protected function getPropertyPath($element, $propertyPath)
 {
     if ($propertyPath[0] === '_') {
         return \TYPO3\FLOW3\Reflection\ObjectAccess::getPropertyPath($element, substr($propertyPath, 1));
     } else {
         return $element->getProperty($propertyPath);
     }
 }
Exemple #2
0
 /**
  * Updates the password credential from the POST vars, if the POST parameters
  * are available. Sets the authentication status to AUTHENTICATION_NEEDED, if credentials have been sent.
  *
  * Note: You need to send the password in this POST parameter:
  *       __authentication[TYPO3][FLOW3][Security][Authentication][Token][PasswordToken][password]
  *
  * @param \TYPO3\FLOW3\Mvc\ActionRequest $actionRequest The current action request
  * @return void
  */
 public function updateCredentials(\TYPO3\FLOW3\Mvc\ActionRequest $actionRequest)
 {
     if ($actionRequest->getHttpRequest()->getMethod() !== 'POST') {
         return;
     }
     $postArguments = $actionRequest->getInternalArguments();
     $password = \TYPO3\FLOW3\Reflection\ObjectAccess::getPropertyPath($postArguments, '__authentication.TYPO3.FLOW3.Security.Authentication.Token.PasswordToken.password');
     if (!empty($password)) {
         $this->credentials['password'] = $password;
         $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED);
     }
 }
 /**
  * {@inheritdoc}
  *
  * @param \TYPO3\Eel\FlowQuery\FlowQuery $flowQuery the FlowQuery object
  * @param array $arguments the arguments for this operation
  * @return mixed|null if the operation is final, the return value
  */
 public function evaluate(\TYPO3\Eel\FlowQuery\FlowQuery $flowQuery, array $arguments)
 {
     if (!isset($arguments[0]) || empty($arguments[0])) {
         throw new \TYPO3\Eel\FlowQuery\FlowQueryException('property() does not support returning all attributes yet', 1332492263);
     } else {
         $context = $flowQuery->getContext();
         $propertyPath = $arguments[0];
         if (!isset($context[0])) {
             return NULL;
         }
         $element = $context[0];
         if ($propertyPath[0] === '_') {
             return \TYPO3\FLOW3\Reflection\ObjectAccess::getPropertyPath($element, substr($propertyPath, 1));
         } else {
             return $element->getProperty($propertyPath);
         }
     }
 }
Exemple #4
0
 /**
  * @test
  */
 public function getPropertyPathReturnsNullIfSubjectOnPathIsNoObject()
 {
     $object = new \stdClass();
     $object->foo = 'Hello World';
     $this->assertNull(\TYPO3\FLOW3\Reflection\ObjectAccess::getPropertyPath($object, 'foo.bar'));
 }
 /**
  * Redirects directly to \TYPO3\FLOW3\Reflection\ObjectAccess::getPropertyPath($result, $propertyPath)
  * This is only needed for unit tests!
  *
  * @param mixed $object The object to fetch the property from
  * @param string $path The path to the property to be fetched
  * @return mixed The property value
  */
 protected function getObjectValueByPath($object, $path)
 {
     return \TYPO3\FLOW3\Reflection\ObjectAccess::getPropertyPath($object, $path);
 }
Exemple #6
0
 /**
  * Creates a URI representation (path segment) for the given object matching $this->uriPattern.
  *
  * @param mixed $object object of type $this->objectType
  * @return string URI representation (path segment) of the given object
  * @throws \TYPO3\FLOW3\Mvc\Exception\InvalidUriPatternException
  */
 protected function createPathSegmentForObject($object)
 {
     $uriPattern = $this->getUriPattern();
     if ($uriPattern === '') {
         return $this->rewriteForUri($this->persistenceManager->getIdentifierByObject($object));
     }
     $matches = array();
     preg_match_all('/(?P<dynamic>{?)(?P<content>[^}{]+)}?/', $uriPattern, $matches, PREG_SET_ORDER);
     $pathSegment = '';
     foreach ($matches as $match) {
         if (empty($match['dynamic'])) {
             $pathSegment .= $match['content'];
         } else {
             $dynamicPathSegmentParts = explode(':', $match['content']);
             $propertyPath = $dynamicPathSegmentParts[0];
             $dynamicPathSegment = \TYPO3\FLOW3\Reflection\ObjectAccess::getPropertyPath($object, $propertyPath);
             if (is_object($dynamicPathSegment)) {
                 if ($dynamicPathSegment instanceof \DateTime) {
                     $dateFormat = isset($dynamicPathSegmentParts[1]) ? trim($dynamicPathSegmentParts[1]) : 'Y-m-d';
                     $pathSegment .= $this->rewriteForUri($dynamicPathSegment->format($dateFormat));
                 } else {
                     throw new \TYPO3\FLOW3\Mvc\Exception\InvalidUriPatternException('Invalid uriPattern "' . $uriPattern . '" for route part "' . $this->getName() . '". Property "' . $propertyPath . '" must be of type string or \\DateTime. "' . (is_object($dynamicPathSegment) ? get_class($dynamicPathSegment) : gettype($dynamicPathSegment)) . '" given.', 1316442409);
                 }
             } else {
                 $pathSegment .= $this->rewriteForUri($dynamicPathSegment);
             }
         }
     }
     return $pathSegment;
 }
Exemple #7
0
 /**
  * Iterates through all segments in $this->uriPattern and creates
  * appropriate RoutePart instances.
  *
  * @return void
  * @throws \TYPO3\FLOW3\Mvc\Exception\InvalidRoutePartHandlerException
  * @throws \TYPO3\FLOW3\Mvc\Exception\InvalidUriPatternException
  */
 public function parse()
 {
     if ($this->isParsed || $this->uriPattern === NULL || $this->uriPattern === '') {
         return;
     }
     $this->routeParts = array();
     $currentRoutePartIsOptional = FALSE;
     if (substr($this->uriPattern, -1) === '/') {
         throw new \TYPO3\FLOW3\Mvc\Exception\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 \TYPO3\FLOW3\Mvc\Exception\InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" starts with a slash, which is not allowed.', 1234782983);
     }
     $matches = array();
     preg_match_all(self::PATTERN_EXTRACTROUTEPARTS, $this->uriPattern, $matches, PREG_SET_ORDER);
     $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 \TYPO3\FLOW3\Mvc\Exception\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 \TYPO3\FLOW3\Mvc\Routing\DynamicRoutePartInterface) {
                     throw new \TYPO3\FLOW3\Mvc\Exception\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 \TYPO3\FLOW3\Mvc\Routing\DynamicRoutePartInterface) {
                         throw new \TYPO3\FLOW3\Mvc\Exception\InvalidRoutePartHandlerException('routePart handlers must implement "\\TYPO3\\FLOW3\\Mvc\\Routing\\DynamicRoutePartInterface" in route "' . $this->getName() . '"', 1218480972);
                     }
                 } elseif (isset($this->routePartsConfiguration[$routePartName]['objectType'])) {
                     $routePart = new \TYPO3\FLOW3\Mvc\Routing\IdentityRoutePart();
                     $routePart->setObjectType($this->routePartsConfiguration[$routePartName]['objectType']);
                     if (isset($this->routePartsConfiguration[$routePartName]['uriPattern'])) {
                         $routePart->setUriPattern($this->routePartsConfiguration[$routePartName]['uriPattern']);
                     }
                 } else {
                     $routePart = new \TYPO3\FLOW3\Mvc\Routing\DynamicRoutePart();
                 }
                 $routePartDefaultValue = \TYPO3\FLOW3\Reflection\ObjectAccess::getPropertyPath($this->defaults, $routePartName);
                 if ($routePartDefaultValue !== NULL) {
                     $routePart->setDefaultValue($routePartDefaultValue);
                 }
                 break;
             case self::ROUTEPART_TYPE_STATIC:
                 $routePart = new \TYPO3\FLOW3\Mvc\Routing\StaticRoutePart();
                 if ($lastRoutePart !== NULL && $lastRoutePart instanceof \TYPO3\FLOW3\Mvc\Routing\DynamicRoutePartInterface) {
                     $lastRoutePart->setSplitString($routePartName);
                 }
         }
         $routePart->setName($routePartName);
         $routePart->setOptional($currentRoutePartIsOptional);
         $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 \TYPO3\FLOW3\Mvc\Exception\InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains an unopened optional section.', 1234564495);
             }
             $currentRoutePartIsOptional = FALSE;
         }
         $lastRoutePart = $routePart;
     }
     if ($currentRoutePartIsOptional) {
         throw new \TYPO3\FLOW3\Mvc\Exception\InvalidUriPatternException('The URI pattern "' . $this->uriPattern . '" of route "' . $this->getName() . '" contains an unterminated optional section.', 1234563922);
     }
     $this->isParsed = TRUE;
 }
Exemple #8
0
 /**
  * Returns the route value of the current route part.
  * This method can be overridden by custom RoutePartHandlers to implement custom resolving mechanisms.
  *
  * @param array $routeValues An array with key/value pairs to be resolved by Dynamic Route Parts.
  * @return string|array value to resolve.
  * @api
  */
 protected function findValueToResolve(array $routeValues)
 {
     return \TYPO3\FLOW3\Reflection\ObjectAccess::getPropertyPath($routeValues, $this->name);
 }