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.
61 lines
1.5 KiB
61 lines
1.5 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 $error_stream;
|
|
|
|
protected function __construct()
|
|
{
|
|
ErrorHandler::init();
|
|
$this->error_stream = fopen('php://stderr', 'rw');
|
|
}
|
|
|
|
/**
|
|
* @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) {
|
|
fwrite($this->error_stream, PHP_EOL . 'Error: ' . $e->getMessage() . PHP_EOL);
|
|
fwrite($this->error_stream, PHP_EOL . 'Stack trace: ' . PHP_EOL . $e->getTraceAsString() . PHP_EOL);
|
|
}
|
|
}
|
|
}
|