feature #16411 [3.0] use ContainerAwareTrait (blanchonvincent, Tobion)
This PR was merged into the 3.0-dev branch. Discussion ---------- [3.0] use ContainerAwareTrait | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Finished version of #12595 This adds the first deprecation in symfony 3. We cannot deprecate ContainerAware in 2.8 as the alternative, the trait, cannot be used with php 5.3. So there would not be an upgrade path for people using an older php version Commits -------f75a940
[VarDumper] fix filename2309901
[VarDumper] replace VarDumperTestCase by trait24ff770
[TwigBundle] use ContainerAwareTrait in commandse337ce6
Remove deprecated ContainerAware class and make use of the trait in another class52c50e3
Remove abstract class and use Interface+Trait
This commit is contained in:
commit
697e6da19e
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Bridge\Doctrine;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Doctrine\Common\Persistence\AbstractManagerRegistry;
|
||||
|
||||
/**
|
||||
@ -22,10 +22,7 @@ use Doctrine\Common\Persistence\AbstractManagerRegistry;
|
||||
*/
|
||||
abstract class ManagerRegistry extends AbstractManagerRegistry implements ContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
use ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@ -42,12 +39,4 @@ abstract class ManagerRegistry extends AbstractManagerRegistry implements Contai
|
||||
{
|
||||
$this->container->set($name, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,12 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
@ -35,8 +36,10 @@ use Doctrine\Bundle\DoctrineBundle\Registry;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
abstract class Controller extends ContainerAware
|
||||
abstract class Controller implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* Generates a URL from the given parameters.
|
||||
*
|
||||
|
@ -11,7 +11,8 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@ -23,8 +24,10 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class RedirectController extends ContainerAware
|
||||
class RedirectController implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* Redirects to another route with the given name.
|
||||
*
|
||||
|
@ -11,7 +11,8 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
@ -19,8 +20,10 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class TemplateController extends ContainerAware
|
||||
class TemplateController implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* Renders a template.
|
||||
*
|
||||
|
@ -11,12 +11,15 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
|
||||
class FragmentController extends ContainerAware
|
||||
class FragmentController implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
public function indexAction(Request $request)
|
||||
{
|
||||
return $this->container->get('templating')->renderResponse('fragment.html.php', array('bar' => new Bar()));
|
||||
|
@ -11,11 +11,14 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
|
||||
class ProfilerController extends ContainerAware
|
||||
class ProfilerController implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
return new Response('Hello');
|
||||
|
@ -11,13 +11,16 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
|
||||
class SessionController extends ContainerAware
|
||||
class SessionController implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
public function welcomeAction(Request $request, $name = null)
|
||||
{
|
||||
$session = $request->getSession();
|
||||
|
@ -11,13 +11,16 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
||||
|
||||
class SubRequestController extends ContainerAware
|
||||
class SubRequestController implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$handler = $this->container->get('fragment.handler');
|
||||
|
@ -11,12 +11,15 @@
|
||||
|
||||
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\CsrfFormLoginBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
|
||||
class LoginController extends ContainerAware
|
||||
class LoginController implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
public function loginAction()
|
||||
{
|
||||
$form = $this->container->get('form.factory')->create('Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\CsrfFormLoginBundle\Form\UserLoginType');
|
||||
|
@ -11,13 +11,16 @@
|
||||
|
||||
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
|
||||
class LocalizedController extends ContainerAware
|
||||
class LocalizedController implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
public function loginAction(Request $request)
|
||||
{
|
||||
// get the login error if there is one
|
||||
|
@ -11,14 +11,17 @@
|
||||
|
||||
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
|
||||
class LoginController extends ContainerAware
|
||||
class LoginController implements ContainerAwareInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
public function loginAction(Request $request)
|
||||
{
|
||||
// get the login error if there is one
|
||||
|
@ -12,28 +12,17 @@
|
||||
namespace Symfony\Bundle\TwigBundle\Command;
|
||||
|
||||
use Symfony\Bridge\Twig\Command\DebugCommand as BaseDebugCommand;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* Lists twig functions, filters, globals and tests present in the current project.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class DebugCommand extends BaseDebugCommand implements ContainerAwareInterface
|
||||
final class DebugCommand extends BaseDebugCommand implements ContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface|null
|
||||
*/
|
||||
private $container;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
use ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -12,8 +12,8 @@
|
||||
namespace Symfony\Bundle\TwigBundle\Command;
|
||||
|
||||
use Symfony\Bridge\Twig\Command\LintCommand as BaseLintCommand;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
/**
|
||||
@ -22,20 +22,9 @@ use Symfony\Component\Finder\Finder;
|
||||
* @author Marc Weistroff <marc.weistroff@sensiolabs.com>
|
||||
* @author Jérôme Tamarelle <jerome@tamarelle.net>
|
||||
*/
|
||||
class LintCommand extends BaseLintCommand implements ContainerAwareInterface
|
||||
final class LintCommand extends BaseLintCommand implements ContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface|null
|
||||
*/
|
||||
private $container;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
use ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection;
|
||||
|
||||
/**
|
||||
* A simple implementation of ContainerAwareInterface.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since version 2.8, to be removed in 3.0. Use the ContainerAwareTrait instead.
|
||||
*/
|
||||
abstract class ContainerAware implements ContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Sets the Container associated with this Controller.
|
||||
*
|
||||
* @param ContainerInterface $container A ContainerInterface instance
|
||||
*/
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Bundle;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\Console\Application;
|
||||
@ -24,8 +24,10 @@ use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
abstract class Bundle extends ContainerAware implements BundleInterface
|
||||
abstract class Bundle implements BundleInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
protected $name;
|
||||
protected $extension;
|
||||
protected $path;
|
||||
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\VarDumper\Test;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @deprecated since version 2.8, to be removed in 3.0. Use the VarDumperTestTrait instead.
|
||||
*/
|
||||
abstract class VarDumperTestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function assertDumpEquals($dump, $data, $message = '')
|
||||
{
|
||||
$this->assertSame(rtrim($dump), $this->getDump($data), $message);
|
||||
}
|
||||
|
||||
public function assertDumpMatchesFormat($dump, $data, $message = '')
|
||||
{
|
||||
$this->assertStringMatchesFormat(rtrim($dump), $this->getDump($data), $message);
|
||||
}
|
||||
|
||||
protected function getDump($data)
|
||||
{
|
||||
$h = fopen('php://memory', 'r+b');
|
||||
$cloner = new VarCloner();
|
||||
$dumper = new CliDumper($h);
|
||||
$dumper->setColors(false);
|
||||
$dumper->dump($cloner->cloneVar($data)->withRefHandles(false));
|
||||
$data = stream_get_contents($h, -1, 0);
|
||||
fclose($h);
|
||||
|
||||
return rtrim($data);
|
||||
}
|
||||
}
|
@ -12,13 +12,15 @@
|
||||
namespace Symfony\Component\VarDumper\Tests\Caster;
|
||||
|
||||
use Symfony\Component\VarDumper\Caster\Caster;
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class CasterTest extends VarDumperTestCase
|
||||
class CasterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
use VarDumperTestTrait;
|
||||
|
||||
private $referenceArray = array(
|
||||
'null' => null,
|
||||
'empty' => false,
|
||||
|
@ -11,14 +11,16 @@
|
||||
|
||||
namespace Symfony\Component\VarDumper\Tests\Caster;
|
||||
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
|
||||
use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class ReflectionCasterTest extends VarDumperTestCase
|
||||
class ReflectionCasterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
use VarDumperTestTrait;
|
||||
|
||||
public function testReflectionCaster()
|
||||
{
|
||||
$var = new \ReflectionClass('ReflectionClass');
|
||||
@ -73,7 +75,7 @@ Closure {
|
||||
\$b: & 123
|
||||
}
|
||||
file: "%sReflectionCasterTest.php"
|
||||
line: "63 to 63"
|
||||
line: "65 to 65"
|
||||
}
|
||||
EOTXT
|
||||
, $var
|
||||
@ -93,7 +95,7 @@ Closure {
|
||||
returnType: "int"
|
||||
class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
|
||||
this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
|
||||
file: "%sReflectionCasterTest.php(88) : eval()'d code"
|
||||
file: "%sReflectionCasterTest.php(90) : eval()'d code"
|
||||
line: "1 to 1"
|
||||
}
|
||||
EOTXT
|
||||
|
@ -11,13 +11,15 @@
|
||||
|
||||
namespace Symfony\Component\VarDumper\Tests\Caster;
|
||||
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
|
||||
|
||||
/**
|
||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||
*/
|
||||
class SplCasterTest extends VarDumperTestCase
|
||||
class SplCasterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
use VarDumperTestTrait;
|
||||
|
||||
public function getCastFileInfoTests()
|
||||
{
|
||||
return array(
|
||||
|
@ -13,13 +13,15 @@ namespace Symfony\Component\VarDumper\Tests;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class CliDumperTest extends VarDumperTestCase
|
||||
class CliDumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
use VarDumperTestTrait;
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
require __DIR__.'/Fixtures/dumb-var.php';
|
||||
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
// Skipping trait tests for PHP < 5.4
|
||||
if (version_compare(PHP_VERSION, '5.4.0-dev', '>=')) {
|
||||
require 'VarDumpTestTraitRequire54.php';
|
||||
}
|
||||
|
@ -11,10 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\VarDumper\Tests\Test;
|
||||
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
|
||||
|
||||
class VarDumperTestTraitTest extends VarDumperTestCase
|
||||
class VarDumperTestTraitTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
use VarDumperTestTrait;
|
||||
|
Reference in New Issue
Block a user