/**
  * 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);
 }
Exemple #2
0
 /**
  * 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;
 }
 /**
  * Reconstitues related entities to an unserialized object in __wakeup.
  * Used in __wakeup methods of proxy classes.
  *
  * Note: This method adds code which ignores objects of type Neos\Flow\ResourceManagement\ResourcePointer in order to provide
  * backwards compatibility data generated with Flow 2.2.x which still provided that class.
  *
  * @return void
  */
 private function Flow_setRelatedEntities()
 {
     if (property_exists($this, 'Flow_Persistence_RelatedEntities') && is_array($this->Flow_Persistence_RelatedEntities)) {
         $persistenceManager = Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class);
         foreach ($this->Flow_Persistence_RelatedEntities as $entityInformation) {
             if ($entityInformation['entityType'] === ResourcePointer::class) {
                 continue;
             }
             $entity = $persistenceManager->getObjectByIdentifier($entityInformation['identifier'], $entityInformation['entityType'], true);
             if (isset($entityInformation['entityPath'])) {
                 $this->{$entityInformation['propertyName']} = Arrays::setValueByPath($this->{$entityInformation['propertyName']}, $entityInformation['entityPath'], $entity);
             } else {
                 $this->{$entityInformation['propertyName']} = $entity;
             }
         }
         unset($this->Flow_Persistence_RelatedEntities);
     }
 }
 /**
  * @param NodeInterface $rootNode
  * @param array<\Neos\ContentRepository\Domain\Model\NodeData> $nodes
  * @return array
  */
 public function collectParentNodeData(NodeInterface $rootNode, array $nodes)
 {
     $nodeCollection = array();
     $addNode = function ($node, $matched) use($rootNode, &$nodeCollection) {
         /** @var NodeInterface $node */
         $path = str_replace('/', '.children.', substr($node->getPath(), strlen($rootNode->getPath()) + 1));
         if ($path !== '') {
             $nodeCollection = Arrays::setValueByPath($nodeCollection, $path . '.node', $node);
             if ($matched === true) {
                 $nodeCollection = Arrays::setValueByPath($nodeCollection, $path . '.matched', true);
             }
         }
     };
     $findParent = function ($node) use(&$findParent, &$addNode) {
         /** @var NodeInterface $node */
         $parent = $node->getParent();
         if ($parent !== null) {
             $addNode($parent, false);
             $findParent($parent);
         }
     };
     foreach ($nodes as $node) {
         $addNode($node, true);
         $findParent($node);
     }
     $treeNodes = array();
     $self = $this;
     $collectTreeNodeData = function (&$treeNodes, $node) use(&$collectTreeNodeData, $self) {
         $children = array();
         if (isset($node['children'])) {
             foreach ($node['children'] as $childNode) {
                 $collectTreeNodeData($children, $childNode);
             }
         }
         $treeNodes[] = $self->collectTreeNodeData($node['node'], true, $children, $children !== array(), isset($node['matched']));
     };
     foreach ($nodeCollection as $firstLevelNode) {
         $collectTreeNodeData($treeNodes, $firstLevelNode);
     }
     return $treeNodes;
 }
 /**
  * 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;
 }
Exemple #6
0
 /**
  * @test
  */
 public function setValueByLeavesInputArrayUnchanged()
 {
     $subject = $subjectBackup = ['foo' => 'bar'];
     Arrays::setValueByPath($subject, 'foo', 'baz');
     $this->assertEquals($subject, $subjectBackup);
 }
 /**
  * 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]);
 }
Exemple #8
0
 /**
  * Sets the default value of a form element
  *
  * @param string $elementIdentifier identifier of the form element. This supports property paths!
  * @param mixed $defaultValue
  * @return void
  * @internal
  */
 public function addElementDefaultValue($elementIdentifier, $defaultValue)
 {
     $this->elementDefaultValues = \Neos\Utility\Arrays::setValueByPath($this->elementDefaultValues, $elementIdentifier, $defaultValue);
 }
 /**
  * {@inheritdoc}
  */
 public function postProcessFormValues(array $formValues)
 {
     $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Imagine.driver', $formValues['imagineDriver']);
     $this->configurationSource->save(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $this->distributionSettings);
     $this->configurationManager->flushConfigurationCache();
 }
Exemple #10
0
 /**
  * @param string $propertyPath
  * @param mixed $value
  * @return void
  */
 public function setFormValue($propertyPath, $value)
 {
     $this->formValues = \Neos\Utility\Arrays::setValueByPath($this->formValues, $propertyPath, $value);
 }
Exemple #11
0
 /**
  * Checks if the configured PHP binary is executable and the same version as the one
  * running the current (web server) PHP process. If not or if there is no binary configured,
  * tries to find the correct one on the PATH.
  *
  * Once found, the binary will be written to the configuration, if it is not the default one
  * (PHP_BINARY or in PHP_BINDIR).
  *
  * @return Message An error or warning message or NULL if PHP was detected successfully
  */
 protected function checkAndSetPhpBinaryIfNeeded()
 {
     $configurationSource = new YamlSource();
     $distributionSettings = $configurationSource->load(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS);
     if (isset($distributionSettings['TYPO3']['Flow']['core']['phpBinaryPathAndFilename'])) {
         return $this->checkPhpBinary($distributionSettings['TYPO3']['Flow']['core']['phpBinaryPathAndFilename']);
     }
     list($phpBinaryPathAndFilename, $message) = $this->detectPhpBinaryPathAndFilename();
     if ($phpBinaryPathAndFilename !== null) {
         $defaultPhpBinaryPathAndFilename = PHP_BINDIR . '/php';
         if (DIRECTORY_SEPARATOR !== '/') {
             $defaultPhpBinaryPathAndFilename = str_replace('\\', '/', $defaultPhpBinaryPathAndFilename) . '.exe';
         }
         if ($phpBinaryPathAndFilename !== $defaultPhpBinaryPathAndFilename) {
             $distributionSettings = \Neos\Utility\Arrays::setValueByPath($distributionSettings, 'Neos.Flow.core.phpBinaryPathAndFilename', $phpBinaryPathAndFilename);
             $configurationSource->save(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $distributionSettings);
         }
     }
     return $message;
 }
Exemple #12
0
 /**
  * This method is called when the form of this step has been submitted
  *
  * @param array $formValues
  * @return void
  * @throws \Exception
  */
 public function postProcessFormValues(array $formValues)
 {
     $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.driver', $formValues['driver']);
     $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.dbname', $formValues['dbname']);
     $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.user', $formValues['user']);
     $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.password', $formValues['password']);
     $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.host', $formValues['host']);
     $this->configurationSource->save(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $this->distributionSettings);
     $this->configurationManager->flushConfigurationCache();
     $settings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow');
     $connectionSettings = $settings['persistence']['backendOptions'];
     try {
         $this->connectToDatabase($connectionSettings);
     } catch (\Exception $exception) {
         if (!$exception instanceof DBALException && !$exception instanceof \PDOException) {
             throw $exception;
         }
         try {
             $this->createDatabase($connectionSettings, $formValues['dbname']);
         } catch (DBALException $exception) {
             throw new SetupException(sprintf('Database "%s" could not be created. Please check the permissions for user "%s". DBAL Exception: "%s"', $formValues['dbname'], $formValues['user'], $exception->getMessage()), 1351000841, $exception);
         } catch (\PDOException $exception) {
             throw new SetupException(sprintf('Database "%s" could not be created. Please check the permissions for user "%s". PDO Exception: "%s"', $formValues['dbname'], $formValues['user'], $exception->getMessage()), 1346758663, $exception);
         }
         try {
             $this->connectToDatabase($connectionSettings);
         } catch (DBALException $exception) {
             throw new SetupException(sprintf('Could not connect to database "%s". Please check the permissions for user "%s". DBAL Exception: "%s"', $formValues['dbname'], $formValues['user'], $exception->getMessage()), 1351000864);
         } catch (\PDOException $exception) {
             throw new SetupException(sprintf('Could not connect to database "%s". Please check the permissions for user "%s". PDO Exception: "%s"', $formValues['dbname'], $formValues['user'], $exception->getMessage()), 1346758737);
         }
     }
     $migrationExecuted = Scripts::executeCommand('neos.flow:doctrine:migrate', $settings, false);
     if ($migrationExecuted !== true) {
         throw new SetupException(sprintf('Could not execute database migrations. Please check the permissions for user "%s" and execute "./flow neos.flow:doctrine:migrate" manually.', $formValues['user']), 1346759486);
     }
     $this->resetPolicyRolesCacheAfterDatabaseChanges();
 }