/**
  * Checks, resolves and injects dependencies as properties through calling the setter methods or setting
  * properties directly through reflection.
  *
  * @param array $properties Array of \F3\FLOW3\Object\Configuration\ConfigurationProperty for the current object
  * @param object $object The recently created instance of the current object. Dependencies will be injected to it.
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 protected function injectProperties($properties, $object)
 {
     foreach ($properties as $propertyName => $property) {
         $propertyValue = $property->getValue();
         switch ($property->getType()) {
             case \F3\FLOW3\Object\Configuration\ConfigurationProperty::PROPERTY_TYPES_OBJECT:
                 if ($propertyValue instanceof \F3\FLOW3\Object\Configuration\Configuration) {
                     $preparedValue = $this->createObject($propertyValue->getObjectName(), $propertyValue);
                 } else {
                     if (strpos($propertyValue, '.') !== FALSE) {
                         $settingPath = explode('.', $propertyValue);
                         $settings = $this->configurationManager->getConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, array_shift($settingPath));
                         $propertyValue = \F3\FLOW3\Utility\Arrays::getValueByPath($settings, $settingPath);
                     }
                     $preparedValue = $this->objectManager->getObject($propertyValue);
                 }
                 break;
             case \F3\FLOW3\Object\Configuration\ConfigurationProperty::PROPERTY_TYPES_STRAIGHTVALUE:
                 $preparedValue = $propertyValue;
                 break;
             case \F3\FLOW3\Object\Configuration\ConfigurationProperty::PROPERTY_TYPES_SETTING:
                 if (strpos($propertyValue, '.') !== FALSE) {
                     $settingPath = explode('.', $propertyValue);
                     $settings = $this->configurationManager->getConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, array_shift($settingPath));
                     $preparedValue = \F3\FLOW3\Utility\Arrays::getValueByPath($settings, $settingPath);
                 } else {
                     $preparedValue = $this->configurationManager->getConfiguration(\F3\FLOW3\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $propertyValue);
                 }
                 break;
         }
         $setterMethodName = 'inject' . ucfirst($propertyName);
         if (method_exists($object, $setterMethodName)) {
             $object->{$setterMethodName}($preparedValue);
             continue;
         }
         $setterMethodName = 'set' . ucfirst($propertyName);
         if (method_exists($object, $setterMethodName)) {
             $object->{$setterMethodName}($preparedValue);
             continue;
         }
         if (property_exists($object, $propertyName)) {
             $propertyReflection = new \ReflectionProperty($object, $propertyName);
             $propertyReflection->setAccessible(TRUE);
             $propertyReflection->setValue($object, $preparedValue);
         }
     }
 }
Пример #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 = array();
     $fieldPaths = array();
     foreach ($convolutedFiles as $firstLevelFieldName => $fieldInformation) {
         if (!is_array($fieldInformation['error'])) {
             $fieldPaths[] = array($firstLevelFieldName);
         } else {
             $newFieldPaths = $this->calculateFieldPaths($fieldInformation['error'], $firstLevelFieldName);
             array_walk($newFieldPaths, function (&$value, $key) {
                 $value = explode('/', $value);
             });
             $fieldPaths = array_merge($fieldPaths, $newFieldPaths);
         }
     }
     foreach ($fieldPaths as $fieldPath) {
         if (count($fieldPath) === 1) {
             $fileInformation = $convolutedFiles[$fieldPath[0]];
         } else {
             $fileInformation = array();
             foreach ($convolutedFiles[$fieldPath[0]] as $key => $subStructure) {
                 $fileInformation[$key] = \F3\FLOW3\Utility\Arrays::getValueByPath($subStructure, array_slice($fieldPath, 1));
             }
         }
         $untangledFiles = \F3\FLOW3\Utility\Arrays::setValueByPath($untangledFiles, $fieldPath, $fileInformation);
     }
     return $untangledFiles;
 }
Пример #3
0
 /**
  * @test
  * @author Robert Lemke <*****@*****.**>
  */
 public function getValueByPathReturnsNullIfThePathHasMoreSegmentsThanTheGivenArray()
 {
     $array = array('Foo' => array('Bar' => array('Baz' => 'the value')));
     $this->assertNULL(\F3\FLOW3\Utility\Arrays::getValueByPath($array, array('Foo', 'Bar', 'Baz', 'Bux')));
 }