Merge branch '3.4'

* 3.4:
  [DI] Deprecate XML services without ID
  [3.4] Allow 4.* deps
  Fix kernel.project_dir extensibility
This commit is contained in:
Nicolas Grekas 2017-05-27 12:06:16 +02:00
commit 1ecfa82ff0
12 changed files with 94 additions and 11 deletions

View File

@ -1,15 +1,20 @@
UPGRADE FROM 3.3 to 3.4 UPGRADE FROM 3.3 to 3.4
======================= =======================
DependencyInjection
-------------------
* Top-level anonymous services in XML are deprecated and will throw an exception in Symfony 4.0.
Finder Finder
------ ------
* The `Symfony\Component\Finder\Iterator\FilterIterator` class has been * The `Symfony\Component\Finder\Iterator\FilterIterator` class has been
deprecated and will be removed in 4.0 as it used to fix a bug which existed deprecated and will be removed in 4.0 as it used to fix a bug which existed
before version 5.5.23/5.6.7 before version 5.5.23/5.6.7.
Validator Validator
--------- ---------
* not setting the `strict` option of the `Choice` constraint to `true` is * Not setting the `strict` option of the `Choice` constraint to `true` is
deprecated and will throw an exception in Symfony 4.0 deprecated and will throw an exception in Symfony 4.0.

View File

@ -128,6 +128,8 @@ DependencyInjection
* The ``strict`` attribute in service arguments has been removed. * The ``strict`` attribute in service arguments has been removed.
The attribute is ignored since 3.0, so you can simply remove it. The attribute is ignored since 3.0, so you can simply remove it.
* Top-level anonymous services in XML are no longer supported.
EventDispatcher EventDispatcher
--------------- ---------------

View File

@ -52,12 +52,12 @@
<argument /> <!-- resource checkers --> <argument /> <!-- resource checkers -->
</service> </service>
<service class="Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker"> <service id="Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker">
<argument type="service" id="service_container" /> <argument type="service" id="service_container" />
<tag name="config_cache.resource_checker" priority="-980" /> <tag name="config_cache.resource_checker" priority="-980" />
</service> </service>
<service class="Symfony\Component\Config\Resource\SelfCheckingResourceChecker"> <service id="Symfony\Component\Config\Resource\SelfCheckingResourceChecker">
<tag name="config_cache.resource_checker" priority="-990" /> <tag name="config_cache.resource_checker" priority="-990" />
</service> </service>
</services> </services>

View File

@ -15,6 +15,7 @@ CHANGELOG
----- -----
* deprecated the ability to check for the initialization of a private service with the `Container::initialized()` method * deprecated the ability to check for the initialization of a private service with the `Container::initialized()` method
* deprecated support for top-level anonymous services in XML
3.3.0 3.3.0
----- -----

View File

@ -409,6 +409,8 @@ class XmlFileLoader extends FileLoader
// anonymous services "in the wild" // anonymous services "in the wild"
if (false !== $nodes = $xpath->query('//container:services/container:service[not(@id)]')) { if (false !== $nodes = $xpath->query('//container:services/container:service[not(@id)]')) {
foreach ($nodes as $node) { foreach ($nodes as $node) {
@trigger_error(sprintf('Top-level anonymous services are deprecated since Symfony 3.4, the "id" attribute will be required in version 4.0 in %s at line %d.', $file, $node->getLineNo()), E_USER_DEPRECATED);
// give it a unique name // give it a unique name
$id = sprintf('%d_%s', ++$count, hash('sha256', $file)); $id = sprintf('%d_%s', ++$count, hash('sha256', $file));
$node->setAttribute('id', $id); $node->setAttribute('id', $id);

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="FooClass">
<argument type="service">
<service class="BarClass" />
</argument>
</service>
</services>
</container>

View File

@ -5,7 +5,7 @@
<tag name="foo" /> <tag name="foo" />
</defaults> </defaults>
<service class="Bar" public="true" /> <service id="bar" class="Bar" public="true" />
<service id="with_defaults" class="Foo" /> <service id="with_defaults" class="Foo" />
<service id="no_defaults" class="Foo" public="true" autowire="false" /> <service id="no_defaults" class="Foo" public="true" autowire="false" />
<service id="child_def" parent="with_defaults" public="true" autowire="false" /> <service id="child_def" parent="with_defaults" public="true" autowire="false" />

View File

@ -18,7 +18,7 @@
</property> </property>
</service> </service>
<service id="bar" parent="foo" /> <service id="bar" parent="foo" />
<service class="BizClass"> <service id="biz" class="BizClass">
<tag name="biz_tag" /> <tag name="biz_tag" />
</service> </service>
</services> </services>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service class="FooClass"/>
<service id="FooClass">
<argument type="service">
<service class="BarClass" />
</argument>
</service>
</services>
</container>

View File

@ -230,6 +230,28 @@ class XmlFileLoaderTest extends TestCase
$this->assertSame($fooArgs[0], $barArgs[0]); $this->assertSame($fooArgs[0], $barArgs[0]);
} }
/**
* @group legacy
* @expectedDeprecation Top-level anonymous services are deprecated since Symfony 3.4, the "id" attribute will be required in version 4.0 in %sservices_without_id.xml at line 4.
*/
public function testLoadAnonymousServicesWithoutId()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('services_without_id.xml');
}
public function testLoadAnonymousNestedServices()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('nested_service_without_id.xml');
$this->assertTrue($container->hasDefinition('FooClass'));
$arguments = $container->getDefinition('FooClass')->getArguments();
$this->assertInstanceOf(Reference::class, array_shift($arguments));
}
public function testLoadServices() public function testLoadServices()
{ {
$container = new ContainerBuilder(); $container = new ContainerBuilder();
@ -655,9 +677,8 @@ class XmlFileLoaderTest extends TestCase
$this->assertSame('service_container', key($definitions)); $this->assertSame('service_container', key($definitions));
array_shift($definitions); array_shift($definitions);
$this->assertStringStartsWith('1_', key($definitions));
$anonymous = current($definitions); $anonymous = current($definitions);
$this->assertSame('bar', key($definitions));
$this->assertTrue($anonymous->isPublic()); $this->assertTrue($anonymous->isPublic());
$this->assertTrue($anonymous->isAutowired()); $this->assertTrue($anonymous->isAutowired());
$this->assertSame(array('foo' => array(array())), $anonymous->getTags()); $this->assertSame(array('foo' => array(array())), $anonymous->getTags());

View File

@ -80,7 +80,6 @@ abstract class Kernel implements KernelInterface, TerminableInterface
$this->environment = $environment; $this->environment = $environment;
$this->debug = (bool) $debug; $this->debug = (bool) $debug;
$this->rootDir = $this->getRootDir(); $this->rootDir = $this->getRootDir();
$this->projectDir = $this->getProjectDir();
$this->name = $this->getName(); $this->name = $this->getName();
if ($this->debug) { if ($this->debug) {
@ -546,7 +545,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
return array( return array(
'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir, 'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir,
'kernel.project_dir' => realpath($this->projectDir) ?: $this->projectDir, 'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
'kernel.environment' => $this->environment, 'kernel.environment' => $this->environment,
'kernel.debug' => $this->debug, 'kernel.debug' => $this->debug,
'kernel.name' => $this->name, 'kernel.name' => $this->name,

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\Tests; namespace Symfony\Component\HttpKernel\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Config\EnvParametersResource; use Symfony\Component\HttpKernel\Config\EnvParametersResource;
@ -813,3 +814,34 @@ class TestKernel implements HttpKernelInterface
{ {
} }
} }
class CustomProjectDirKernel extends Kernel
{
private $baseDir;
public function __construct()
{
parent::__construct('test', false);
$this->baseDir = 'foo';
}
public function registerBundles()
{
return array();
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
}
public function getProjectDir()
{
return $this->baseDir;
}
public function getRootDir()
{
return __DIR__.'/Fixtures';
}
}