* @since Version 1.0 */ class cSysConsole { private static $instance = null; private $outputLines = array(); const C_TYPE = 't'; const C_FUNCTION = 'f'; const C_LINE_DATA = 'l'; const C_RESPONSE_DATA = 'r'; const C_TYPES_JS = 'JS'; const C_TYPES_PHP = 'PHP'; private static $vCommands = array( 'expand_sql' => array( self::C_TYPE => 'JS', // Type of group JS - javascript handles action self::C_FUNCTION => 'expandAllSqlQueries' // Javascript call function ), 'collapse_sql' => array( self::C_TYPE => 'JS', // Type of group JS - javascript handles action self::C_FUNCTION => 'collapseAllSqlQueries' // Javascript call function ), 'math' => array( self::C_TYPE => 'PHP', // Type of group PHP - php script handles action self::C_FUNCTION => 'parseBaseMathProblem' // php call function ), ); public function __construct(){ } public static function getInstance(){ // Singleton initiation if (self::$instance == null) { self::$instance = new self(); } return self::$instance; } /** * Function to add output line * * @author Mareks Keišs * @category CMS * @param array $lineData - line data to show * @param string $type - line type * @return void */ public function addOutputLine($lineData = array(), $type = ''){ if(!!$lineData){ $microTime = explode(' ', microtime()); $microTime[0] *= 1000000; $this->outputLines[] = array( 't' => "{$microTime[0]}:{$microTime[1]}", 'd' => $lineData, 'c' => $type ); } } /** * Function to get output line data * * @author Mareks Keišs * @category CMS * @return array - new line data */ public function getLineData(){ if(!!$this->outputLines){ foreach($this->outputLines as &$v){ // Format each line $v['t'] = explode(':', $v['t']); $v['t'] = date('H:i:s', $v['t'][1]) . " {$v['t'][0]}"; } } return $this->outputLines; } public function p(){ pr($this->outputLines); } /** * Function to handle console command & send answers * * @author Mareks Keišs * @category CMS * @return array - new line data */ public function handleConsoleCommand($sCommand){ if(isset(self::$vCommands[$sCommand])){ $c = self::$vCommands[$sCommand]; $oView = new cView($this); if($c[self::C_TYPE] == self::C_TYPES_JS){ if(!empty($c[self::C_FUNCTION])){ $this->addOutputLine(array( "{$c[self::C_TYPE]} : {$sCommand} - calling custom js function '{$c[self::C_FUNCTION]}'" )); $oView->CONSOLE_DATA = $this->getLineData(); cJSON::sendOk(array(self::C_TYPE => $c[self::C_TYPE], self::C_FUNCTION => $c[self::C_FUNCTION], self::C_LINE_DATA => $oView->genHelperView('console/console-line.tpl'))); } } } return $this->outputLines; } }