Merge branch '3.2'

* 3.2:
  [2.7] Fix issues reported by static analyse
  [Serializer] Reduce nesting in YamlFileLoader
  [DependencyInjection] add missing dumped private services list in a container frozen constructor.
This commit is contained in:
Nicolas Grekas 2017-02-28 14:19:28 +01:00
commit 6bede45549
7 changed files with 138 additions and 26 deletions

View File

@ -112,7 +112,7 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface
* @param string|TemplateReferenceInterface|\Twig_Template $name A template name or an instance of
* TemplateReferenceInterface or \Twig_Template
*
* @return \Twig_TemplateInterface A \Twig_TemplateInterface instance
* @return \Twig_Template A \Twig_Template instance
*
* @throws \InvalidArgumentException if the template does not exist
*/

View File

@ -67,7 +67,7 @@ class TemplateManager
*
* @param Profile $profile
*
* @return Twig_Template[]
* @return \Twig_Template[]
*
* @deprecated not used anymore internally
*/

View File

@ -976,6 +976,7 @@ EOF;
$code .= "\n \$this->services = array();\n";
$code .= $this->addNormalizedIds();
$code .= $this->addMethodMap();
$code .= $this->addPrivateServices();
$code .= $this->addAliases();
$code .= <<<'EOF'

View File

@ -617,4 +617,17 @@ class PhpDumperTest extends TestCase
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services33.php', $dumper->dump());
}
public function testDumpContainerBuilderWithFrozenConstructorIncludingPrivateServices()
{
$container = new ContainerBuilder();
$container->register('foo_service', 'stdClass')->setArguments(array(new Reference('baz_service')));
$container->register('bar_service', 'stdClass')->setArguments(array(new Reference('baz_service')));
$container->register('baz_service', 'stdClass')->setPublic(false);
$container->compile();
$dumper = new PhpDumper($container);
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_private_frozen.php', $dumper->dump());
}
}

View File

@ -0,0 +1,97 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
/**
* ProjectServiceContainer.
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();
/**
* Constructor.
*/
public function __construct()
{
$this->services = array();
$this->methodMap = array(
'bar_service' => 'getBarServiceService',
'baz_service' => 'getBazServiceService',
'foo_service' => 'getFooServiceService',
);
$this->privates = array(
'baz_service' => true,
);
$this->aliases = array();
}
/**
* {@inheritdoc}
*/
public function compile()
{
throw new LogicException('You cannot compile a dumped frozen container.');
}
/**
* {@inheritdoc}
*/
public function isFrozen()
{
return true;
}
/**
* Gets the 'bar_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance
*/
protected function getBarServiceService()
{
return $this->services['bar_service'] = new \stdClass(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : $this->getBazServiceService()) && false ?: '_'});
}
/**
* Gets the 'foo_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance
*/
protected function getFooServiceService()
{
return $this->services['foo_service'] = new \stdClass(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : $this->getBazServiceService()) && false ?: '_'});
}
/**
* Gets the 'baz_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* This service is private.
* If you want to be able to request this service from the container directly,
* make it public, otherwise you might end up with broken code.
*
* @return \stdClass A stdClass instance
*/
protected function getBazServiceService()
{
return $this->services['baz_service'] = new \stdClass();
}
}

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\EventListener;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

View File

@ -45,48 +45,48 @@ class YamlFileLoader extends FileLoader
return false;
}
if (isset($this->classes[$classMetadata->getName()])) {
$yaml = $this->classes[$classMetadata->getName()];
if (!isset($this->classes[$classMetadata->getName()])) {
return false;
}
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
$attributesMetadata = $classMetadata->getAttributesMetadata();
$yaml = $this->classes[$classMetadata->getName()];
foreach ($yaml['attributes'] as $attribute => $data) {
if (isset($attributesMetadata[$attribute])) {
$attributeMetadata = $attributesMetadata[$attribute];
} else {
$attributeMetadata = new AttributeMetadata($attribute);
$classMetadata->addAttributeMetadata($attributeMetadata);
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
$attributesMetadata = $classMetadata->getAttributesMetadata();
foreach ($yaml['attributes'] as $attribute => $data) {
if (isset($attributesMetadata[$attribute])) {
$attributeMetadata = $attributesMetadata[$attribute];
} else {
$attributeMetadata = new AttributeMetadata($attribute);
$classMetadata->addAttributeMetadata($attributeMetadata);
}
if (isset($data['groups'])) {
if (!is_array($data['groups'])) {
throw new MappingException(sprintf('The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
}
if (isset($data['groups'])) {
if (!is_array($data['groups'])) {
throw new MappingException('The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName());
foreach ($data['groups'] as $group) {
if (!is_string($group)) {
throw new MappingException(sprintf('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
}
foreach ($data['groups'] as $group) {
if (!is_string($group)) {
throw new MappingException('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName());
}
$attributeMetadata->addGroup($group);
}
$attributeMetadata->addGroup($group);
}
if (isset($data['max_depth'])) {
if (!is_int($data['max_depth'])) {
throw new MappingException('The "max_depth" value must be an integer in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName());
throw new MappingException(sprintf('The "max_depth" value must be an integer in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
}
$attributeMetadata->setMaxDepth($data['max_depth']);
}
}
}
return true;
}
return false;
return true;
}
/**