Skip to content

[FrameworkBundle] Add a framework aware base command #23632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Console/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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\Console;

use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Command\Command as BaseCommand;
use Symfony\Component\HttpKernel\KernelInterface;

/**
* Framework aware base command.
*
* @author Roland Franssen <franssen.roland@gmail.com>
*/
abstract class Command extends BaseCommand
{
public function setApplication(BaseApplication $application = null)
{
if (null !== $application && !$application instanceof Application) {
throw new \InvalidArgumentException(sprintf('Application must be an instance of "%s", got "%s"', Application::class, get_class($application)));
}

parent::setApplication($application);
}

/**
* @return Application
*/
public function getApplication()
{
return parent::getApplication();
}

/**
* @return KernelInterface
*/
protected function getKernel()
{
return $this->getApplication()->getKernel();
}
}