/** * @param array $module * @return mixed * @throws DisabledModuleException */ public function indexAction(array $module) { $moduleRequest = new ActionRequest($this->request); $moduleRequest->setArgumentNamespace('moduleArguments'); $moduleRequest->setControllerObjectName($module['controller']); $moduleRequest->setControllerActionName($module['action']); if (isset($module['format'])) { $moduleRequest->setFormat($module['format']); } if ($this->request->hasArgument($moduleRequest->getArgumentNamespace()) === true && is_array($this->request->getArgument($moduleRequest->getArgumentNamespace()))) { $moduleRequest->setArguments($this->request->getArgument($moduleRequest->getArgumentNamespace())); } foreach ($this->request->getPluginArguments() as $argumentNamespace => $argument) { $moduleRequest->setArgument('--' . $argumentNamespace, $argument); } $modules = explode('/', $module['module']); $moduleConfiguration = Arrays::getValueByPath($this->settings['modules'], implode('.submodules.', $modules)); $moduleConfiguration['path'] = $module['module']; if (!$this->menuHelper->isModuleEnabled($moduleConfiguration['path'])) { throw new DisabledModuleException(sprintf('The module "%s" is disabled. You can enable it with the "enabled" flag in Settings.yaml.', $module['module']), 1437148922); } $moduleBreadcrumb = array(); $path = array(); foreach ($modules as $moduleIdentifier) { array_push($path, $moduleIdentifier); $config = Arrays::getValueByPath($this->settings['modules'], implode('.submodules.', $path)); $moduleBreadcrumb[implode('/', $path)] = $config; } $moduleRequest->setArgument('__moduleConfiguration', $moduleConfiguration); $moduleResponse = new Response($this->response); $this->dispatcher->dispatch($moduleRequest, $moduleResponse); if ($moduleResponse->hasHeader('Location')) { $this->redirectToUri($moduleResponse->getHeader('Location'), 0, $moduleResponse->getStatusCode()); } elseif ($moduleRequest->getFormat() !== 'html') { $mediaType = MediaTypes::getMediaTypeFromFilename('file.' . $moduleRequest->getFormat()); if ($mediaType !== 'application/octet-stream') { $this->controllerContext->getResponse()->setHeader('Content-Type', $mediaType); } return $moduleResponse->getContent(); } else { $user = $this->partyService->getAssignedPartyOfAccount($this->securityContext->getAccount()); $sites = $this->menuHelper->buildSiteList($this->controllerContext); $this->view->assignMultiple(array('moduleClass' => implode('-', $modules), 'moduleContents' => $moduleResponse->getContent(), 'title' => $moduleRequest->hasArgument('title') ? $moduleRequest->getArgument('title') : $moduleConfiguration['label'], 'rootModule' => array_shift($modules), 'submodule' => array_shift($modules), 'moduleConfiguration' => $moduleConfiguration, 'moduleBreadcrumb' => $moduleBreadcrumb, 'user' => $user, 'modules' => $this->menuHelper->buildModuleList($this->controllerContext), 'sites' => $sites)); } }
/** * Returns the form definitions for the step * * @param FormDefinition $formDefinition * @return void */ protected function buildForm(FormDefinition $formDefinition) { $page1 = $formDefinition->createPage('page1'); $page1->setRenderingOption('header', 'Configure database'); $introduction = $page1->createElement('introduction', 'Neos.Form:StaticText'); $introduction->setProperty('text', 'Please enter database details below:'); $connectionSection = $page1->createElement('connectionSection', 'Neos.Form:Section'); $connectionSection->setLabel('Connection'); $databaseDriver = $connectionSection->createElement('driver', 'Neos.Form:SingleSelectDropdown'); $databaseDriver->setLabel('DB Driver'); $databaseDriver->setProperty('options', $this->getAvailableDrivers()); $databaseDriver->setDefaultValue(Arrays::getValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.driver')); $databaseDriver->addValidator(new NotEmptyValidator()); $databaseUser = $connectionSection->createElement('user', 'Neos.Form:SingleLineText'); $databaseUser->setLabel('DB Username'); $databaseUser->setDefaultValue(Arrays::getValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.user')); $databaseUser->addValidator(new NotEmptyValidator()); $databasePassword = $connectionSection->createElement('password', 'Neos.Form:Password'); $databasePassword->setLabel('DB Password'); $databasePassword->setDefaultValue(Arrays::getValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.password')); $databaseHost = $connectionSection->createElement('host', 'Neos.Form:SingleLineText'); $databaseHost->setLabel('DB Host'); $defaultHost = Arrays::getValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.host'); if ($defaultHost === null) { $defaultHost = '127.0.0.1'; } $databaseHost->setDefaultValue($defaultHost); $databaseHost->addValidator(new NotEmptyValidator()); $databaseSection = $page1->createElement('databaseSection', 'Neos.Form:Section'); $databaseSection->setLabel('Database'); $databaseName = $databaseSection->createElement('dbname', 'Neos.Setup:DatabaseSelector'); $databaseName->setLabel('DB Name'); $databaseName->setProperty('driverDropdownFieldId', $databaseDriver->getUniqueIdentifier()); $databaseName->setProperty('userFieldId', $databaseUser->getUniqueIdentifier()); $databaseName->setProperty('passwordFieldId', $databasePassword->getUniqueIdentifier()); $databaseName->setProperty('hostFieldId', $databaseHost->getUniqueIdentifier()); $databaseName->setDefaultValue(Arrays::getValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.dbname')); $databaseName->addValidator(new NotEmptyValidator()); }
/** * Sets labels for global NodeType elements like tabs and groups and the general label. * * @param string $nodeTypeLabelIdPrefix * @param array $configuration * @return void */ protected function setGlobalUiElementLabels($nodeTypeName, array &$configuration) { $nodeTypeLabelIdPrefix = $this->generateNodeTypeLabelIdPrefix($nodeTypeName); if ($this->shouldFetchTranslation($configuration['ui'])) { $configuration['ui']['label'] = $this->getInspectorElementTranslationId($nodeTypeLabelIdPrefix, 'ui', 'label'); } if (isset($configuration['ui']['help']['message']) && $this->shouldFetchTranslation($configuration['ui']['help'], 'message')) { $configuration['ui']['help']['message'] = $this->getInspectorElementTranslationId($nodeTypeLabelIdPrefix, 'ui', 'help.message'); } if (isset($configuration['ui']['help'])) { $configurationThumbnail = isset($configuration['ui']['help']['thumbnail']) ? $configuration['ui']['help']['thumbnail'] : null; $thumbnailUrl = $this->resolveHelpMessageThumbnail($nodeTypeName, $configurationThumbnail); if ($thumbnailUrl !== '') { $configuration['ui']['help']['thumbnail'] = $thumbnailUrl; } } $inspectorConfiguration = Arrays::getValueByPath($configuration, 'ui.inspector'); if (is_array($inspectorConfiguration)) { foreach ($inspectorConfiguration as $elementTypeName => $elementTypeItems) { foreach ($elementTypeItems as $elementName => $elementConfiguration) { if (!is_array($elementConfiguration) || !$this->shouldFetchTranslation($elementConfiguration)) { continue; } $translationLabelId = $this->getInspectorElementTranslationId($nodeTypeLabelIdPrefix, $elementTypeName, $elementName); $configuration['ui']['inspector'][$elementTypeName][$elementName]['label'] = $translationLabelId; } } } }
/** * 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 = []; $fieldPaths = []; foreach ($convolutedFiles as $firstLevelFieldName => $fieldInformation) { if (!is_array($fieldInformation['error'])) { $fieldPaths[] = [$firstLevelFieldName]; } else { $newFieldPaths = $this->calculateFieldPaths($fieldInformation['error'], $firstLevelFieldName); array_walk($newFieldPaths, function (&$value) { $value = explode('/', $value); }); $fieldPaths = array_merge($fieldPaths, $newFieldPaths); } } foreach ($fieldPaths as $fieldPath) { if (count($fieldPath) === 1) { $fileInformation = $convolutedFiles[$fieldPath[0]]; } else { $fileInformation = []; 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 * @throws Exception\InvalidConfigurationTypeException * @throws Exception\InvalidConfigurationException * @return void */ protected function loadConfiguration($configurationType, array $packages) { $this->cacheNeedsUpdate = true; $configurationProcessingType = $this->resolveConfigurationProcessingType($configurationType); $allowSplitSource = $this->isSplitSourceAllowedForConfigurationType($configurationType); switch ($configurationProcessingType) { case self::CONFIGURATION_PROCESSING_TYPE_SETTINGS: // Make sure that the Flow package is the first item of the packages array: if (isset($packages['Neos.Flow'])) { $flowPackage = $packages['Neos.Flow']; unset($packages['Neos.Flow']); $packages = array_merge(['Neos.Flow' => $flowPackage], $packages); unset($flowPackage); } $settings = []; /** @var $package PackageInterface */ foreach ($packages as $packageKey => $package) { if (Arrays::getValueByPath($settings, $packageKey) === null) { $settings = Arrays::setValueByPath($settings, $packageKey, []); } $settings = Arrays::arrayMergeRecursiveOverrule($settings, $this->configurationSource->load($package->getConfigurationPath() . $configurationType, $allowSplitSource)); } $settings = Arrays::arrayMergeRecursiveOverrule($settings, $this->configurationSource->load(FLOW_PATH_CONFIGURATION . $configurationType, $allowSplitSource)); foreach ($this->orderedListOfContextNames as $contextName) { /** @var $package PackageInterface */ foreach ($packages as $package) { $settings = Arrays::arrayMergeRecursiveOverrule($settings, $this->configurationSource->load($package->getConfigurationPath() . $contextName . '/' . $configurationType, $allowSplitSource)); } $settings = Arrays::arrayMergeRecursiveOverrule($settings, $this->configurationSource->load(FLOW_PATH_CONFIGURATION . $contextName . '/' . $configurationType, $allowSplitSource)); } if ($this->configurations[$configurationType] !== []) { $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $settings); } else { $this->configurations[$configurationType] = $settings; } $this->configurations[$configurationType]['Neos']['Flow']['core']['context'] = (string) $this->context; break; case self::CONFIGURATION_PROCESSING_TYPE_OBJECTS: $this->configurations[$configurationType] = []; /** @var $package PackageInterface */ foreach ($packages as $packageKey => $package) { $configuration = $this->configurationSource->load($package->getConfigurationPath() . $configurationType); $configuration = Arrays::arrayMergeRecursiveOverrule($configuration, $this->configurationSource->load(FLOW_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(FLOW_PATH_CONFIGURATION . $contextName . '/' . $configurationType)); } $this->configurations[$configurationType][$packageKey] = $configuration; } break; case self::CONFIGURATION_PROCESSING_TYPE_POLICY: if ($this->context->isTesting()) { $testingPolicyPathAndFilename = $this->temporaryDirectoryPath . 'Policy'; if ($this->configurationSource->has($testingPolicyPathAndFilename)) { $this->configurations[$configurationType] = $this->configurationSource->load($testingPolicyPathAndFilename); break; } } $this->configurations[$configurationType] = []; /** @var $package PackageInterface */ foreach ($packages as $package) { $packagePolicyConfiguration = $this->configurationSource->load($package->getConfigurationPath() . $configurationType, $allowSplitSource); $this->validatePolicyConfiguration($packagePolicyConfiguration, $package); $this->configurations[$configurationType] = $this->mergePolicyConfiguration($this->configurations[$configurationType], $packagePolicyConfiguration); } $this->configurations[$configurationType] = $this->mergePolicyConfiguration($this->configurations[$configurationType], $this->configurationSource->load(FLOW_PATH_CONFIGURATION . $configurationType, $allowSplitSource)); foreach ($this->orderedListOfContextNames as $contextName) { /** @var $package PackageInterface */ foreach ($packages as $package) { $packagePolicyConfiguration = $this->configurationSource->load($package->getConfigurationPath() . $contextName . '/' . $configurationType, $allowSplitSource); $this->validatePolicyConfiguration($packagePolicyConfiguration, $package); $this->configurations[$configurationType] = $this->mergePolicyConfiguration($this->configurations[$configurationType], $packagePolicyConfiguration); } $this->configurations[$configurationType] = $this->mergePolicyConfiguration($this->configurations[$configurationType], $this->configurationSource->load(FLOW_PATH_CONFIGURATION . $contextName . '/' . $configurationType, $allowSplitSource)); } break; case self::CONFIGURATION_PROCESSING_TYPE_DEFAULT: $this->configurations[$configurationType] = []; /** @var $package PackageInterface */ foreach ($packages as $package) { $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $this->configurationSource->load($package->getConfigurationPath() . $configurationType, $allowSplitSource)); } $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $this->configurationSource->load(FLOW_PATH_CONFIGURATION . $configurationType, $allowSplitSource)); foreach ($this->orderedListOfContextNames as $contextName) { /** @var $package PackageInterface */ foreach ($packages as $package) { $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $this->configurationSource->load($package->getConfigurationPath() . $contextName . '/' . $configurationType, $allowSplitSource)); } $this->configurations[$configurationType] = Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $this->configurationSource->load(FLOW_PATH_CONFIGURATION . $contextName . '/' . $configurationType, $allowSplitSource)); } break; case self::CONFIGURATION_PROCESSING_TYPE_ROUTES: // load main routes $this->configurations[$configurationType] = []; foreach (array_reverse($this->orderedListOfContextNames) as $contextName) { $this->configurations[$configurationType] = array_merge($this->configurations[$configurationType], $this->configurationSource->load(FLOW_PATH_CONFIGURATION . $contextName . '/' . $configurationType)); } $this->configurations[$configurationType] = array_merge($this->configurations[$configurationType], $this->configurationSource->load(FLOW_PATH_CONFIGURATION . $configurationType)); // load subroutes from Routes.yaml and Settings.yaml and merge them with main routes recursively $this->includeSubRoutesFromSettings($this->configurations[$configurationType]); $this->mergeRoutesWithSubRoutes($this->configurations[$configurationType]); break; case self::CONFIGURATION_PROCESSING_TYPE_APPEND: $this->configurations[$configurationType] = []; /** @var $package PackageInterface */ foreach ($packages as $package) { $this->configurations[$configurationType] = array_merge($this->configurations[$configurationType], $this->configurationSource->load($package->getConfigurationPath() . $configurationType, $allowSplitSource)); } $this->configurations[$configurationType] = array_merge($this->configurations[$configurationType], $this->configurationSource->load(FLOW_PATH_CONFIGURATION . $configurationType, $allowSplitSource)); foreach ($this->orderedListOfContextNames as $contextName) { foreach ($packages as $package) { $this->configurations[$configurationType] = array_merge($this->configurations[$configurationType], $this->configurationSource->load($package->getConfigurationPath() . $contextName . '/' . $configurationType, $allowSplitSource)); } $this->configurations[$configurationType] = array_merge($this->configurations[$configurationType], $this->configurationSource->load(FLOW_PATH_CONFIGURATION . $contextName . '/' . $configurationType, $allowSplitSource)); } break; default: throw new Exception\InvalidConfigurationTypeException('Configuration type "' . $configurationType . '" cannot be loaded with loadConfiguration().', 1251450613); } $this->postProcessConfiguration($this->configurations[$configurationType]); }
/** * Invokes the Factory defined in the object configuration of the specified object in order * to build an instance. Arguments which were defined in the object configuration are * passed to the factory method. * * @param string $objectName Name of the object to build * @return object The built object */ protected function buildObjectByFactory($objectName) { $factory = $this->get($this->objects[$objectName]['f'][0]); $factoryMethodName = $this->objects[$objectName]['f'][1]; $factoryMethodArguments = []; foreach ($this->objects[$objectName]['fa'] as $index => $argumentInformation) { switch ($argumentInformation['t']) { case ObjectConfigurationArgument::ARGUMENT_TYPES_SETTING: $settingPath = explode('.', $argumentInformation['v']); $factoryMethodArguments[$index] = Arrays::getValueByPath($this->allSettings, $settingPath); break; case ObjectConfigurationArgument::ARGUMENT_TYPES_STRAIGHTVALUE: $factoryMethodArguments[$index] = $argumentInformation['v']; break; case ObjectConfigurationArgument::ARGUMENT_TYPES_OBJECT: $factoryMethodArguments[$index] = $this->get($argumentInformation['v']); break; } } if (count($factoryMethodArguments) === 0) { return $factory->{$factoryMethodName}(); } else { return call_user_func_array([$factory, $factoryMethodName], $factoryMethodArguments); } }
/** * @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 $value * @return mixed */ public function getConfigurationValue($value) { return Arrays::getValueByPath($this->configuration, $value); }
/** * Checks whether a module is enabled or disabled in the configuration * * @param string $modulePath name of the module including parent modules ("mainModule/subModule/subSubModule") * @return boolean TRUE if module is enabled (default), FALSE otherwise */ public function isModuleEnabled($modulePath) { $modulePathSegments = explode('/', $modulePath); $moduleConfiguration = Arrays::getValueByPath($this->settings['modules'], implode('.submodules.', $modulePathSegments)); if (isset($moduleConfiguration['enabled']) && $moduleConfiguration['enabled'] !== true) { return false; } array_pop($modulePathSegments); if ($modulePathSegments === []) { return true; } return $this->isModuleEnabled(implode('/', $modulePathSegments)); }
/** * Determine whether we are able to find TypoScript at the requested position * * @return boolean TRUE if TypoScript exists at the current TypoScript path; FALSE otherwise */ protected function isTypoScriptFoundForCurrentRequest() { return Arrays::getValueByPath($this->parsedTypoScript, str_replace('/', '.', $this->getTypoScriptPathForCurrentRequest())) !== null; }
/** * @param \Neos\Form\Core\Model\Page $page * @return \Neos\Error\Messages\Result * @internal */ protected function mapAndValidatePage(\Neos\Form\Core\Model\Page $page) { $result = new \Neos\Error\Messages\Result(); $requestArguments = $this->request->getArguments(); $propertyPathsForWhichPropertyMappingShouldHappen = array(); $registerPropertyPaths = function ($propertyPath) use(&$propertyPathsForWhichPropertyMappingShouldHappen) { $propertyPathParts = explode('.', $propertyPath); $accumulatedPropertyPathParts = array(); foreach ($propertyPathParts as $propertyPathPart) { $accumulatedPropertyPathParts[] = $propertyPathPart; $temporaryPropertyPath = implode('.', $accumulatedPropertyPathParts); $propertyPathsForWhichPropertyMappingShouldHappen[$temporaryPropertyPath] = $temporaryPropertyPath; } }; foreach ($page->getElementsRecursively() as $element) { $value = \Neos\Utility\Arrays::getValueByPath($requestArguments, $element->getIdentifier()); $element->onSubmit($this, $value); $this->formState->setFormValue($element->getIdentifier(), $value); $registerPropertyPaths($element->getIdentifier()); } // The more parts the path has, the more early it is processed usort($propertyPathsForWhichPropertyMappingShouldHappen, function ($a, $b) { return substr_count($b, '.') - substr_count($a, '.'); }); $processingRules = $this->formDefinition->getProcessingRules(); foreach ($propertyPathsForWhichPropertyMappingShouldHappen as $propertyPath) { if (isset($processingRules[$propertyPath])) { $processingRule = $processingRules[$propertyPath]; $value = $this->formState->getFormValue($propertyPath); try { $value = $processingRule->process($value); } catch (\Neos\Flow\Property\Exception $exception) { throw new \Neos\Form\Exception\PropertyMappingException('Failed to process FormValue at "' . $propertyPath . '" from "' . gettype($value) . '" to "' . $processingRule->getDataType() . '"', 1355218921, $exception); } $result->forProperty($propertyPath)->merge($processingRule->getProcessingMessages()); $this->formState->setFormValue($propertyPath, $value); } } return $result; }
/** * Generate a schema for the given configuration or YAML file. * * ./flow configuration:generateschema --type Settings --path Neos.Flow.persistence * * The schema will be output to standard output. * * @param string $type Configuration type to create a schema for * @param string $path path to the subconfiguration separated by "." like "Neos.Flow" * @param string $yaml YAML file to create a schema for * @return void */ public function generateSchemaCommand($type = null, $path = null, $yaml = null) { $data = null; if ($yaml !== null && is_file($yaml) && is_readable($yaml)) { $data = Yaml::parse($yaml); } elseif ($type !== null) { $data = $this->configurationManager->getConfiguration($type); if ($path !== null) { $data = Arrays::getValueByPath($data, $path); } } if (empty($data)) { $this->outputLine('Data was not found or is empty'); $this->quit(1); } $this->outputLine(Yaml::dump($this->schemaGenerator->generate($data), 99)); }
/** * Validate a single configuration type * * @param string $configurationType the configuration typr to validate * @param string $path configuration path to validate, or NULL. * @param array $loadedSchemaFiles will be filled with a list of loaded schema files * @return \Neos\Error\Messages\Result * @throws Exception\SchemaValidationException */ protected function validateSingleType($configurationType, $path, &$loadedSchemaFiles) { $availableConfigurationTypes = $this->configurationManager->getAvailableConfigurationTypes(); if (in_array($configurationType, $availableConfigurationTypes) === false) { throw new Exception\SchemaValidationException('The configuration type "' . $configurationType . '" was not found. Only the following configuration types are supported: "' . implode('", "', $availableConfigurationTypes) . '"', 1364984886); } $configuration = $this->configurationManager->getConfiguration($configurationType); // find schema files for the given type and path $schemaFileInfos = []; $activePackages = $this->packageManager->getActivePackages(); foreach ($activePackages as $package) { $packageKey = $package->getPackageKey(); $packageSchemaPath = Files::concatenatePaths([$package->getResourcesPath(), 'Private/Schema']); if (is_dir($packageSchemaPath)) { foreach (Files::getRecursiveDirectoryGenerator($packageSchemaPath, '.schema.yaml') as $schemaFile) { $schemaName = substr($schemaFile, strlen($packageSchemaPath) + 1, -strlen('.schema.yaml')); $schemaNameParts = explode('.', str_replace('/', '.', $schemaName), 2); $schemaType = $schemaNameParts[0]; $schemaPath = isset($schemaNameParts[1]) ? $schemaNameParts[1] : null; if ($schemaType === $configurationType && ($path === null || strpos($schemaPath, $path) === 0)) { $schemaFileInfos[] = ['file' => $schemaFile, 'name' => $schemaName, 'path' => $schemaPath, 'packageKey' => $packageKey]; } } } } if (count($schemaFileInfos) === 0) { throw new Exception\SchemaValidationException('No schema files found for configuration type "' . $configurationType . '"' . ($path !== null ? ' and path "' . $path . '".' : '.'), 1364985056); } $result = new Result(); foreach ($schemaFileInfos as $schemaFileInfo) { $loadedSchemaFiles[] = $schemaFileInfo['file']; if ($schemaFileInfo['path'] !== null) { $data = Arrays::getValueByPath($configuration, $schemaFileInfo['path']); } else { $data = $configuration; } if (empty($data)) { $result->addNotice(new Notice('No configuration found, skipping schema "%s".', 1364985445, [substr($schemaFileInfo['file'], strlen(FLOW_PATH_ROOT))])); } else { $parsedSchema = Yaml::parse($schemaFileInfo['file']); $validationResultForSingleSchema = $this->schemaValidator->validate($data, $parsedSchema); if ($schemaFileInfo['path'] !== null) { $result->forProperty($schemaFileInfo['path'])->merge($validationResultForSingleSchema); } else { $result->merge($validationResultForSingleSchema); } } } return $result; }
/** * FIXME: Not yet completely refactored to new proxy mechanism * * @param array $argumentConfigurations * @return string */ protected function buildMethodParametersCode(array $argumentConfigurations) { $preparedArguments = []; foreach ($argumentConfigurations as $argument) { if ($argument === null) { $preparedArguments[] = 'NULL'; } else { $argumentValue = $argument->getValue(); switch ($argument->getType()) { case ConfigurationArgument::ARGUMENT_TYPES_OBJECT: if ($argumentValue instanceof Configuration) { $argumentValueObjectName = $argumentValue->getObjectName(); if ($this->objectConfigurations[$argumentValueObjectName]->getScope() === Configuration::SCOPE_PROTOTYPE) { $preparedArguments[] = 'new \\' . $argumentValueObjectName . '(' . $this->buildMethodParametersCode($argumentValue->getArguments(), $this->objectConfigurations) . ')'; } else { $preparedArguments[] = '\\Neos\\Flow\\Core\\Bootstrap::$staticObjectManager->get(\'' . $argumentValueObjectName . '\')'; } } else { if (strpos($argumentValue, '.') !== false) { $settingPath = explode('.', $argumentValue); $settings = Arrays::getValueByPath($this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS), array_shift($settingPath)); $argumentValue = Arrays::getValueByPath($settings, $settingPath); } $preparedArguments[] = '\\Neos\\Flow\\Core\\Bootstrap::$staticObjectManager->get(\'' . $argumentValue . '\')'; } break; case ConfigurationArgument::ARGUMENT_TYPES_STRAIGHTVALUE: $preparedArguments[] = var_export($argumentValue, true); break; case ConfigurationArgument::ARGUMENT_TYPES_SETTING: $preparedArguments[] = '\\Neos\\Flow\\Core\\Bootstrap::$staticObjectManager->getSettingsByPath(explode(\'.\', \'' . $argumentValue . '\'))'; break; } } } return implode(', ', $preparedArguments); }
/** * @param string $propertyPath * @return mixed */ public function getFormValue($propertyPath) { return \Neos\Utility\Arrays::getValueByPath($this->formValues, $propertyPath); }
/** * 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); }
/** * @return string */ public function editPreviewAction() { $this->response->setHeader('Content-Type', 'application/json'); $configuration = new PositionalArraySorter(Arrays::getValueByPath($this->settings, 'userInterface.editPreviewModes')); return json_encode($configuration->toArray()); }
/** * @test */ public function getValueByPathReturnsNullIfThePathHasMoreSegmentsThanTheGivenArray() { $array = ['Foo' => ['Bar' => ['Baz' => 'the value']]]; $this->assertNULL(Arrays::getValueByPath($array, ['Foo', 'Bar', 'Baz', 'Bux'])); }