You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.4 KiB
59 lines
1.4 KiB
<?php
|
|
/**
|
|
* @copyright NetMonsters <team@netmonsters.ru>
|
|
* @link http://netmonsters.ru
|
|
* @package Majestic
|
|
* @subpackage App
|
|
* @since 27.06.12
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* @desc CliController (run cli_class, end profiler)
|
|
* @author Aleksandr Demidov
|
|
*/
|
|
class CliController
|
|
{
|
|
/**
|
|
* @var CliController
|
|
*/
|
|
protected static $instance;
|
|
|
|
protected function __construct()
|
|
{
|
|
ErrorHandler::init();
|
|
}
|
|
|
|
/**
|
|
* @static
|
|
* @return CliController
|
|
*/
|
|
public static function getInstance()
|
|
{
|
|
if (!isset(self::$instance)) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* @param iCli $cli_class
|
|
* @throws ErrorException
|
|
*/
|
|
public function execute($cli_class)
|
|
{
|
|
try {
|
|
if (!in_array('iCli', class_implements($cli_class))) {
|
|
throw new ErrorException('Runner "' . get_class($cli_class) . '" need implement of "iCli" interface.');
|
|
}
|
|
$cli_class->run();
|
|
if (Config::get('PROFILER')) {
|
|
echo PHP_EOL . Profiler::getInstance()->getCli();
|
|
}
|
|
} catch (Exception $e) {
|
|
$stderr = fopen('php://stderr', 'w');
|
|
fputs($stderr, PHP_EOL . 'Error: ' . $e->getMessage() . PHP_EOL);
|
|
fputs($stderr, PHP_EOL . 'Stack trace: ' . PHP_EOL . $e->getTraceAsString() . PHP_EOL);
|
|
}
|
|
}
|
|
}
|