|
|
@ -0,0 +1,59 @@ |
|
|
|
<?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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |