/**
  * @test
  */
 public function passingAnEmptyArrayToSetPropertiesRemovesAllExistingproperties()
 {
     $someProperties = array('prop1' => new \TYPO3\Flow\Object\Configuration\ConfigurationProperty('prop1', 'simple string'), 'prop2' => new \TYPO3\Flow\Object\Configuration\ConfigurationProperty('prop2', 'another string'));
     $this->objectConfiguration->setProperties($someProperties);
     $this->assertEquals($someProperties, $this->objectConfiguration->getProperties(), 'The set properties could not be retrieved again.');
     $this->objectConfiguration->setProperties(array());
     $this->assertEquals(array(), $this->objectConfiguration->getProperties(), 'The properties have not been cleared.');
 }
 /**
  * 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;
 }
 /**
  * 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, $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[] = '$this->' . $propertyName . ' = ' . $preparedSetterArgument . ';';
                 break;
             case ConfigurationProperty::PROPERTY_TYPES_SETTING:
                 $commands = array_merge($commands, $this->buildPropertyInjectionCodeBySettingPath($objectConfiguration, $propertyName, $propertyValue));
                 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;
 }