Bug #6928

ObjectContainerBuilder does not work for factory setups

Added by Karsten Dambekalns over 11 years ago. Updated about 11 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Object
Start date:
Due date:
% Done:

0%

Estimated time:
PHP Version:
Has patch:
Complexity:

Description

When configuring argument injection with a factory object and no name/classname the object container builder throws an exception (after fixing the first symptom), which is:

Notice: Undefined index: name in /.../Object/Configuration/ConfigurationBuilder.php line 162

The line causing this reads as follows:

static protected function parseArgumentOfTypeObject($argumentName, $objectNameOrConfiguration, $configurationSourceHint) {
    if (is_array($objectNameOrConfiguration)) {
        $objectName = $objectNameOrConfiguration['name'];

The Objects.yaml used:

F3\SwiftMailer\Mailer:
  arguments:
    1:
      object:
        factoryObjectName: F3\SwiftMailer\TransportFactory
        arguments:
          1:
            setting: SwiftMailer.transport.type
          2:
            setting: SwiftMailer.transport.options

Setting a classname there is not an option, as it would not be registered anyway. For property injection the case of a missing object name is handled on ConfigurationBuilder by those lines in parsePropertyOfTypeObject:

if (isset($objectNameOrConfiguration['name'])) {
    $objectName = $objectNameOrConfiguration['name'];
    unset($objectNameOrConfiguration['name']);
} else {
    $objectName = NULL;
}

Adding this to parseArgumentOfTypeObject does the trick, but then we come to the error in the object builder:

Notice: Undefined index: in /.../Object/Container/ObjectContainerBuilder.php line 280

The line causing this reads as follows:

if ($argumentValue instanceof \F3\FLOW3\Object\Configuration\Configuration) {
    $argumentValueObjectName = $argumentValue->getObjectName();
    if ($this->objectConfigurations[$argumentValueObjectName]->getScope() === \F3\FLOW3\Object\Configuration\Configuration::SCOPE_PROTOTYPE) {
        $assignments[] = $assignmentPrologue . '$this->getPrototype(\'' . $argumentValueObjectName . '\', array(' . $this->buildMethodParametersCode($argumentValue->getArguments()) . '))';

The bottom line is: using a factory with no object/class name does not work (anymore), neither for property nor argument injection.

Also available in: Atom PDF