Page MenuHomeIn-Portal Phabricator

AbstractCommand.php
No OneTemporary

File Metadata

Created
Wed, Jul 2, 2:47 PM

AbstractCommand.php

<?php
/**
* @version $Id$
* @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 Intechnic\InPortal\Core\kernel\Console\Command;
use Intechnic\InPortal\Core\kernel\Console\ConsoleApplication;
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
{
/**
* Reference to global kApplication instance
*
* @var \kApplication.
*/
protected $Application = null;
/**
* Connection to database.
*
* @var \IDBConnection
*/
protected $Conn = null;
/**
* 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();
}
}
/**
* 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.');
}
}
}

Event Timeline