/**
  * 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 \TYPO3\Flow\Error\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 = array();
     $activePackages = $this->packageManager->getActivePackages();
     foreach ($activePackages as $package) {
         $packageKey = $package->getPackageKey();
         $packageSchemaPath = \TYPO3\Flow\Utility\Files::concatenatePaths(array($package->getResourcesPath(), 'Private/Schema'));
         if (is_dir($packageSchemaPath)) {
             $packageSchemaFiles = \TYPO3\Flow\Utility\Files::readDirectoryRecursively($packageSchemaPath, '.schema.yaml');
             foreach ($packageSchemaFiles 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[] = array('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 = \TYPO3\Flow\Utility\Arrays::getValueByPath($configuration, $schemaFileInfo['path']);
         } else {
             $data = $configuration;
         }
         if (empty($data)) {
             $result->addNotice(new Notice('No configuration found, skipping schema "%s".', 1364985445, array(substr($schemaFileInfo['file'], strlen(FLOW_PATH_ROOT)))));
         } else {
             $parsedSchema = \Symfony\Component\Yaml\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;
 }
 /**
  * @param string $type
  * @return void
  */
 public function indexAction($type = 'Settings')
 {
     $availableConfigurationTypes = $this->configurationManager->getAvailableConfigurationTypes();
     $this->view->assignMultiple(array('type' => $type, 'availableConfigurationTypes' => $availableConfigurationTypes));
     if (in_array($type, $availableConfigurationTypes)) {
         $this->view->assign('configuration', $this->configurationManager->getConfiguration($type));
         try {
             $this->view->assign('validationResult', $this->configurationSchemaValidator->validate($type));
         } catch (\TYPO3\Flow\Configuration\Exception\SchemaValidationException $exception) {
             $this->addFlashMessage($exception->getMessage(), 'An error occurred during validation of the configuration.', Message::SEVERITY_ERROR, array(), 1412373972);
         }
     } else {
         $this->addFlashMessage('Configuration type not found.', '', Message::SEVERITY_ERROR, array(), 1412373998);
     }
 }
 /**
  * List registered configuration types
  *
  * @return void
  */
 public function listTypesCommand()
 {
     $this->outputLine('The following configuration types are registered:');
     $this->outputLine();
     foreach ($this->configurationManager->getAvailableConfigurationTypes() as $type) {
         $this->outputFormatted('- %s', array($type));
     }
 }
 /**
  * Builds the code necessary to inject setter based dependencies.
  *
  * @param Configuration $objectConfiguration (needed to produce helpful exception message)
  * @return string The built code
  * @throws \TYPO3\Flow\Object\Exception\UnknownObjectException
  */
 protected function buildPropertyInjectionCode(Configuration $objectConfiguration)
 {
     $commands = array();
     $injectedProperties = array();
     foreach ($objectConfiguration->getProperties() as $propertyName => $propertyConfiguration) {
         /* @var $propertyConfiguration ConfigurationProperty */
         if ($propertyConfiguration->getAutowiring() === Configuration::AUTOWIRING_MODE_OFF) {
             continue;
         }
         $propertyValue = $propertyConfiguration->getValue();
         switch ($propertyConfiguration->getType()) {
             case ConfigurationProperty::PROPERTY_TYPES_OBJECT:
                 if ($propertyValue instanceof Configuration) {
                     $commands = array_merge($commands, $this->buildPropertyInjectionCodeByConfiguration($objectConfiguration, $propertyName, $propertyValue));
                 } else {
                     $commands = array_merge($commands, $this->buildPropertyInjectionCodeByString($objectConfiguration, $propertyConfiguration, $propertyName, $propertyValue));
                 }
                 break;
             case ConfigurationProperty::PROPERTY_TYPES_STRAIGHTVALUE:
                 if (is_string($propertyValue)) {
                     $preparedSetterArgument = '\'' . str_replace('\'', '\\\'', $propertyValue) . '\'';
                 } elseif (is_array($propertyValue)) {
                     $preparedSetterArgument = var_export($propertyValue, true);
                 } elseif (is_bool($propertyValue)) {
                     $preparedSetterArgument = $propertyValue ? 'TRUE' : 'FALSE';
                 } else {
                     $preparedSetterArgument = $propertyValue;
                 }
                 $commands[] = 'if (\\TYPO3\\Flow\\Reflection\\ObjectAccess::setProperty($this, \'' . $propertyName . '\', ' . $preparedSetterArgument . ') === FALSE) { $this->' . $propertyName . ' = ' . $preparedSetterArgument . ';}';
                 break;
             case ConfigurationProperty::PROPERTY_TYPES_CONFIGURATION:
                 $configurationType = $propertyValue['type'];
                 if (!in_array($configurationType, $this->configurationManager->getAvailableConfigurationTypes())) {
                     throw new \TYPO3\Flow\Object\Exception\UnknownObjectException('The configuration injection specified for property "' . $propertyName . '" in the object configuration of object "' . $objectConfiguration->getObjectName() . '" refers to the unknown configuration type "' . $configurationType . '".', 1420736211);
                 }
                 $commands = array_merge($commands, $this->buildPropertyInjectionCodeByConfigurationTypeAndPath($objectConfiguration, $propertyName, $configurationType, $propertyValue['path']));
                 break;
         }
         $injectedProperties[] = $propertyName;
     }
     if (count($commands) > 0) {
         $commandString = "\t\t" . implode("\n\t\t", $commands) . "\n";
         $commandString .= '$this->Flow_Injected_Properties = ' . var_export($injectedProperties, true) . ";\n";
     } else {
         $commandString = '';
     }
     return $commandString;
 }