Page MenuHomeIn-Portal Phabricator

AbstractCommand.php
No OneTemporary

File Metadata

Created
Mon, Oct 6, 5:35 PM

AbstractCommand.php

<?php
/**
* @version $Id: AbstractCommand.php 16283 2015-09-27 11:22:39Z alex $
* @package In-Portal
* @copyright Copyright (C) 1997 - 2015 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
namespace InPortal\Core\kernel\Console\Command;
use InPortal\Core\kernel\Console\ConsoleApplication;
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use InPortal\Core\kernel\Console\ConsoleIO;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
defined('FULL_PATH') or die('restricted access!');
abstract class AbstractCommand extends SymfonyCommand implements IConsoleCommand, CompletionAwareInterface
{
/**
* Reference to global kApplication instance
*
* @var \kApplication.
*/
protected $Application = null;
/**
* Connection to database.
*
* @var \IDBConnection
*/
protected $Conn = null;
/**
* Console IO.
*
* @var ConsoleIO
*/
protected $io;
/**
* Sets the application instance for this command.
*
* @param ConsoleApplication $application An Application instance.
*
* @return void
*/
public function setApplication(ConsoleApplication $application = null)
{
parent::setApplication($application);
// For disabled commands $application is not set.
if ( isset($application) ) {
$this->Application = $application->getKernelApplication();
$this->Conn =& $this->Application->GetADODBConnection();
}
}
/**
* Return possible values for the named option
*
* @param string $optionName Option name.
* @param CompletionContext $context Completion context.
*
* @return array
*/
public function completeOptionValues($optionName, CompletionContext $context)
{
$this->initDependencies();
return array();
}
/**
* Return possible values for the named argument
*
* @param string $argumentName Argument name.
* @param CompletionContext $context Completion context.
*
* @return array
*/
public function completeArgumentValues($argumentName, CompletionContext $context)
{
$this->initDependencies();
return array();
}
/**
* Perform additional validation of the input.
*
* @param InputInterface $input An InputInterface instance.
* @param OutputInterface $output An OutputInterface instance.
*
* @return void
* @throws \RuntimeException When not all required arguments were passed.
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
$arguments = array_filter($input->getArguments());
// Consider required arguments passed with empty values as an error.
if ( count($arguments) < $this->getDefinition()->getArgumentRequiredCount() ) {
throw new \RuntimeException('Not enough arguments.');
}
// Don't use factory because of "classmap:rebuild" command.
$this->io = new ConsoleIO($input, $output, $this->getHelperSet());
$this->initDependencies();
}
/**
* Initializes dependencies.
*
* @return void
*/
protected function initDependencies()
{
}
}

Event Timeline