Bug #6928

ObjectContainerBuilder does not work for factory setups

Added by Karsten Dambekalns almost 11 years ago. Updated over 10 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.

#1

Updated by Karsten Dambekalns almost 11 years ago

  • Status changed from Accepted to New
  • Assignee deleted (Karsten Dambekalns)
  • Start date deleted (2010-03-19)

Postponing as it can be gotten to work with a marker interface and some YAML magic. Needs to be discussed.

#2

Updated by Robert Lemke over 10 years ago

  • Status changed from New to Needs Feedback
  • Priority changed from Must have to Should have
  • Target version set to 1.0 alpha 11
#3

Updated by Karsten Dambekalns over 10 years ago

  • Status changed from Needs Feedback to Closed

Closing, as the problem has not surfaced again so far. And in cases like these, adding an interface to allow for type hints makes sense, so the "workaround" actually looks like a good idea.

Also available in: Atom PDF