Changeset View
Changeset View
Standalone View
Standalone View
branches/5.3.x/core/kernel/Console/Command/BuildClassMapCommand.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\utility\ClassDiscovery\ClassMapBuilder; | |||||
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface; | |||||
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; | |||||
use Symfony\Component\Console\Input\InputInterface; | |||||
use Symfony\Component\Console\Input\InputOption; | |||||
use Symfony\Component\Console\Output\OutputInterface; | |||||
defined('FULL_PATH') or die('restricted access!'); | |||||
class BuildClassMapCommand extends AbstractCommand implements CompletionAwareInterface | |||||
{ | |||||
/** | |||||
* Configures the current command. | |||||
* | |||||
* @return void | |||||
*/ | |||||
protected function configure() | |||||
{ | |||||
$this | |||||
->setName('classmap:rebuild') | |||||
->setDescription('Rebuilds the class map') | |||||
->addOption( | |||||
'module', | |||||
null, | |||||
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, | |||||
'Module name to build class map for' | |||||
); | |||||
} | |||||
/** | |||||
* Executes the current command. | |||||
* | |||||
* @param InputInterface $input An InputInterface instance. | |||||
* @param OutputInterface $output An OutputInterface instance. | |||||
* | |||||
* @return null|integer | |||||
*/ | |||||
protected function execute(InputInterface $input, OutputInterface $output) | |||||
{ | |||||
$user_modules = $input->getOption('module'); | |||||
if ( $user_modules ) { | |||||
$modules_filter = array(); | |||||
$valid_modules = $this->getModules(); | |||||
foreach ( $user_modules as $module_name ) { | |||||
if ( !in_array($module_name, $valid_modules) ) { | |||||
throw new \InvalidArgumentException('Module "' . $module_name . '" not found or installed'); | |||||
} | |||||
$modules_filter[$module_name] = $this->Application->ModuleInfo[$module_name]; | |||||
} | |||||
} | |||||
else { | |||||
$modules_filter = null; | |||||
} | |||||
$table_rows = array(); | |||||
foreach ( ClassMapBuilder::createBuilders($modules_filter) as $class_map_builder ) { | |||||
$table_rows[] = $class_map_builder->build(); | |||||
} | |||||
// Needed because we aggregate class map from installed modules in unit config cache. | |||||
$this->Application->HandleEvent(new \kEvent('adm:OnResetParsedData')); | |||||
$table = $this->getHelper('table'); | |||||
$table | |||||
->setHeaders(array('Path', 'Scanned in', 'Parsed in')) | |||||
->setRows($table_rows); | |||||
$table->render($output); | |||||
return 0; | |||||
} | |||||
/** | |||||
* 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) | |||||
{ | |||||
if ( $optionName === 'module' ) { | |||||
return $this->getModules(); | |||||
} | |||||
return array(); | |||||
} | |||||
/** | |||||
* Returns possible module names. | |||||
* | |||||
* @return array | |||||
*/ | |||||
protected function getModules() | |||||
{ | |||||
$modules = array_keys($this->Application->ModuleInfo); | |||||
return array_diff($modules, array('In-Portal')); | |||||
} | |||||
/** | |||||
* 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) | |||||
{ | |||||
return array(); | |||||
} | |||||
} |