Changeset View
Changeset View
Standalone View
Standalone View
branches/5.3.x/core/kernel/Console/Command/CompletionCommand.php
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | LF |
<?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 Stecman\Component\Symfony\Console\BashCompletion\Completion; | |||||
use Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand as BashCompletionCommand; | |||||
use Stecman\Component\Symfony\Console\BashCompletion\CompletionHandler; | |||||
defined('FULL_PATH') or die('restricted access!'); | |||||
class CompletionCommand extends BashCompletionCommand 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(); | |||||
} | |||||
} | |||||
/** | |||||
* Configure the CompletionHandler instance before it is run | |||||
* | |||||
* @param CompletionHandler $handler Completion handler. | |||||
* | |||||
* @return void | |||||
*/ | |||||
protected function configureCompletion(CompletionHandler $handler) | |||||
{ | |||||
// This can be removed once https://github.com/stecman/symfony-console-completion v0.5.2 will be released. | |||||
$handler->addHandler( | |||||
new Completion( | |||||
'help', | |||||
'command_name', | |||||
Completion::TYPE_ARGUMENT, | |||||
array_keys($this->getApplication()->all()) | |||||
) | |||||
); | |||||
$handler->addHandler( | |||||
new Completion( | |||||
'list', | |||||
'namespace', | |||||
Completion::TYPE_ARGUMENT, | |||||
$this->getApplication()->getNamespaces() | |||||
) | |||||
); | |||||
} | |||||
} |