/** * * @param string $type * @param boolean $showHiddenProperties if TRUE, the hidden properties are shown as configured in settings "supertypeResolver.hiddenProperties" are shown as well. FALSE by default * @return array * @throws \Neos\Form\Exception\TypeDefinitionNotFoundException if a type definition was not found * @internal */ public function getMergedTypeDefinition($type, $showHiddenProperties = false) { if (!isset($this->configuration[$type])) { throw new \Neos\Form\Exception\TypeDefinitionNotFoundException(sprintf('Type "%s" not found. Probably some configuration is missing.', $type), 1325686909); } $mergedTypeDefinition = array(); if (isset($this->configuration[$type]['superTypes'])) { foreach ($this->configuration[$type]['superTypes'] as $superTypeName => $enabled) { // Skip unset node types if ($enabled === false || $enabled === null) { continue; } // Make this setting backwards compatible with old array schema (deprecated since 2.0) if (!is_bool($enabled)) { $superTypeName = $enabled; } $mergedTypeDefinition = \Neos\Utility\Arrays::arrayMergeRecursiveOverrule($mergedTypeDefinition, $this->getMergedTypeDefinition($superTypeName, $showHiddenProperties)); } } $mergedTypeDefinition = \Neos\Utility\Arrays::arrayMergeRecursiveOverrule($mergedTypeDefinition, $this->configuration[$type]); unset($mergedTypeDefinition['superTypes']); if ($showHiddenProperties === false && isset($this->settings['supertypeResolver']['hiddenProperties']) && is_array($this->settings['supertypeResolver']['hiddenProperties'])) { foreach ($this->settings['supertypeResolver']['hiddenProperties'] as $propertyName) { unset($mergedTypeDefinition[$propertyName]); } } return $mergedTypeDefinition; }
/** * @return void */ protected function initializeAction() { $this->objects = $this->widgetConfiguration['objects']; $this->configuration = Arrays::arrayMergeRecursiveOverrule($this->configuration, $this->widgetConfiguration['configuration'], true); $this->numberOfPages = (int) ceil(count($this->objects) / (int) $this->configuration['itemsPerPage']); $this->maximumNumberOfLinks = (int) $this->configuration['maximumNumberOfLinks']; }
/** * @param Request $httpRequest * @param array $matchResults * @return ActionRequest */ protected function createActionRequest(Request $httpRequest, array $matchResults = null) { $actionRequest = new ActionRequest($httpRequest); if ($matchResults !== null) { $requestArguments = $actionRequest->getArguments(); $mergedArguments = Arrays::arrayMergeRecursiveOverrule($requestArguments, $matchResults); $actionRequest->setArguments($mergedArguments); } return $actionRequest; }
/** * @param string $persistenceIdentifier the persistence identifier for the form. * @param string $factoryClass The fully qualified class name of the factory (which has to implement \Neos\Form\Factory\FormFactoryInterface) * @param string $presetName name of the preset to use * @param array $overrideConfiguration factory specific configuration * @return string the rendered form */ public function render($persistenceIdentifier = null, $factoryClass = \Neos\Form\Factory\ArrayFormFactory::class, $presetName = 'default', array $overrideConfiguration = null) { if (isset($persistenceIdentifier)) { $overrideConfiguration = Arrays::arrayMergeRecursiveOverrule($this->formPersistenceManager->load($persistenceIdentifier), $overrideConfiguration ?: []); } $factory = $this->objectManager->get($factoryClass); $formDefinition = $factory->build($overrideConfiguration, $presetName); $response = new Response($this->controllerContext->getResponse()); $form = $formDefinition->bind($this->controllerContext->getRequest(), $response); return $form->render(); }
/** * @test */ public function ignoredClassesCanBeOverwrittenBySettings() { $object = new ApplicationContext('Development'); $this->assertEquals(sprintf('%s prototype object', ApplicationContext::class), Debugger::renderDump($object, 10, true)); Debugger::clearState(); $currentConfiguration = ObjectAccess::getProperty($this->configurationManager, 'configurations', true); $configurationOverwrite['Settings']['Neos']['Flow']['error']['debugger']['ignoredClasses']['Neos\\\\Flow\\\\Core\\\\.*'] = false; $newConfiguration = Arrays::arrayMergeRecursiveOverrule($currentConfiguration, $configurationOverwrite); ObjectAccess::setProperty($this->configurationManager, 'configurations', $newConfiguration, true); $this->assertContains('rootContextString', Debugger::renderDump($object, 10, true)); }
/** * Merges the given context properties with sane defaults for the context implementation. * * @param array $contextProperties * @return array */ protected function mergeContextPropertiesWithDefaults(array $contextProperties) { $contextProperties = $this->removeDeprecatedProperties($contextProperties); $defaultContextProperties = array('workspaceName' => 'live', 'currentDateTime' => $this->now, 'dimensions' => array(), 'targetDimensions' => array(), 'invisibleContentShown' => false, 'removedContentShown' => false, 'inaccessibleContentShown' => false, 'currentSite' => null, 'currentDomain' => null); if (!isset($contextProperties['currentSite'])) { $defaultContextProperties = $this->setDefaultSiteAndDomainFromCurrentRequest($defaultContextProperties); } $mergedProperties = Arrays::arrayMergeRecursiveOverrule($defaultContextProperties, $contextProperties, true); $this->mergeDimensionValues($contextProperties, $mergedProperties); $this->mergeTargetDimensionContextProperties($contextProperties, $mergedProperties, $defaultContextProperties); return $mergedProperties; }
/** * @return void */ protected function initializeAction() { $this->parentNode = $this->widgetConfiguration['parentNode']; $this->nodes = $this->widgetConfiguration['nodes']; $this->nodeTypeFilter = $this->widgetConfiguration['nodeTypeFilter'] ?: null; $this->configuration = Arrays::arrayMergeRecursiveOverrule($this->configuration, $this->widgetConfiguration['configuration'], true); $this->maximumNumberOfNodes = $this->configuration['maximumNumberOfNodes']; $numberOfNodes = $this->parentNode === null ? count($this->nodes) : $this->parentNode->getNumberOfChildNodes($this->nodeTypeFilter); if ($this->maximumNumberOfNodes > 0 && $numberOfNodes > $this->maximumNumberOfNodes) { $numberOfNodes = $this->maximumNumberOfNodes; } $this->numberOfPages = ceil($numberOfNodes / (int) $this->configuration['itemsPerPage']); $this->maximumNumberOfLinks = (int) $this->configuration['maximumNumberOfLinks']; }
/** * Checks if the given $nodeType is allowed as a childNode of the given $childNodeName * (which must be auto-created in $this NodeType). * * Only allowed to be called if $childNodeName is auto-created. * * @param string $childNodeName The name of a configured childNode of this NodeType * @param NodeType $nodeType The NodeType to check constraints for. * @return boolean TRUE if the $nodeType is allowed as grandchild node, FALSE otherwise. * @throws \InvalidArgumentException If the given $childNodeName is not configured to be auto-created in $this. */ public function allowsGrandchildNodeType($childNodeName, NodeType $nodeType) { $autoCreatedChildNodes = $this->getAutoCreatedChildNodes(); if (!isset($autoCreatedChildNodes[$childNodeName])) { throw new \InvalidArgumentException('The method "allowsGrandchildNodeType" can only be used on auto-created childNodes, given $childNodeName "' . $childNodeName . '" is not auto-created.', 1403858395); } $constraints = $autoCreatedChildNodes[$childNodeName]->getConfiguration('constraints.nodeTypes') ?: array(); $childNodeConfiguration = []; foreach ($this->getConfiguration('childNodes') as $name => $configuration) { $childNodeConfiguration[Utility::renderValidNodeName($name)] = $configuration; } $childNodeConstraintConfiguration = ObjectAccess::getPropertyPath($childNodeConfiguration, $childNodeName . '.constraints.nodeTypes') ?: array(); $constraints = Arrays::arrayMergeRecursiveOverrule($constraints, $childNodeConstraintConfiguration); return $this->isNodeTypeAllowedByConstraints($nodeType, $constraints); }
/** * Checks if custom rendering rules apply to the given $exception and returns those. * * @param object $exception \Exception or \Throwable * @return array the custom rendering options, or NULL if no custom rendering is defined for this exception */ protected function resolveCustomRenderingOptions($exception) { $renderingOptions = []; if (isset($this->options['defaultRenderingOptions'])) { $renderingOptions = $this->options['defaultRenderingOptions']; } $renderingGroup = $this->resolveRenderingGroup($exception); if ($renderingGroup !== null) { $renderingOptions = Arrays::arrayMergeRecursiveOverrule($renderingOptions, $this->options['renderingGroups'][$renderingGroup]['options']); $renderingOptions['renderingGroup'] = $renderingGroup; } return $renderingOptions; }
/** * 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 Request $httpRequest the HTTP request to match * @return boolean TRUE if this Route corresponds to the given $routePath, otherwise FALSE * @throws InvalidRoutePartValueException * @see getMatchResults() */ public function matches(Request $httpRequest) { $routePath = $httpRequest->getRelativePath(); $this->matchResults = null; if ($this->uriPattern === null) { return false; } if (!$this->isParsed) { $this->parse(); } if ($this->hasHttpMethodConstraints() && !in_array($httpRequest->getMethod(), $this->httpMethods)) { return false; } $matchResults = []; $routePath = trim($routePath, '/'); $skipOptionalParts = false; $optionalPartCount = 0; /** @var $routePart RoutePartInterface */ 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 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 = Arrays::setValueByPath($matchResults, $routePart->getName(), $routePartValue); } } if (strlen($routePath) > 0) { return false; } $this->matchResults = Arrays::arrayMergeRecursiveOverrule($this->defaults, $matchResults); return true; }
/** * Takes the raw GET & POST arguments and maps them into the request object. * Afterwards all mapped arguments can be retrieved by the getArgument(s) method, no matter if they * have been GET, POST or PUT arguments before. * * @param array $getArguments Arguments as found in $_GET * @param array $postArguments Arguments as found in $_POST * @param array $uploadArguments Arguments as found in $_FILES * @return array the unified arguments */ protected function buildUnifiedArguments(array $getArguments, array $postArguments, array $uploadArguments) { $arguments = $getArguments; $arguments = Arrays::arrayMergeRecursiveOverrule($arguments, $postArguments); $arguments = Arrays::arrayMergeRecursiveOverrule($arguments, $this->untangleFilesArray($uploadArguments)); return $arguments; }
/** * @param string $finisherIdentifier identifier of the finisher as registered in the current form preset (for example: "Neos.Form:Redirect") * @param array $options options for this finisher in the format array('option1' => 'value1', 'option2' => 'value2', ...) * @return FinisherInterface * @throws \Neos\Form\Exception\FinisherPresetNotFoundException * @api */ public function createFinisher($finisherIdentifier, array $options = array()) { if (isset($this->finisherPresets[$finisherIdentifier]) && is_array($this->finisherPresets[$finisherIdentifier]) && isset($this->finisherPresets[$finisherIdentifier]['implementationClassName'])) { $implementationClassName = $this->finisherPresets[$finisherIdentifier]['implementationClassName']; $defaultOptions = isset($this->finisherPresets[$finisherIdentifier]['options']) ? $this->finisherPresets[$finisherIdentifier]['options'] : array(); $options = \Neos\Utility\Arrays::arrayMergeRecursiveOverrule($defaultOptions, $options); $finisher = new $implementationClassName(); $finisher->setOptions($options); $this->addFinisher($finisher); return $finisher; } else { throw new \Neos\Form\Exception\FinisherPresetNotFoundException('The finisher preset identified by "' . $finisherIdentifier . '" could not be found, or the implementationClassName was not specified.', 1328709784); } }
/** * @return void */ protected function initializeAction() { $this->configuration = Arrays::arrayMergeRecursiveOverrule($this->configuration, $this->widgetConfiguration['configuration'], true); }
/** * Returns the preset with the given $presetName. * * The preset is merged with the values of the 'default' preset before being returned. * * @param string $presetName * @return array * @throws UnknownPresetException */ protected function getPreset($presetName) { if (!isset($this->presets[$presetName])) { throw new UnknownPresetException(sprintf('Preset %s is not configured.', $presetName), 1434730924); } $default = $this->presets['default']; $preset = $this->presets[$presetName]; return Arrays::arrayMergeRecursiveOverrule($default, $preset, TRUE); }
/** * Returns the settings for the requested queue, merged with the preset defaults if any * * @param string $queueName * @return array * @throws JobQueueException if no queue for the given $queueName is configured * @api */ public function getQueueSettings($queueName) { if (isset($this->queueSettingsRuntimeCache[$queueName])) { return $this->queueSettingsRuntimeCache[$queueName]; } if (!isset($this->settings['queues'][$queueName])) { throw new JobQueueException(sprintf('Queue "%s" is not configured', $queueName), 1334054137); } $queueSettings = $this->settings['queues'][$queueName]; if (isset($queueSettings['preset'])) { $presetName = $queueSettings['preset']; if (!isset($this->settings['presets'][$presetName])) { throw new JobQueueException(sprintf('Preset "%s", referred to in settings for queue "%s" is not configured', $presetName, $queueName), 1466677893); } $queueSettings = Arrays::arrayMergeRecursiveOverrule($this->settings['presets'][$presetName], $queueSettings); } $this->queueSettingsRuntimeCache[$queueName] = $queueSettings; return $this->queueSettingsRuntimeCache[$queueName]; }
/** * Tries to load the 'Neos.Flow.error.debugger.ignoredClasses' setting * to build a regular expression that can be used to filter ignored class names * If settings can't be loaded it uses self::$ignoredClassesFallback. * * @return string */ public static function getIgnoredClassesRegex() { if (self::$ignoredClassesRegex !== '') { return self::$ignoredClassesRegex; } $ignoredClassesConfiguration = self::$ignoredClassesFallback; $ignoredClasses = []; if (self::$objectManager instanceof ObjectManagerInterface) { $configurationManager = self::$objectManager->get(ConfigurationManager::class); if ($configurationManager instanceof ConfigurationManager) { $ignoredClassesFromSettings = $configurationManager->getConfiguration('Settings', 'Neos.Flow.error.debugger.ignoredClasses'); if (is_array($ignoredClassesFromSettings)) { $ignoredClassesConfiguration = Arrays::arrayMergeRecursiveOverrule($ignoredClassesConfiguration, $ignoredClassesFromSettings); } } } foreach ($ignoredClassesConfiguration as $classNamePattern => $active) { if ($active === true) { $ignoredClasses[] = $classNamePattern; } } self::$ignoredClassesRegex = sprintf('/^%s$/xs', implode('$|^', $ignoredClasses)); return self::$ignoredClassesRegex; }
/** * Return the json array for a given locale, sourceCatalog, xliffPath and package. * The json will be cached. * * @param Locale $locale The locale * @return Result * @throws Exception */ public function getCachedJson(Locale $locale) { $cacheIdentifier = md5($locale); if ($this->xliffToJsonTranslationsCache->has($cacheIdentifier)) { $json = $this->xliffToJsonTranslationsCache->get($cacheIdentifier); } else { $labels = []; $localeChain = $this->localizationService->getLocaleChain($locale); foreach ($this->packagesRegisteredForAutoInclusion as $packageKey => $sourcesToBeIncluded) { if (!is_array($sourcesToBeIncluded)) { continue; } $translationBasePath = Files::concatenatePaths([$this->packageManager->getPackage($packageKey)->getResourcesPath(), $this->xliffBasePath]); // We merge labels in the chain from the worst choice to best choice foreach (array_reverse($localeChain) as $allowedLocale) { $localeSourcePath = Files::getNormalizedPath(Files::concatenatePaths([$translationBasePath, $allowedLocale])); foreach ($sourcesToBeIncluded as $sourceName) { foreach (glob($localeSourcePath . $sourceName . '.xlf') as $xliffPathAndFilename) { $xliffPathInfo = pathinfo($xliffPathAndFilename); $sourceName = str_replace($localeSourcePath, '', $xliffPathInfo['dirname'] . '/' . $xliffPathInfo['filename']); $labels = Arrays::arrayMergeRecursiveOverrule($labels, $this->parseXliffToArray($xliffPathAndFilename, $packageKey, $sourceName)); } } } } $json = json_encode($labels); $this->xliffToJsonTranslationsCache->set($cacheIdentifier, $json); } return $json; }
/** * @Given /^I have the following (additional |)NodeTypes configuration:$/ */ public function iHaveTheFollowingNodetypesConfiguration($additional, $nodeTypesConfiguration) { if ($this->isolated === true) { $this->callStepInSubProcess(__METHOD__, sprintf(' %s %s %s %s', 'string', escapeshellarg($additional), 'integer', escapeshellarg($nodeTypesConfiguration))); } else { if (strlen($additional) > 0) { $configuration = Arrays::arrayMergeRecursiveOverrule($this->nodeTypesConfiguration, Yaml::parse($nodeTypesConfiguration->getRaw())); } else { $this->nodeTypesConfiguration = Yaml::parse($nodeTypesConfiguration->getRaw()); $configuration = $this->nodeTypesConfiguration; } $this->getObjectManager()->get(\Neos\ContentRepository\Domain\Service\NodeTypeManager::class)->overrideNodeTypes($configuration); } }
/** * Merges two policy configuration arrays. * * @param array $firstConfigurationArray * @param array $secondConfigurationArray * @return array */ protected function mergePolicyConfiguration(array $firstConfigurationArray, array $secondConfigurationArray) { $result = Arrays::arrayMergeRecursiveOverrule($firstConfigurationArray, $secondConfigurationArray); if (!isset($result['roles'])) { return $result; } foreach ($result['roles'] as $roleIdentifier => $roleConfiguration) { if (!isset($firstConfigurationArray['roles'][$roleIdentifier]['privileges']) || !isset($secondConfigurationArray['roles'][$roleIdentifier]['privileges'])) { continue; } $result['roles'][$roleIdentifier]['privileges'] = array_merge($firstConfigurationArray['roles'][$roleIdentifier]['privileges'], $secondConfigurationArray['roles'][$roleIdentifier]['privileges']); } return $result; }
/** * Returns an ActionRequest which referred to this request, if any. * * The referring request is not set or determined automatically but must be * explicitly set through the corresponding internal argument "__referrer". * This mechanism is used by Flow's form and validation mechanisms. * * @return ActionRequest the referring request, or NULL if no referrer found */ public function getReferringRequest() { if ($this->referringRequest !== null) { return $this->referringRequest; } if (!isset($this->internalArguments['__referrer'])) { return null; } if (is_array($this->internalArguments['__referrer'])) { $referrerArray = $this->internalArguments['__referrer']; $referringRequest = new ActionRequest($this->getHttpRequest()); $arguments = []; if (isset($referrerArray['arguments'])) { $serializedArgumentsWithHmac = $referrerArray['arguments']; $serializedArguments = $this->hashService->validateAndStripHmac($serializedArgumentsWithHmac); $arguments = unserialize(base64_decode($serializedArguments)); unset($referrerArray['arguments']); } $referringRequest->setArguments(Arrays::arrayMergeRecursiveOverrule($arguments, $referrerArray)); return $referringRequest; } else { $this->referringRequest = $this->internalArguments['__referrer']; } return $this->referringRequest; }
/** * Get the preset configuration by $presetName, taking the preset hierarchy * (specified by *parentPreset*) into account. * * @param string $presetName name of the preset to get the configuration for * @return array the preset configuration * @throws \Neos\Form\Exception\PresetNotFoundException if preset with the name $presetName was not found * @api */ public function getPresetConfiguration($presetName) { if (!isset($this->formSettings['presets'][$presetName])) { throw new \Neos\Form\Exception\PresetNotFoundException(sprintf('The Preset "%s" was not found underneath TYPO3: Form: presets.', $presetName), 1332170104); } $preset = $this->formSettings['presets'][$presetName]; if (isset($preset['parentPreset'])) { $parentPreset = $this->getPresetConfiguration($preset['parentPreset']); unset($preset['parentPreset']); $preset = \Neos\Utility\Arrays::arrayMergeRecursiveOverrule($parentPreset, $preset); } return $preset; }
/** * Move a settings path from "source" to "destination"; best to be used when package names change. * * @param string $sourcePath * @param string $destinationPath */ protected function moveSettingsPaths($sourcePath, $destinationPath) { $this->processConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, function (array &$configuration) use($sourcePath, $destinationPath) { $sourceConfigurationValue = Arrays::getValueByPath($configuration, $sourcePath); $destinationConfigurationValue = Arrays::getValueByPath($configuration, $destinationPath); if ($sourceConfigurationValue !== null) { // source exists, so we need to move source to destination. if ($destinationConfigurationValue !== null) { // target exists as well; we need to MERGE source and target. $destinationConfigurationValue = Arrays::arrayMergeRecursiveOverrule($sourceConfigurationValue, $destinationConfigurationValue); } else { // target does NOT exist; we directly set target = source $destinationConfigurationValue = $sourceConfigurationValue; } // set the config on the new path $configuration = Arrays::setValueByPath($configuration, $destinationPath, $destinationConfigurationValue); // Unset the old configuration $configuration = Arrays::unsetValueByPath($configuration, $sourcePath); // remove empty keys before our removed key (if it exists) $sourcePathExploded = explode('.', $sourcePath); for ($length = count($sourcePathExploded) - 1; $length > 0; $length--) { $temporaryPath = array_slice($sourcePathExploded, 0, $length); $valueAtPath = Arrays::getValueByPath($configuration, $temporaryPath); if (empty($valueAtPath)) { $configuration = Arrays::unsetValueByPath($configuration, $temporaryPath); } else { break; } } } }, true); }
/** * Set the "context node" this operation was working on. * * @param NodeInterface $node * @return void */ public function setNode(NodeInterface $node) { $this->nodeIdentifier = $node->getIdentifier(); $this->workspaceName = $node->getContext()->getWorkspaceName(); $this->dimension = $node->getContext()->getDimensions(); $context = $node->getContext(); if ($context instanceof ContentContext && $context->getCurrentSite() !== null) { $siteIdentifier = $this->persistenceManager->getIdentifierByObject($context->getCurrentSite()); } else { $siteIdentifier = null; } $this->data = Arrays::arrayMergeRecursiveOverrule($this->data, array('nodeContextPath' => $node->getContextPath(), 'nodeLabel' => $node->getLabel(), 'nodeType' => $node->getNodeType()->getName(), 'site' => $siteIdentifier)); $node = self::getClosestAggregateNode($node); if ($node !== null) { $this->documentNodeIdentifier = $node->getIdentifier(); $this->data = Arrays::arrayMergeRecursiveOverrule($this->data, array('documentNodeContextPath' => $node->getContextPath(), 'documentNodeLabel' => $node->getLabel(), 'documentNodeType' => $node->getNodeType()->getName())); } }
/** * Merges specified arguments with arguments from request. * * If $this->request is no sub request, request arguments will only be merged if $this->addQueryString is set. * Otherwise all request arguments except for the ones prefixed with the current request argument namespace will * be merged. Additionally special arguments (PackageKey, SubpackageKey, ControllerName & Action) are merged. * * The argument provided through the $arguments parameter always overrule the request * arguments. * * The request hierarchy is structured as follows: * root (HTTP) > main (Action) > sub (Action) > sub sub (Action) * * @param array $arguments * @return array */ protected function mergeArgumentsWithRequestArguments(array $arguments) { if ($this->request !== $this->request->getMainRequest()) { $subRequest = $this->request; while ($subRequest instanceof ActionRequest) { $requestArguments = (array) $subRequest->getArguments(); // Reset arguments for the request that is bound to this UriBuilder instance if ($subRequest === $this->request) { if ($this->addQueryString === false) { $requestArguments = []; } else { foreach ($this->argumentsToBeExcludedFromQueryString as $argumentToBeExcluded) { unset($requestArguments[$argumentToBeExcluded]); } } } else { // Remove all arguments of the current sub request if it's namespaced if ($this->request->getArgumentNamespace() !== '') { $requestNamespace = $this->getRequestNamespacePath($this->request); if ($this->addQueryString === false) { $requestArguments = Arrays::unsetValueByPath($requestArguments, $requestNamespace); } else { foreach ($this->argumentsToBeExcludedFromQueryString as $argumentToBeExcluded) { $requestArguments = Arrays::unsetValueByPath($requestArguments, $requestNamespace . '.' . $argumentToBeExcluded); } } } } // Merge special arguments (package, subpackage, controller & action) from main request $requestPackageKey = $subRequest->getControllerPackageKey(); if (!empty($requestPackageKey)) { $requestArguments['@package'] = $requestPackageKey; } $requestSubpackageKey = $subRequest->getControllerSubpackageKey(); if (!empty($requestSubpackageKey)) { $requestArguments['@subpackage'] = $requestSubpackageKey; } $requestControllerName = $subRequest->getControllerName(); if (!empty($requestControllerName)) { $requestArguments['@controller'] = $requestControllerName; } $requestActionName = $subRequest->getControllerActionName(); if (!empty($requestActionName)) { $requestArguments['@action'] = $requestActionName; } if (count($requestArguments) > 0) { $requestArguments = $this->addNamespaceToArguments($requestArguments, $subRequest); $arguments = Arrays::arrayMergeRecursiveOverrule($requestArguments, $arguments); } $subRequest = $subRequest->getParentRequest(); } } elseif ($this->addQueryString === true) { $requestArguments = $this->request->getArguments(); foreach ($this->argumentsToBeExcludedFromQueryString as $argumentToBeExcluded) { unset($requestArguments[$argumentToBeExcluded]); } if ($requestArguments !== []) { $arguments = Arrays::arrayMergeRecursiveOverrule($requestArguments, $arguments); } } return $arguments; }
/** * Assigns a value to a node or a property in the object tree, specified by the object path array. * * @param array $objectPathArray The object path, specifying the node / property to set * @param mixed $value The value to assign, is a non-array type or an array with __eelExpression etc. * @param array $objectTree The current (sub-) tree, used internally - don't specify! * @return array The modified object tree */ protected function setValueInObjectTree(array $objectPathArray, $value, &$objectTree = null) { if ($objectTree === null) { $objectTree =& $this->objectTree; } $currentKey = array_shift($objectPathArray); if ((int) $currentKey > 0) { $currentKey = (int) $currentKey; } if (empty($objectPathArray)) { // last part of the iteration, setting the final value if (isset($objectTree[$currentKey]) && $value === null) { unset($objectTree[$currentKey]); } elseif (isset($objectTree[$currentKey]) && is_array($objectTree[$currentKey])) { if (is_array($value)) { $objectTree[$currentKey] = Arrays::arrayMergeRecursiveOverrule($objectTree[$currentKey], $value); } else { $objectTree[$currentKey]['__value'] = $value; $objectTree[$currentKey]['__eelExpression'] = null; $objectTree[$currentKey]['__objectType'] = null; } } else { $objectTree[$currentKey] = $value; } } else { // we still need to traverse further down if (isset($objectTree[$currentKey]) && !is_array($objectTree[$currentKey])) { // the element one-level-down is already defined, but it is NOT an array. So we need to convert the simple type to __value $objectTree[$currentKey] = array('__value' => $objectTree[$currentKey], '__eelExpression' => null, '__objectType' => null); } elseif (!isset($objectTree[$currentKey])) { $objectTree[$currentKey] = array(); } $this->setValueInObjectTree($objectPathArray, $value, $objectTree[$currentKey]); } return $objectTree; }
/** * @param array $additionalOptions * @return array * @throws InvalidConfigurationException */ protected function getOptionsMergedWithDefaults(array $additionalOptions = array()) { $defaultOptions = Arrays::getValueByPath($this->settings, 'image.defaultOptions'); if (!is_array($defaultOptions)) { $defaultOptions = array(); } if ($additionalOptions !== array()) { $defaultOptions = Arrays::arrayMergeRecursiveOverrule($defaultOptions, $additionalOptions); } $quality = isset($defaultOptions['quality']) ? (int) $defaultOptions['quality'] : 90; if ($quality < 0 || $quality > 100) { throw new InvalidConfigurationException(sprintf('Setting "Neos.Media.image.defaultOptions.quality" allow only value between 0 and 100, current value: %s', $quality), 1404982574); } $defaultOptions['jpeg_quality'] = $quality; // png_compression_level should be an integer between 0 and 9 and inverse to the quality level given. So quality 100 should result in compression 0. $defaultOptions['png_compression_level'] = 9 - ceil($quality * 9 / 100); return $defaultOptions; }
/** * @param string $nodeTypeName * @param array $configuration * @throws Exception * @return void */ protected function addEditorDefaultsToNodeTypeConfiguration($nodeTypeName, array &$configuration) { if (isset($configuration['properties']) && is_array($configuration['properties'])) { foreach ($configuration['properties'] as $propertyName => &$propertyConfiguration) { if (!isset($propertyConfiguration['type'])) { continue; } $type = $propertyConfiguration['type']; if (!isset($this->dataTypesDefaultConfiguration[$type])) { continue; } if (!isset($propertyConfiguration['ui']['inspector'])) { continue; } $defaultConfigurationFromDataType = $this->dataTypesDefaultConfiguration[$type]; // FIRST STEP: Figure out which editor should be used // - Default: editor as configured from the data type // - Override: editor as configured from the property configuration. if (isset($propertyConfiguration['ui']['inspector']['editor'])) { $editor = $propertyConfiguration['ui']['inspector']['editor']; } elseif (isset($defaultConfigurationFromDataType['editor'])) { $editor = $defaultConfigurationFromDataType['editor']; } else { throw new Exception('Could not find editor for ' . $propertyName . ' in node type ' . $nodeTypeName, 1436809123); } // SECOND STEP: Build up the full inspector configuration by merging: // - take configuration from editor defaults // - take configuration from dataType // - take configuration from properties (NodeTypes) $mergedInspectorConfiguration = array(); if (isset($this->editorDefaultConfiguration[$editor])) { $mergedInspectorConfiguration = $this->editorDefaultConfiguration[$editor]; } $mergedInspectorConfiguration = Arrays::arrayMergeRecursiveOverrule($mergedInspectorConfiguration, $defaultConfigurationFromDataType); $mergedInspectorConfiguration = Arrays::arrayMergeRecursiveOverrule($mergedInspectorConfiguration, $propertyConfiguration['ui']['inspector']); $propertyConfiguration['ui']['inspector'] = $mergedInspectorConfiguration; $propertyConfiguration['ui']['inspector']['editor'] = $editor; } } }
/** * Create a validator for the element * * @param string $validatorIdentifier * @param array $options * @return mixed * @throws \Neos\Form\Exception\ValidatorPresetNotFoundException */ public function createValidator($validatorIdentifier, array $options = array()) { $validatorPresets = $this->getRootForm()->getValidatorPresets(); if (isset($validatorPresets[$validatorIdentifier]) && is_array($validatorPresets[$validatorIdentifier]) && isset($validatorPresets[$validatorIdentifier]['implementationClassName'])) { $implementationClassName = $validatorPresets[$validatorIdentifier]['implementationClassName']; $defaultOptions = isset($validatorPresets[$validatorIdentifier]['options']) ? $validatorPresets[$validatorIdentifier]['options'] : array(); $options = \Neos\Utility\Arrays::arrayMergeRecursiveOverrule($defaultOptions, $options); $validator = new $implementationClassName($options); $this->addValidator($validator); return $validator; } else { throw new \Neos\Form\Exception\ValidatorPresetNotFoundException('The validator preset identified by "' . $validatorIdentifier . '" could not be found, or the implementationClassName was not specified.', 1328710202); } }
/** * Loads the specified configuration file and returns its content as an * array. If the file does not exist or could not be loaded, an empty * array is returned * * @param string $pathAndFilename Full path and filename of the file to load, excluding the file extension (ie. ".yaml") * @param boolean $allowSplitSource If TRUE, the type will be used as a prefix when looking for configuration files * @return array * @throws ParseErrorException */ public function load($pathAndFilename, $allowSplitSource = false) { $pathsAndFileNames = [$pathAndFilename . '.yaml']; if ($allowSplitSource === true) { $splitSourcePathsAndFileNames = glob($pathAndFilename . '.*.yaml'); if ($splitSourcePathsAndFileNames !== false) { sort($splitSourcePathsAndFileNames); $pathsAndFileNames = array_merge($pathsAndFileNames, $splitSourcePathsAndFileNames); } } $configuration = []; foreach ($pathsAndFileNames as $pathAndFilename) { if (is_file($pathAndFilename)) { try { if ($this->usePhpYamlExtension) { if (strpos($pathAndFilename, 'resource://') === 0) { $yaml = file_get_contents($pathAndFilename); $loadedConfiguration = @yaml_parse($yaml); unset($yaml); } else { $loadedConfiguration = @yaml_parse_file($pathAndFilename); } if ($loadedConfiguration === false) { throw new ParseErrorException('A parse error occurred while parsing file "' . $pathAndFilename . '".', 1391894094); } } else { $loadedConfiguration = Yaml::parse($pathAndFilename); } if (is_array($loadedConfiguration)) { $configuration = Arrays::arrayMergeRecursiveOverrule($configuration, $loadedConfiguration); } } catch (Exception $exception) { throw new ParseErrorException('A parse error occurred while parsing file "' . $pathAndFilename . '". Error message: ' . $exception->getMessage(), 1232014321); } } } return $configuration; }
/** * @dataProvider arrayMergeRecursiveOverruleData * @test */ public function arrayMergeRecursiveOverruleMergesSimpleArrays($inputArray1, $inputArray2, $dontAddNewKeys, $emptyValuesOverride, $expected) { $actual = Arrays::arrayMergeRecursiveOverrule($inputArray1, $inputArray2, $dontAddNewKeys, $emptyValuesOverride); $this->assertSame($expected, $actual); }