diff --git a/UPDATE.md b/UPDATE.md index 3c596a7394..0442a1bc26 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -9,6 +9,9 @@ timeline closely anyway. beta5 to RC1 ------------ +* renamed `Symfony\Bundle\FrameworkBundle\Command\Command` to + `Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand` + * removed the routing `AnnotGlobLoader` class * Some blocks in the Twig Form templates have been renamed to avoid diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php index 4a05510c7d..9f5cf6efc2 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php @@ -11,7 +11,7 @@ namespace Symfony\Bundle\DoctrineBundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\Command; +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Doctrine\ORM\Tools\EntityGenerator; /** @@ -19,7 +19,7 @@ use Doctrine\ORM\Tools\EntityGenerator; * * @author Fabien Potencier */ -abstract class DoctrineCommand extends Command +abstract class DoctrineCommand extends ContainerAwareCommand { protected function getEntityGenerator() { @@ -35,7 +35,7 @@ abstract class DoctrineCommand extends Command protected function getEntityManager($name) { - return $this->container->get('doctrine')->getEntityManager($name); + return $this->getContainer()->get('doctrine')->getEntityManager($name); } /** @@ -46,6 +46,6 @@ abstract class DoctrineCommand extends Command */ protected function getDoctrineConnection($name) { - return $this->container->get('doctrine')->getConnection($name); + return $this->getContainer()->get('doctrine')->getConnection($name); } } diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php index c5307cae8d..e2dfc20384 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php @@ -71,7 +71,7 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { - $manager = new DisconnectedMetadataFactory($this->container->get('doctrine')); + $manager = new DisconnectedMetadataFactory($this->getContainer()->get('doctrine')); try { $bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('name')); @@ -82,7 +82,7 @@ EOT $name = strtr($input->getArgument('name'), '/', '\\'); if (false !== $pos = strpos($name, ':')) { - $name = $this->container->get('doctrine')->getEntityNamespace(substr($name, 0, $pos)).'\\'.substr($name, $pos + 1); + $name = $this->getContainer()->get('doctrine')->getEntityNamespace(substr($name, 0, $pos)).'\\'.substr($name, $pos + 1); } if (class_exists($name)) { diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntityDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntityDoctrineCommand.php index d17d220a18..dd53555987 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntityDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntityDoctrineCommand.php @@ -79,7 +79,7 @@ EOT )); $entity = substr($entity, $pos + 1); - $fullEntityClassName = $this->container->get('doctrine')->getEntityNamespace($bundleName).'\\'.$entity; + $fullEntityClassName = $this->getContainer()->get('doctrine')->getEntityNamespace($bundleName).'\\'.$entity; $mappingType = $input->getOption('mapping-type'); $class = new ClassMetadataInfo($fullEntityClassName); diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php index 13aa037cc6..f46140d1c0 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php @@ -46,7 +46,7 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { - $entityManagerName = $input->getOption('em') ? $input->getOption('em') : $this->container->get('doctrine')->getDefaultEntityManagerName(); + $entityManagerName = $input->getOption('em') ? $input->getOption('em') : $this->getContainer()->get('doctrine')->getDefaultEntityManagerName(); /* @var $entityManager Doctrine\ORM\EntityManager */ $entityManager = $this->getEntityManager($input->getOption('em')); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 1aeb152161..bafecb6ed9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -22,7 +22,7 @@ use Symfony\Component\Console\Output\Output; * * @author Fabien Potencier */ -class AssetsInstallCommand extends Command +class AssetsInstallCommand extends ContainerAwareCommand { /** * @see Command @@ -67,12 +67,12 @@ EOT throw new \InvalidArgumentException('The symlink() function is not available on your system. You need to install the assets without the --symlink option.'); } - $filesystem = $this->container->get('filesystem'); + $filesystem = $this->getContainer()->get('filesystem'); // Create the bundles directory otherwise symlink will fail. $filesystem->mkdir($input->getArgument('target').'/bundles/', 0777); - foreach ($this->container->get('kernel')->getBundles() as $bundle) { + foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) { if (is_dir($originDir = $bundle->getPath().'/Resources/public')) { $targetDir = $input->getArgument('target').'/bundles/'.preg_replace('/bundle$/', '', strtolower($bundle->getName())); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index 0b0bbc5b14..f91506ab9e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -23,7 +23,7 @@ use Symfony\Component\Finder\Finder; * @author Francis Besset * @author Fabien Potencier */ -class CacheClearCommand extends Command +class CacheClearCommand extends ContainerAwareCommand { /** * @see Command @@ -52,7 +52,7 @@ EOF */ protected function execute(InputInterface $input, OutputInterface $output) { - $realCacheDir = $this->container->getParameter('kernel.cache_dir'); + $realCacheDir = $this->getContainer()->getParameter('kernel.cache_dir'); $oldCacheDir = $realCacheDir.'_old'; if (!is_writable($realCacheDir)) { @@ -70,14 +70,14 @@ EOF rename($warmupDir, $realCacheDir); } - $this->container->get('filesystem')->remove($oldCacheDir); + $this->getContainer()->get('filesystem')->remove($oldCacheDir); } protected function warmup($warmupDir) { - $this->container->get('filesystem')->remove($warmupDir); + $this->getContainer()->get('filesystem')->remove($warmupDir); - $kernel = $this->getTempKernel($this->container->get('kernel'), $warmupDir); + $kernel = $this->getTempKernel($this->getContainer()->get('kernel'), $warmupDir); $kernel->boot(); $warmer = $kernel->getContainer()->get('cache_warmer'); @@ -131,7 +131,7 @@ namespace $namespace } } EOF; - $this->container->get('filesystem')->mkdir($warmupDir); + $this->getContainer()->get('filesystem')->mkdir($warmupDir); file_put_contents($file = $warmupDir.'/kernel.tmp', $code); require_once $file; @unlink($file); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php index d997812e87..f8e00650a3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php @@ -19,7 +19,7 @@ use Symfony\Component\Console\Output\OutputInterface; * * @author Fabien Potencier */ -class CacheWarmupCommand extends Command +class CacheWarmupCommand extends ContainerAwareCommand { /** * @see Command @@ -45,8 +45,8 @@ EOF { $output->writeln('Warming up the cache'); - $warmer = $this->container->get('cache_warmer'); + $warmer = $this->getContainer()->get('cache_warmer'); $warmer->enableOptionalWarmers(); - $warmer->warmUp($this->container->getParameter('kernel.cache_dir')); + $warmer->warmUp($this->getContainer()->getParameter('kernel.cache_dir')); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/Command.php b/src/Symfony/Bundle/FrameworkBundle/Command/Command.php deleted file mode 100644 index d9a0de378a..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Command/Command.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Command; - -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\Output; -use Symfony\Component\Console\Command\Command as BaseCommand; - -/** - * Command. - * - * @author Fabien Potencier - */ -abstract class Command extends BaseCommand -{ - /** - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected $container; - - protected function initialize(InputInterface $input, OutputInterface $output) - { - $this->container = $this->getApplication()->getKernel()->getContainer(); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerAwareCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerAwareCommand.php new file mode 100644 index 0000000000..3712ccb7c8 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerAwareCommand.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Command; + +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\Output; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; + +/** + * Command. + * + * @author Fabien Potencier + */ +abstract class ContainerAwareCommand extends Command implements ContainerAwareInterface +{ + /** + * @var ContainerInterface + */ + private $container; + + protected function getContainer() + { + if (null === $this->container) { + $this->container = $this->getApplication()->getKernel()->getContainer(); + } + + return $this->container; + } + + /** + * @see ContainerAwareInterface::setContainer() + */ + public function setContainer(ContainerInterface $container = null) + { + $this->container = $container; + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 3a05cc5ce7..d4be8b999f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -27,7 +27,7 @@ use Symfony\Component\Config\FileLocator; * * @author Ryan Weaver */ -class ContainerDebugCommand extends Command +class ContainerDebugCommand extends ContainerAwareCommand { /** * @var ContainerBuilder @@ -183,7 +183,7 @@ EOF throw new \LogicException(sprintf('Debug information about the container is only available in debug mode.')); } - if (!file_exists($cachedFile = $this->container->getParameter('debug.container.dump'))) { + if (!file_exists($cachedFile = $this->getContainer()->getParameter('debug.container.dump'))) { throw new \LogicException(sprintf('Debug information about the container could not be found. Please clear the cache and try again.')); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php index 0bdd0d47c8..17f01dcd3d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php @@ -23,7 +23,7 @@ use Symfony\Bundle\FrameworkBundle\Generator\Generator; * * @author Fabien Potencier */ -class InitBundleCommand extends Command +class InitBundleCommand extends ContainerAwareCommand { /** * @see Command @@ -101,7 +101,7 @@ EOT throw new \RuntimeException(sprintf('Bundle "%s" already exists.', $bundle)); } - $filesystem = $this->container->get('filesystem'); + $filesystem = $this->getContainer()->get('filesystem'); $filesystem->mirror(__DIR__.'/../Resources/skeleton/bundle/generic', $targetDir); $filesystem->mirror(__DIR__.'/../Resources/skeleton/bundle/'.$input->getOption('format'), $targetDir); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php index 8d2d64906c..1fc480ae7f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php @@ -23,7 +23,7 @@ use Symfony\Component\Routing\Matcher\Dumper\ApacheMatcherDumper; * * @author Fabien Potencier */ -class RouterApacheDumperCommand extends Command +class RouterApacheDumperCommand extends ContainerAwareCommand { /** * @see Command @@ -53,7 +53,7 @@ EOF */ protected function execute(InputInterface $input, OutputInterface $output) { - $router = $this->container->get('router'); + $router = $this->getContainer()->get('router'); $dumpOptions = array(); if ($input->getArgument('script_name')) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index 4b53504550..c003b03a2d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -23,7 +23,7 @@ use Symfony\Component\Routing\Matcher\Dumper\ApacheMatcherDumper; * * @author Fabien Potencier */ -class RouterDebugCommand extends Command +class RouterDebugCommand extends ContainerAwareCommand { /** * @see Command @@ -50,7 +50,7 @@ EOF */ protected function execute(InputInterface $input, OutputInterface $output) { - $router = $this->container->get('router'); + $router = $this->getContainer()->get('router'); $routes = array(); foreach ($router->getRouteCollection()->all() as $name => $route) { diff --git a/src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php b/src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php index ee76b12621..8d61c3695b 100644 --- a/src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php +++ b/src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php @@ -11,7 +11,7 @@ namespace Symfony\Bundle\SecurityBundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\Command; +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Security\Acl\Dbal\Schema; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -39,15 +39,15 @@ class InitAclCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $connection = $this->container->get('security.acl.dbal.connection'); + $connection = $this->getContainer()->get('security.acl.dbal.connection'); $sm = $connection->getSchemaManager(); $tableNames = $sm->listTableNames(); $tables = array( - 'class_table_name' => $this->container->getParameter('security.acl.dbal.class_table_name'), - 'sid_table_name' => $this->container->getParameter('security.acl.dbal.sid_table_name'), - 'oid_table_name' => $this->container->getParameter('security.acl.dbal.oid_table_name'), - 'oid_ancestors_table_name' => $this->container->getParameter('security.acl.dbal.oid_ancestors_table_name'), - 'entry_table_name' => $this->container->getParameter('security.acl.dbal.entry_table_name'), + 'class_table_name' => $this->getContainer()->getParameter('security.acl.dbal.class_table_name'), + 'sid_table_name' => $this->getContainer()->getParameter('security.acl.dbal.sid_table_name'), + 'oid_table_name' => $this->getContainer()->getParameter('security.acl.dbal.oid_table_name'), + 'oid_ancestors_table_name' => $this->getContainer()->getParameter('security.acl.dbal.oid_ancestors_table_name'), + 'entry_table_name' => $this->getContainer()->getParameter('security.acl.dbal.entry_table_name'), ); foreach ($tables as $table) { diff --git a/src/Symfony/Bundle/SwiftmailerBundle/Command/SendEmailCommand.php b/src/Symfony/Bundle/SwiftmailerBundle/Command/SendEmailCommand.php index 2d7d0e53dd..6c1f5206ba 100644 --- a/src/Symfony/Bundle/SwiftmailerBundle/Command/SendEmailCommand.php +++ b/src/Symfony/Bundle/SwiftmailerBundle/Command/SendEmailCommand.php @@ -11,7 +11,7 @@ namespace Symfony\Bundle\SwiftmailerBundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\Command; +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; @@ -22,7 +22,7 @@ use Symfony\Component\Console\Input\InputOption; * @author Fabien Potencier * @author Clément JOBEILI */ -class SendEmailCommand extends Command +class SendEmailCommand extends ContainerAwareCommand { /** * @see Command @@ -49,14 +49,14 @@ EOF */ protected function execute(InputInterface $input, OutputInterface $output) { - $mailer = $this->container->get('mailer'); + $mailer = $this->getContainer()->get('mailer'); $transport = $mailer->getTransport(); if ($transport instanceof \Swift_Transport_SpoolTransport) { $spool = $transport->getSpool(); $spool->setMessageLimit($input->getOption('message-limit')); $spool->setTimeLimit($input->getOption('time-limit')); - $sent = $spool->flushQueue($this->container->get('swiftmailer.transport.real')); + $sent = $spool->flushQueue($this->getContainer()->get('swiftmailer.transport.real')); $output->writeln(sprintf('sent %s emails', $sent)); }