Skip to content

Commit

Permalink
renamed Command to ContainerAwareCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 20, 2011
1 parent 5744b52 commit 25e99e8
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 76 deletions.
3 changes: 3 additions & 0 deletions UPDATE.md
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php
Expand Up @@ -11,15 +11,15 @@

namespace Symfony\Bundle\DoctrineBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Doctrine\ORM\Tools\EntityGenerator;

/**
* Base class for Doctrine console commands to extend from.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
abstract class DoctrineCommand extends Command
abstract class DoctrineCommand extends ContainerAwareCommand
{
protected function getEntityGenerator()
{
Expand All @@ -35,7 +35,7 @@ protected function getEntityGenerator()

protected function getEntityManager($name)
{
return $this->container->get('doctrine')->getEntityManager($name);
return $this->getContainer()->get('doctrine')->getEntityManager($name);
}

/**
Expand All @@ -46,6 +46,6 @@ protected function getEntityManager($name)
*/
protected function getDoctrineConnection($name)
{
return $this->container->get('doctrine')->getConnection($name);
return $this->getContainer()->get('doctrine')->getConnection($name);
}
}
Expand Up @@ -71,7 +71,7 @@ protected function configure()

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'));
Expand All @@ -82,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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)) {
Expand Down
Expand Up @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
));

$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);
Expand Down
Expand Up @@ -46,7 +46,7 @@ protected function configure()

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'));
Expand Down
Expand Up @@ -22,7 +22,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class AssetsInstallCommand extends Command
class AssetsInstallCommand extends ContainerAwareCommand
{
/**
* @see Command
Expand Down Expand Up @@ -67,12 +67,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
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()));

Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
Expand Up @@ -23,7 +23,7 @@
* @author Francis Besset <francis.besset@gmail.com>
* @author Fabien Potencier <fabien@symfony.com>
*/
class CacheClearCommand extends Command
class CacheClearCommand extends ContainerAwareCommand
{
/**
* @see Command
Expand Down Expand Up @@ -52,7 +52,7 @@ protected function configure()
*/
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)) {
Expand All @@ -70,14 +70,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
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');
Expand Down Expand Up @@ -131,7 +131,7 @@ protected function getContainerClass()
}
}
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);
Expand Down
Expand Up @@ -19,7 +19,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class CacheWarmupCommand extends Command
class CacheWarmupCommand extends ContainerAwareCommand
{
/**
* @see Command
Expand All @@ -45,8 +45,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$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'));
}
}
37 changes: 0 additions & 37 deletions src/Symfony/Bundle/FrameworkBundle/Command/Command.php

This file was deleted.

@@ -0,0 +1,51 @@
<?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\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 <fabien@symfony.com>
*/
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;
}
}
Expand Up @@ -27,7 +27,7 @@
*
* @author Ryan Weaver <ryan@thatsquality.com>
*/
class ContainerDebugCommand extends Command
class ContainerDebugCommand extends ContainerAwareCommand
{
/**
* @var ContainerBuilder
Expand Down Expand Up @@ -183,7 +183,7 @@ private function getContainerBuilder()
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.'));
}

Expand Down
Expand Up @@ -23,7 +23,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class InitBundleCommand extends Command
class InitBundleCommand extends ContainerAwareCommand
{
/**
* @see Command
Expand Down Expand Up @@ -101,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
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);

Expand Down
Expand Up @@ -23,7 +23,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class RouterApacheDumperCommand extends Command
class RouterApacheDumperCommand extends ContainerAwareCommand
{
/**
* @see Command
Expand Down Expand Up @@ -53,7 +53,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$router = $this->container->get('router');
$router = $this->getContainer()->get('router');

$dumpOptions = array();
if ($input->getArgument('script_name')) {
Expand Down
Expand Up @@ -23,7 +23,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class RouterDebugCommand extends Command
class RouterDebugCommand extends ContainerAwareCommand
{
/**
* @see Command
Expand All @@ -50,7 +50,7 @@ protected function configure()
*/
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) {
Expand Down
14 changes: 7 additions & 7 deletions src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Bundle\SecurityBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;

This comment has been minimized.

Copy link
@tecbot

tecbot Jun 20, 2011

PHP Fatal error: Class 'Symfony\Bundle\SecurityBundle\Command\Command' not found.
you have forget to change the extends class in the InitAclCommand.

This comment has been minimized.

Copy link
@j

j Jun 20, 2011

Same error in vendor/bundles/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php.

use Symfony\Component\Security\Acl\Dbal\Schema;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -39,15 +39,15 @@ protected function configure()
*/
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) {
Expand Down
Expand Up @@ -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;
Expand All @@ -22,7 +22,7 @@
* @author Fabien Potencier <fabien@symfony.com>
* @author Clément JOBEILI <clement.jobeili@gmail.com>
*/
class SendEmailCommand extends Command
class SendEmailCommand extends ContainerAwareCommand
{
/**
* @see Command
Expand All @@ -49,14 +49,14 @@ protected function configure()
*/
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));
}
Expand Down

0 comments on commit 25e99e8

Please sign in to comment.