/** * @test */ public function setValueByLeavesInputArrayUnchanged() { $subject = $subjectBackup = array('foo' => 'bar'); \TYPO3\FLOW3\Utility\Arrays::setValueByPath($subject, 'foo', 'baz'); $this->assertEquals($subject, $subjectBackup); }
/** * Checks whether $routePath corresponds to this Route. * If all Route Parts match successfully TRUE is returned and * $this->matchResults contains an array combining Route default values and * calculated matchResults from the individual Route Parts. * * @param string $routePath the route path without protocol, host and query string * @return boolean TRUE if this Route corresponds to the given $routePath, otherwise FALSE * @throws \TYPO3\FLOW3\Mvc\Exception\InvalidRoutePartValueException * @see getMatchResults() */ public function matches($routePath) { $this->matchResults = NULL; if ($routePath === NULL) { return FALSE; } if ($this->uriPattern === NULL) { return FALSE; } if (!$this->isParsed) { $this->parse(); } $matchResults = array(); $routePath = trim($routePath, '/'); $skipOptionalParts = FALSE; $optionalPartCount = 0; foreach ($this->routeParts as $routePart) { if ($routePart->isOptional()) { $optionalPartCount++; if ($skipOptionalParts) { if ($routePart->getDefaultValue() === NULL) { return FALSE; } continue; } } else { $optionalPartCount = 0; $skipOptionalParts = FALSE; } if ($routePart->match($routePath) !== TRUE) { if ($routePart->isOptional() && $optionalPartCount === 1) { if ($routePart->getDefaultValue() === NULL) { return FALSE; } $skipOptionalParts = TRUE; } else { return FALSE; } } $routePartValue = $routePart->getValue(); if ($routePartValue !== NULL) { if ($this->containsObject($routePartValue)) { throw new \TYPO3\FLOW3\Mvc\Exception\InvalidRoutePartValueException('RoutePart::getValue() must only return simple types after calling RoutePart::match(). RoutePart "' . get_class($routePart) . '" returned one or more objects in Route "' . $this->getName() . '".'); } $matchResults = \TYPO3\FLOW3\Utility\Arrays::setValueByPath($matchResults, $routePart->getName(), $routePartValue); } } if (strlen($routePath) > 0) { return FALSE; } $this->matchResults = \TYPO3\FLOW3\Utility\Arrays::arrayMergeRecursiveOverrule($this->defaults, $matchResults); return TRUE; }
/** * Transforms the convoluted _FILES superglobal into a manageable form. * * @param array $convolutedFiles The _FILES superglobal * @return array Untangled files */ protected function untangleFilesArray(array $convolutedFiles) { $untangledFiles = array(); $fieldPaths = array(); foreach ($convolutedFiles as $firstLevelFieldName => $fieldInformation) { if (!is_array($fieldInformation['error'])) { $fieldPaths[] = array($firstLevelFieldName); } else { $newFieldPaths = $this->calculateFieldPaths($fieldInformation['error'], $firstLevelFieldName); array_walk($newFieldPaths, function (&$value, $key) { $value = explode('/', $value); }); $fieldPaths = array_merge($fieldPaths, $newFieldPaths); } } foreach ($fieldPaths as $fieldPath) { if (count($fieldPath) === 1) { $fileInformation = $convolutedFiles[$fieldPath[0]]; } else { $fileInformation = array(); foreach ($convolutedFiles[$fieldPath[0]] as $key => $subStructure) { $fileInformation[$key] = Arrays::getValueByPath($subStructure, array_slice($fieldPath, 1)); } } if (isset($fileInformation['error']) && $fileInformation['error'] !== \UPLOAD_ERR_NO_FILE) { $untangledFiles = Arrays::setValueByPath($untangledFiles, $fieldPath, $fileInformation); } } return $untangledFiles; }
/** * Loads special configuration defined in the specified packages and merges them with * those potentially existing in the global configuration folders. The result is stored * in the configuration manager's configuration registry and can be retrieved with the * getConfiguration() method. * * @param string $configurationType The kind of configuration to load - must be one of the CONFIGURATION_TYPE_* constants * @param array $packages An array of Package objects (indexed by package key) to consider * @return void * @throws \TYPO3\FLOW3\Configuration\Exception\InvalidConfigurationTypeException */ protected function loadConfiguration($configurationType, array $packages) { $this->cacheNeedsUpdate = TRUE; switch ($configurationType) { case self::CONFIGURATION_TYPE_SETTINGS: // Make sure that the FLOW3 package is the first item of the packages array: if (isset($packages['TYPO3.FLOW3'])) { $flow3Package = $packages['TYPO3.FLOW3']; unset($packages['TYPO3.FLOW3']); $packages = array_merge(array('TYPO3.FLOW3' => $flow3Package), $packages); unset($flow3Package); } $settings = array(); foreach ($packages as $packageKey => $package) { if (Arrays::getValueByPath($settings, $packageKey) === NULL) { $settings = Arrays::setValueByPath($settings, $packageKey, array()); } $settings = Arrays::arrayMergeRecursiveOverrule($settings, $this->configurationSource->load($package->getConfigurationPath() . self::CONFIGURATION_TYPE_SETTINGS)); } $settings = Arrays::arrayMergeRecursiveOverrule($settings, $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . self::CONFIGURATION_TYPE_SETTINGS)); foreach ($this->orderedListOfContextNames as $contextName) { foreach ($packages as $package) { $settings = Arrays::arrayMergeRecursiveOverrule($settings, $this->configurationSource->load($package->getConfigurationPath() . $contextName . '/' . self::CONFIGURATION_TYPE_SETTINGS)); } $settings = Arrays::arrayMergeRecursiveOverrule($settings, $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $contextName . '/' . self::CONFIGURATION_TYPE_SETTINGS)); } if ($this->configurations[self::CONFIGURATION_TYPE_SETTINGS] !== array()) { $this->configurations[self::CONFIGURATION_TYPE_SETTINGS] = Arrays::arrayMergeRecursiveOverrule($this->configurations[self::CONFIGURATION_TYPE_SETTINGS], $settings); } else { $this->configurations[self::CONFIGURATION_TYPE_SETTINGS] = $settings; } $this->configurations[self::CONFIGURATION_TYPE_SETTINGS]['TYPO3']['FLOW3']['core']['context'] = (string) $this->context; break; case self::CONFIGURATION_TYPE_OBJECTS: $this->configurations[$configurationType] = array(); foreach ($packages as $packageKey => $package) { $configuration = $this->configurationSource->load($package->getConfigurationPath() . $configurationType); $configuration = Arrays::arrayMergeRecursiveOverrule($configuration, $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $configurationType)); foreach ($this->orderedListOfContextNames as $contextName) { $configuration = Arrays::arrayMergeRecursiveOverrule($configuration, $this->configurationSource->load($package->getConfigurationPath() . $contextName . '/' . $configurationType)); $configuration = Arrays::arrayMergeRecursiveOverrule($configuration, $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $contextName . '/' . $configurationType)); } $this->configurations[$configurationType][$packageKey] = $configuration; } break; case self::CONFIGURATION_TYPE_CACHES: case self::CONFIGURATION_TYPE_POLICY: $this->configurations[$configurationType] = array(); foreach ($packages as $package) { $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $this->configurationSource->load($package->getConfigurationPath() . $configurationType)); } $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $configurationType)); foreach ($this->orderedListOfContextNames as $contextName) { foreach ($packages as $package) { $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $this->configurationSource->load($package->getConfigurationPath() . $contextName . '/' . $configurationType)); } $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $contextName . '/' . $configurationType)); } break; case self::CONFIGURATION_TYPE_ROUTES: // load subroutes $subRoutesConfiguration = array(); foreach ($packages as $packageKey => $package) { $subRoutesConfiguration[$packageKey] = array(); foreach (array_reverse($this->orderedListOfContextNames) as $contextName) { $subRoutesConfiguration[$packageKey] = array_merge($subRoutesConfiguration[$packageKey], $this->configurationSource->load($package->getConfigurationPath() . $contextName . '/' . $configurationType)); } $subRoutesConfiguration[$packageKey] = array_merge($subRoutesConfiguration[$packageKey], $this->configurationSource->load($package->getConfigurationPath() . $configurationType)); } // load main routes $this->configurations[self::CONFIGURATION_TYPE_ROUTES] = array(); foreach (array_reverse($this->orderedListOfContextNames) as $contextName) { $this->configurations[self::CONFIGURATION_TYPE_ROUTES] = array_merge($this->configurations[self::CONFIGURATION_TYPE_ROUTES], $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $contextName . '/' . $configurationType)); } $this->configurations[self::CONFIGURATION_TYPE_ROUTES] = array_merge($this->configurations[self::CONFIGURATION_TYPE_ROUTES], $this->configurationSource->load(FLOW3_PATH_CONFIGURATION . $configurationType)); // Merge routes with subroutes $this->mergeRoutesWithSubRoutes($this->configurations[$configurationType], $subRoutesConfiguration); break; default: throw new \TYPO3\FLOW3\Configuration\Exception\InvalidConfigurationTypeException('Configuration type "' . $configurationType . '" cannot be loaded with loadConfiguration().', 1251450613); } $this->postProcessConfiguration($this->configurations[$configurationType]); }