/**
  * @test
  */
 public function theDefaultFactoryMethodNameIsCreate()
 {
     $this->assertSame('create', $this->objectConfiguration->getFactoryMethodName());
 }
Example #2
0
 /**
  * Parses the configuration for properties of type OBJECT
  *
  * @param string $propertyName Name of the property
  * @param mixed $objectNameOrConfiguration Value of the "object" section of the property configuration - either a string or an array
  * @param Configuration $parentObjectConfiguration The Configuration object this property belongs to
  * @return ConfigurationProperty A configuration property of type object
  * @throws InvalidObjectConfigurationException
  */
 protected function parsePropertyOfTypeObject($propertyName, $objectNameOrConfiguration, Configuration $parentObjectConfiguration)
 {
     if (is_array($objectNameOrConfiguration)) {
         if (isset($objectNameOrConfiguration['name'])) {
             $objectName = $objectNameOrConfiguration['name'];
             unset($objectNameOrConfiguration['name']);
         } else {
             if (isset($objectNameOrConfiguration['factoryObjectName'])) {
                 $objectName = null;
             } else {
                 $annotations = $this->reflectionService->getPropertyTagValues($parentObjectConfiguration->getClassName(), $propertyName, 'var');
                 if (count($annotations) !== 1) {
                     throw new InvalidObjectConfigurationException(sprintf('Object %s, for property "%s", contains neither object name, nor factory object name, and nor is the property properly @var - annotated.', $parentObjectConfiguration->getConfigurationSourceHint(), $propertyName, $parentObjectConfiguration->getClassName()), 1297097815);
                 }
                 $objectName = $annotations[0];
             }
         }
         $objectConfiguration = $this->parseConfigurationArray($objectName, $objectNameOrConfiguration, $parentObjectConfiguration->getConfigurationSourceHint() . ', property "' . $propertyName . '"');
         $property = new ConfigurationProperty($propertyName, $objectConfiguration, ConfigurationProperty::PROPERTY_TYPES_OBJECT);
     } else {
         $property = new ConfigurationProperty($propertyName, $objectNameOrConfiguration, ConfigurationProperty::PROPERTY_TYPES_OBJECT);
     }
     return $property;
 }
Example #3
0
 /**
  * Builds code which registers the lifecycle shutdown method, if any.
  *
  * @param Configuration $objectConfiguration
  * @param int $cause a ObjectManagerInterface::INITIALIZATIONCAUSE_* constant which is the cause of the initialization command being called.
  * @return string
  */
 protected function buildLifecycleShutdownCode(Configuration $objectConfiguration, $cause)
 {
     $lifecycleShutdownMethodName = $objectConfiguration->getLifecycleShutdownMethodName();
     if (!$this->reflectionService->hasMethod($objectConfiguration->getClassName(), $lifecycleShutdownMethodName)) {
         return '';
     }
     $className = $objectConfiguration->getClassName();
     $code = "\n" . '        $isSameClass = get_class($this) === \'' . $className . '\';';
     if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_RECREATED) {
         $code .= "\n" . '        $classParents = class_parents($this);';
         $code .= "\n" . '        $classImplements = class_implements($this);';
         $code .= "\n" . '        $isClassProxy = array_search(\'' . $className . '\', $classParents) !== FALSE && array_search(\'Doctrine\\ORM\\Proxy\\Proxy\', $classImplements) !== FALSE;' . "\n";
         $code .= "\n" . '        if ($isSameClass || $isClassProxy) {' . "\n";
     } else {
         $code .= "\n" . '        if ($isSameClass) {' . "\n";
     }
     $code .= '        \\Neos\\Flow\\Core\\Bootstrap::$staticObjectManager->registerShutdownObject($this, \'' . $lifecycleShutdownMethodName . '\');' . PHP_EOL;
     $code .= '        }' . "\n";
     return $code;
 }
 /**
  * Builds code which registers the lifecycle shutdown method, if any.
  *
  * @param Configuration $objectConfiguration
  * @return string
  */
 protected function buildLifecycleShutdownCode(Configuration $objectConfiguration)
 {
     $lifecycleShutdownMethodName = $objectConfiguration->getLifecycleShutdownMethodName();
     if (!$this->reflectionService->hasMethod($objectConfiguration->getClassName(), $lifecycleShutdownMethodName)) {
         return '';
     }
     $className = $objectConfiguration->getClassName();
     $code = "\n" . '        if (get_class($this) === \'' . $className . '\') {' . "\n";
     $code .= '        \\Neos\\Flow\\Core\\Bootstrap::$staticObjectManager->registerShutdownObject($this, \'' . $lifecycleShutdownMethodName . '\');' . PHP_EOL;
     $code .= '        }' . "\n";
     return $code;
 }
 /**
  * @test
  */
 public function itIsPossibleToPassArraysAsStraightArgumentOrPropertyValues()
 {
     $configurationArray = [];
     $configurationArray['properties']['straightValueProperty']['value'] = ['foo' => 'bar', 'object' => 'nö'];
     $configurationArray['arguments'][1]['value'] = ['foo' => 'bar', 'object' => 'nö'];
     $objectConfiguration = new Configuration('TestObject', 'TestObject');
     $objectConfiguration->setProperty(new ConfigurationProperty('straightValueProperty', ['foo' => 'bar', 'object' => 'nö']));
     $objectConfiguration->setArgument(new ConfigurationArgument(1, ['foo' => 'bar', 'object' => 'nö']));
     $configurationBuilder = $this->getAccessibleMock(ConfigurationBuilder::class, ['dummy']);
     $builtObjectConfiguration = $configurationBuilder->_call('parseConfigurationArray', 'TestObject', $configurationArray, __CLASS__);
     $this->assertEquals($objectConfiguration, $builtObjectConfiguration);
 }