Skip to content

Commit

Permalink
Merge branch '3.2'
Browse files Browse the repository at this point in the history
* 3.2: (27 commits)
  Improve tracking of environment variables in the case of private services
  [DI] Align AutowirePass with 2.8
  property constraints can be added in child classes
  added test for staticClassLoader in LazyLoadingMetadatafactory
  fixed PHPUnit setUp and tearDown method visibility
  spelling fixes
  Readd Symfony version status in the toolbar
  [Security] LdapUserProvider should not throw an exception if the UID key does not exist in an LDAP entry
  make sure that null can be the invalid value
  [VarDumper] Improve dump of AMQP* Object
  Fix annotations cache folder path
  [FrameworkBundle] Wire ArrayCache for annotation reader at bootstrap
  Ignore missing 'debug.file_link_formatter' service in Debug bundle
  [VarDumper] Fixed dumping of terminated generator
  bumped Symfony version to 3.2.4
  updated VERSION for 3.2.3
  updated CHANGELOG for 3.2.3
  bumped Symfony version to 2.8.18
  updated VERSION for 2.8.17
  updated CHANGELOG for 2.8.17
  ...
  • Loading branch information
nicolas-grekas committed Feb 14, 2017
2 parents 3b9c55b + cda21bd commit a8bc3ab
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
31 changes: 9 additions & 22 deletions Compiler/AutowirePass.php
Expand Up @@ -423,26 +423,24 @@ private function set($type, $id)

// is this already a type/class that is known to match multiple services?
if (isset($this->ambiguousServiceTypes[$type])) {
$this->addServiceToAmbiguousType($id, $type);
$this->ambiguousServiceTypes[$type][] = $id;

return;
}

// check to make sure the type doesn't match multiple services
if (isset($this->types[$type])) {
if ($this->types[$type] === $id) {
return;
}

// keep an array of all services matching this type
$this->addServiceToAmbiguousType($id, $type);

unset($this->types[$type]);
if (!isset($this->types[$type]) || $this->types[$type] === $id) {
$this->types[$type] = $id;

return;
}

$this->types[$type] = $id;
// keep an array of all services matching this type
if (!isset($this->ambiguousServiceTypes[$type])) {
$this->ambiguousServiceTypes[$type] = array($this->types[$type]);
unset($this->types[$type]);
}
$this->ambiguousServiceTypes[$type][] = $id;
}

/**
Expand Down Expand Up @@ -489,17 +487,6 @@ private function createAutowiredDefinition(\ReflectionClass $typeHint)
return new Reference($argumentId);
}

private function addServiceToAmbiguousType($id, $type)
{
// keep an array of all services matching this type
if (!isset($this->ambiguousServiceTypes[$type])) {
$this->ambiguousServiceTypes[$type] = array(
$this->types[$type],
);
}
$this->ambiguousServiceTypes[$type][] = $id;
}

/**
* @deprecated since version 3.3, to be removed in 4.0.
*/
Expand Down
1 change: 1 addition & 0 deletions Compiler/RemoveUnusedDefinitionsPass.php
Expand Up @@ -71,6 +71,7 @@ public function process(ContainerBuilder $container)
$container->log($this, sprintf('Removed service "%s"; reason: replaces alias %s.', $id, reset($referencingAliases)));
} elseif (0 === count($referencingAliases) && false === $isReferenced) {
$container->removeDefinition($id);
$container->resolveEnvPlaceholders(serialize($definition));
$container->log($this, sprintf('Removed service "%s"; reason: unused.', $id));
$hasChanged = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Compiler/ReplaceAliasByActualDefinitionPass.php
Expand Up @@ -47,7 +47,7 @@ public function process(ContainerBuilder $container)
if (isset($replacements[$targetId])) {
$container->setAlias($definitionId, $replacements[$targetId]);
}
// No neeed to process the same target twice
// No need to process the same target twice
if (isset($seenAliasTargets[$targetId])) {
continue;
}
Expand Down
23 changes: 23 additions & 0 deletions Tests/Compiler/RemoveUnusedDefinitionsPassTest.php
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
use Symfony\Component\DependencyInjection\Compiler\RemoveUnusedDefinitionsPass;
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -105,6 +106,28 @@ public function testProcessWontRemovePrivateFactory()
$this->assertTrue($container->hasDefinition('foobar'));
}

public function testProcessConsiderEnvVariablesAsUsedEvenInPrivateServices()
{
$container = new ContainerBuilder();
$container->setParameter('env(FOOBAR)', 'test');
$container
->register('foo')
->setArguments(array('%env(FOOBAR)%'))
->setPublic(false)
;

$resolvePass = new ResolveParameterPlaceHoldersPass();
$resolvePass->process($container);

$this->process($container);

$this->assertFalse($container->hasDefinition('foo'));

$envCounters = $container->getEnvCounters();
$this->assertArrayHasKey('FOOBAR', $envCounters);
$this->assertSame(1, $envCounters['FOOBAR']);
}

protected function process(ContainerBuilder $container)
{
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new RemoveUnusedDefinitionsPass()));
Expand Down

0 comments on commit a8bc3ab

Please sign in to comment.