Skip to content

interfaceInjectionEnabled="false" in the service disables interface injection #547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Symfony/Component/DependencyInjection/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Definition
private $public;
private $synthetic;
private $abstract;
private $interfaceInjectionEnabled;

protected $arguments;

Expand All @@ -50,6 +51,7 @@ public function __construct($class = null, array $arguments = array())
$this->public = true;
$this->synthetic = false;
$this->abstract = false;
$this->interfaceInjectionEnabled = true;
$this->properties = array();
}

Expand Down Expand Up @@ -507,6 +509,31 @@ public function isAbstract()
return $this->abstract;
}

/**
* Sets whether this definition allows interface injection
*
* @param Boolean $boolean
*
* @return Definition the current instance
*/
public function setInterfaceInjectionEnabled($boolean)
{
$this->interfaceInjectionEnabled = (Boolean) $boolean;

return $this;
}

/**
* Whether this definition is synthetic, that is not constructed by the
* container, but dynamically injected.
*
* @return Boolean
*/
public function isInterfaceInjectionEnabled()
{
return $this->interfaceInjectionEnabled;
}

/**
* Sets a configurator to call after the service is fully initialized.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ public function processDefinition(Definition $definition, $class = null)
return;
}

foreach ($this->calls as $callback) {
list($method, $arguments) = $callback;
$definition->addMethodCall($method, $arguments);
if ($definition->isInterfaceInjectionEnabled()) {
foreach ($this->calls as $callback) {
list($method, $arguments) = $callback;
$definition->addMethodCall($method, $arguments);
}
}

$this->processedDefinitions[] = $definition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private function parseDefinition($id, $service, $file)
$definition = new Definition();
}

foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'abstract') as $key) {
foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'abstract', 'interfaceInjectionEnabled') as $key) {
if (isset($service[$key])) {
$method = 'set'.str_replace('-', '', $key);
$definition->$method((string) $service->getAttributeAsPhp($key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ private function parseDefinition($id, $service, $file)
$definition->setAbstract($service['abstract']);
}

if (isset($service['interfaceInjectionEnabled'])) {
$definition->setInterfaceInjectionEnabled($service['interfaceInjectionEnabled']);
}

if (isset($service['factory_class'])) {
$definition->setFactoryClass($service['factory_class']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<xsd:attribute name="public" type="boolean" />
<xsd:attribute name="synthetic" type="boolean" />
<xsd:attribute name="abstract" type="boolean" />
<xsd:attribute name="interfaceInjectionEnabled" type="boolean" />
<xsd:attribute name="factory-class" type="xsd:string" />
<xsd:attribute name="factory-method" type="xsd:string" />
<xsd:attribute name="factory-service" type="xsd:string" />
Expand Down