Skip to content

Commit

Permalink
removed support for interface injection as well as all relevant tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Apr 23, 2011
1 parent b347aeb commit d9491a7
Show file tree
Hide file tree
Showing 25 changed files with 7 additions and 1,141 deletions.
Expand Up @@ -58,11 +58,4 @@
<argument>%kernel.root_dir%/Resources</argument>
</service>
</services>
<interfaces>
<interface class="Symfony\Component\DependencyInjection\ContainerAwareInterface">
<call method="setContainer">
<argument type="service" id="service_container" />
</call>
</interface>
</interfaces>
</container>
Expand Up @@ -49,9 +49,8 @@ public function process(ContainerBuilder $container)
if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) {
if ($definition->getFactoryClass() || $definition->getFactoryService()) {
throw new \RuntimeException(sprintf(
'Please add the class to service "%s" even if it is constructed '
.'by a factory since we might need to add method calls based on '
.'interface injection, or other compile-time checks.',
'Please add the class to service "%s" even if it is constructed by a factory '
.'since we might need to add method calls based on compile-time checks.',
$id
));
}
Expand All @@ -66,4 +65,4 @@ public function process(ContainerBuilder $container)
}
}
}
}
}
Expand Up @@ -49,7 +49,6 @@ public function __construct()
new ResolveParameterPlaceHoldersPass(),
new CheckDefinitionValidityPass(),
new ResolveReferencesToAliasesPass(),
new ResolveInterfaceInjectorsPass(),
new ResolveInvalidReferencesPass(),
new AnalyzeServiceReferencesPass(true),
new CheckCircularReferencesPass(),
Expand Down Expand Up @@ -224,4 +223,4 @@ public function setRemovingPasses(array $passes)
{
$this->removingPasses = $passes;
}
}
}

This file was deleted.

Expand Up @@ -51,13 +51,6 @@ public function process(ContainerBuilder $container)
}
$container->setAliases($aliases);

$injectors = array();
foreach ($container->getInterfaceInjectors() as $class => $injector) {
$injector->setClass($this->resolveValue($injector->getClass()));
$injectors[$this->resolveValue($class)] = $injector;
}
$container->setInterfaceInjectors($injectors);

$parameterBag = $container->getParameterBag();
foreach ($parameterBag->all() as $key => $value) {
$parameterBag->set($key, $this->resolveValue($value));
Expand Down
74 changes: 0 additions & 74 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Expand Up @@ -15,7 +15,6 @@
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\DependencyInjection\InterfaceInjector;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Resource\ResourceInterface;
Expand Down Expand Up @@ -341,7 +340,6 @@ public function merge(ContainerBuilder $container)

$this->addDefinitions($container->getDefinitions());
$this->addAliases($container->getAliases());
$this->addInterfaceInjectors($container->getInterfaceInjectors());
$this->getParameterBag()->add($container->getParameterBag()->all());

foreach ($container->getResources() as $resource) {
Expand Down Expand Up @@ -514,74 +512,6 @@ public function getAlias($id)
return $this->aliases[$id];
}

/**
* Adds an InterfaceInjector.
*
* @param InterfaceInjector $injector
*/
public function addInterfaceInjector(InterfaceInjector $injector)
{
$class = $injector->getClass();
if (isset($this->injectors[$class])) {
return $this->injectors[$class]->merge($injector);
}

$this->injectors[$class] = $injector;
}

/**
* Adds multiple InterfaceInjectors.
*
* @param array $injectors An array of InterfaceInjectors
*/
public function addInterfaceInjectors(array $injectors)
{
foreach ($injectors as $injector) {
$this->addInterfaceInjector($injector);
}
}

/**
* Gets defined InterfaceInjectors. If a service is provided, only that
* support the service will be returned.
*
* @param string $service If provided, only injectors supporting this service will be returned
*
* @return array An array of InterfaceInjectors
*/
public function getInterfaceInjectors($service = null)
{
if (null === $service) {
return $this->injectors;
}

return array_filter($this->injectors, function(InterfaceInjector $injector) use ($service) {
return $injector->supports($service);
});
}

/**
* Returns true if an InterfaceInjector is defined for the class.
*
* @param string $class The class
*
* @return Boolean true if at least one InterfaceInjector is defined, false otherwise
*/
public function hasInterfaceInjectorForClass($class)
{
return array_key_exists($class, $this->injectors);
}

/**
* Sets the defined InterfaceInjectors.
*
* @param array $injectors An array of InterfaceInjectors indexed by class names
*/
public function setInterfaceInjectors(array $injectors)
{
$this->injectors = $injectors;
}

/**
* Registers a service definition.
*
Expand Down Expand Up @@ -740,10 +670,6 @@ private function createService(Definition $definition, $id)
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
}

foreach ($this->getInterfaceInjectors($service) as $injector) {
$injector->processDefinition($definition, $service);
}

if (self::SCOPE_PROTOTYPE !== $scope = $definition->getScope()) {
if (self::SCOPE_CONTAINER !== $scope && !isset($this->scopedServices[$scope])) {
throw new \RuntimeException('You tried to create a service of an inactive scope.');
Expand Down
49 changes: 0 additions & 49 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Expand Up @@ -86,53 +86,12 @@ public function dump(array $options = array())
$code .=
$this->addServices().
$this->addDefaultParametersMethod().
$this->addInterfaceInjectors().
$this->endClass()
;

return $code;
}

/**
* Returns applyInterfaceInjectors function for the dumper.
*
* @return string
*/
private function addInterfaceInjectors()
{
if ($this->container->isFrozen() || 0 === count($this->container->getInterfaceInjectors())) {
return;
}

$code = <<<EOF
/**
* Applies all known interface injection calls
*
* @param Object \$instance
*/
protected function applyInterfaceInjectors(\$instance)
{
EOF;
foreach ($this->container->getInterfaceInjectors() as $injector) {
$code .= sprintf(" if (\$instance instanceof \\%s) {\n", $injector->getClass());
foreach ($injector->getMethodCalls() as $call) {
$arguments = array();
foreach ($call[1] as $value) {
$arguments[] = $this->dumpValue($value);
}
$code .= $this->wrapServiceConditionals($call[1], sprintf(" \$instance->%s(%s);\n", $call[0], implode(', ', $arguments)));
}
$code .= sprintf(" }\n");
}
$code .= <<<EOF
}
EOF;
return $code;
}

/**
* Generates Service local temp variables.
*
Expand Down Expand Up @@ -375,10 +334,6 @@ private function addServiceInstance($id, $definition)
*/
private function isSimpleInstance($id, $definition)
{
if (!$this->container->isFrozen() && count($this->container->getInterfaceInjectors()) > 0) {
return false;
}

foreach (array_merge(array($definition), $this->getInlinedDefinitions($definition)) as $sDefinition) {
if ($definition !== $sDefinition && !$this->hasReference($id, $sDefinition->getMethodCalls())) {
continue;
Expand Down Expand Up @@ -412,10 +367,6 @@ private function addServiceMethodCalls($id, $definition, $variableName = 'instan
$calls .= $this->wrapServiceConditionals($call[1], sprintf(" \$%s->%s(%s);\n", $variableName, $call[0], implode(', ', $arguments)));
}

if (!$this->container->isFrozen() && count($this->container->getInterfaceInjectors()) > 0) {
$calls .= sprintf("\n \$this->applyInterfaceInjectors(\$%s);\n", $variableName);
}

return $calls;
}

Expand Down
36 changes: 0 additions & 36 deletions src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
Expand Up @@ -15,7 +15,6 @@
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\InterfaceInjector;

/**
* XmlDumper dumps a service container as an XML string.
Expand Down Expand Up @@ -48,7 +47,6 @@ public function dump(array $options = array())

$this->addParameters($container);
$this->addServices($container);
$this->addInterfaceInjectors($container);

$this->document->appendChild($container);
$xml = $this->document->saveXML();
Expand Down Expand Up @@ -98,40 +96,6 @@ private function addMethodCalls(array $methodcalls, \DOMElement $parent)
}
}

/**
* Adds interface injector.
*
* @param InterfaceInjector $injector
* @param DOMElement $parent
* @return void
*/
private function addInterfaceInjector(InterfaceInjector $injector, \DOMElement $parent)
{
$interface = $this->document->createElement('interface');
$interface->setAttribute('class', $injector->getClass());
$this->addMethodCalls($injector->getMethodCalls(), $interface);
$parent->appendChild($interface);
}

/**
* Adds interface injectors.
*
* @param DOMElement $parent
* @return void
*/
private function addInterfaceInjectors(\DOMElement $parent)
{
if (!$this->container->getInterfaceInjectors()) {
return;
}

$interfaces = $this->document->createElement('interfaces');
foreach ($this->container->getInterfaceInjectors() as $injector) {
$this->addInterfaceInjector($injector, $interfaces);
}
$parent->appendChild($interfaces);
}

/**
* Adds a service.
*
Expand Down
24 changes: 1 addition & 23 deletions src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
Expand Up @@ -32,29 +32,7 @@ class YamlDumper extends Dumper
*/
public function dump(array $options = array())
{
return $this->addParameters().$this->addInterfaceInjectors()."\n".$this->addServices();
}

/**
* Adds interface injectors
*
* @return string
*/
private function addInterfaceInjectors()
{
if (!$this->container->getInterfaceInjectors()) {
return '';
}

$code = "\ninterfaces:\n";
foreach ($this->container->getInterfaceInjectors() as $injector) {
$code .= sprintf(" %s:\n", $injector->getClass());
if ($injector->getMethodCalls()) {
$code .= sprintf(" calls:\n %s\n", str_replace("\n", "\n ", Yaml::dump($this->dumpValue($injector->getMethodCalls()), 1)));
}
}

return $code;
return $this->addParameters()."\n".$this->addServices();
}

/**
Expand Down

0 comments on commit d9491a7

Please sign in to comment.