/**
  * Iterate through the configured modules, find the matching module and set
  * the route path accordingly
  *
  * @param array $value (contains action, controller and package of the module controller)
  * @return boolean
  */
 protected function resolveValue($value)
 {
     if (is_array($value)) {
         $this->value = isset($value['@action']) && $value['@action'] !== 'index' ? $value['@action'] : '';
         $exceedingArguments = array();
         foreach ($value as $argumentKey => $argumentValue) {
             if (substr($argumentKey, 0, 1) !== '@' && substr($argumentKey, 0, 2) !== '__') {
                 $exceedingArguments[$argumentKey] = $argumentValue;
             }
         }
         if ($exceedingArguments !== array()) {
             $exceedingArguments = \TYPO3\FLOW3\Utility\Arrays::removeEmptyElementsRecursively($exceedingArguments);
             $exceedingArguments = $this->persistenceManager->convertObjectsToIdentityArrays($exceedingArguments);
             $queryString = http_build_query(array($this->name => $exceedingArguments), NULL, '&');
             if ($queryString !== '') {
                 $this->value .= '?' . $queryString;
             }
         }
     }
     return TRUE;
 }
Example #2
0
 /**
  * @test
  */
 public function removeEmptyElementsRecursivelyRemovesEmptySubArrays()
 {
     $array = array('EmptyElement' => array(), 'Foo' => array('Bar' => array('Baz' => array('AnotherEmptyElement' => NULL))), 'NotNull' => 123);
     $expectedResult = array('NotNull' => 123);
     $actualResult = \TYPO3\FLOW3\Utility\Arrays::removeEmptyElementsRecursively($array);
     $this->assertEquals($expectedResult, $actualResult);
 }
Example #3
0
 /**
  * Checks whether $routeValues can be resolved to a corresponding uri.
  * If all Route Parts can resolve one or more of the $routeValues, TRUE is
  * returned and $this->matchingURI contains the generated URI (excluding
  * protocol and host).
  *
  * @param array $routeValues An array containing key/value pairs to be resolved to uri segments
  * @return boolean TRUE if this Route corresponds to the given $routeValues, otherwise FALSE
  * @throws \TYPO3\FLOW3\Mvc\Exception\InvalidRoutePartValueException
  * @see getMatchingUri()
  */
 public function resolves(array $routeValues)
 {
     $this->matchingUri = NULL;
     if ($this->uriPattern === NULL) {
         return FALSE;
     }
     if (!$this->isParsed) {
         $this->parse();
     }
     $matchingUri = '';
     $mergedRouteValues = \TYPO3\FLOW3\Utility\Arrays::arrayMergeRecursiveOverrule($this->defaults, $routeValues);
     $requireOptionalRouteParts = FALSE;
     $matchingOptionalUriPortion = '';
     foreach ($this->routeParts as $routePart) {
         if (!$routePart->resolve($routeValues)) {
             if (!$routePart->hasDefaultValue()) {
                 return FALSE;
             }
         }
         $routePartValue = NULL;
         if ($routePart->hasValue()) {
             $routePartValue = $routePart->getValue();
             if (!is_string($routePartValue)) {
                 throw new \TYPO3\FLOW3\Mvc\Exception\InvalidRoutePartValueException('RoutePart::getValue() must return a string after calling RoutePart::resolve(), got ' . (is_object($routePartValue) ? get_class($routePartValue) : gettype($routePartValue)) . ' for RoutePart "' . get_class($routePart) . '" in Route "' . $this->getName() . '".');
             }
         }
         $routePartDefaultValue = $routePart->getDefaultValue();
         if ($routePartDefaultValue !== NULL && !is_string($routePartDefaultValue)) {
             throw new \TYPO3\FLOW3\Mvc\Exception\InvalidRoutePartValueException('RoutePart::getDefaultValue() must return a string, got ' . (is_object($routePartDefaultValue) ? get_class($routePartDefaultValue) : gettype($routePartDefaultValue)) . ' for RoutePart "' . get_class($routePart) . '" in Route "' . $this->getName() . '".');
         }
         if (!$routePart->isOptional()) {
             $matchingUri .= $routePart->hasValue() ? $routePartValue : $routePartDefaultValue;
             $requireOptionalRouteParts = FALSE;
             continue;
         }
         if ($routePart->hasValue() && $routePartValue !== $routePartDefaultValue) {
             $matchingOptionalUriPortion .= $routePartValue;
             $requireOptionalRouteParts = TRUE;
         } else {
             $matchingOptionalUriPortion .= $routePartDefaultValue;
         }
         if ($requireOptionalRouteParts) {
             $matchingUri .= $matchingOptionalUriPortion;
             $matchingOptionalUriPortion = '';
         }
     }
     if ($this->compareAndRemoveMatchingDefaultValues($this->defaults, $routeValues) !== TRUE) {
         return FALSE;
     }
     if (isset($routeValues['@format']) && $routeValues['@format'] === '') {
         unset($routeValues['@format']);
     }
     $this->throwExceptionIfTargetControllerDoesNotExist($mergedRouteValues);
     // add query string
     if (count($routeValues) > 0) {
         $routeValues = \TYPO3\FLOW3\Utility\Arrays::removeEmptyElementsRecursively($routeValues);
         $routeValues = $this->persistenceManager->convertObjectsToIdentityArrays($routeValues);
         if (!$this->appendExceedingArguments) {
             $internalArguments = $this->extractInternalArguments($routeValues);
             if ($routeValues !== array()) {
                 return FALSE;
             }
             $routeValues = $internalArguments;
         }
         $queryString = http_build_query($routeValues, NULL, '&');
         if ($queryString !== '') {
             $matchingUri .= strpos($matchingUri, '?') !== FALSE ? '&' . $queryString : '?' . $queryString;
         }
     }
     $this->matchingUri = $matchingUri;
     return TRUE;
 }