示例#1
0
文件: hush.php 项目: zhuxd1983/hush
<?php

/**
 * Ihush Console
 *
 * @author     James.Huang <*****@*****.**>
 * @license    http://www.apache.org/licenses/LICENSE-2.0
 * @version    $Id$
 */
define('__HUSH_CLI', 1);
require_once '../etc/global.config.php';
require_once 'Hush/Util.php';
////////////////////////////////////////////////////////////////////////////////////////////////////
// Constants definition
define('__MYSQL_IMPORT_TOOL', 'mysql');
define('__MYSQL_DUMPER_TOOL', 'mysqldump');
define('__MYSQL_IMPORT_COMMAND', __MYSQL_IMPORT_TOOL . ' {PARAMS} < {SQLFILE}');
define('__MYSQL_DUMPER_COMMAND', __MYSQL_DUMPER_TOOL . ' {PARAMS} --add-drop-database > {SQLFILE}');
////////////////////////////////////////////////////////////////////////////////////////////////////
// Main process
try {
    require_once 'Ihush/Cli.php';
    $cli = new Ihush_Cli();
    $cli->run();
} catch (Exception $e) {
    Hush_Util::trace($e);
    exit;
}
示例#2
0
 /**
  * Main dispatch process
  * @param array $app_dir
  * @param array $tpl_dir
  * @return unknown
  */
 public function dispatch($app_dir, $tpl_dir)
 {
     // app dispatch time
     if (Hush_Debug::showDebug('time')) {
         $this->start_time = microtime(true);
     }
     $this->_formatPath();
     $mapper_class = array();
     $mapper = $this->getMapper();
     /* MAIN PROCESS
      * Parse mapping file
      * Get mapped class
      */
     if ($mapper) {
         // prepare mapping
         $page_map = $mapper->getPageMap();
         $path_raw = $this->_request->getPathInfo();
         // map with raw url path
         if (array_key_exists($path_raw, $page_map)) {
             $mapper_class = $page_map[$path_raw];
         } elseif (array_key_exists($this->_path, $page_map)) {
             $mapper_class = $page_map[$this->_path];
         } else {
             foreach ((array) $page_map as $pattern => $class) {
                 // escape not REGEXP rules
                 if (strpos($pattern, '*') === false) {
                     continue;
                 }
                 // url matching
                 $pattern = preg_quote($pattern, '/');
                 $pattern = str_replace('\\*', '(.*?)', $pattern);
                 if (preg_match('/^' . $pattern . '$/i', $path_raw)) {
                     $mapper_class = $class;
                     break;
                 }
             }
         }
     }
     /* MAIN PROCESS
      * Get class & action name
      */
     if ($mapper_class) {
         // get mapped class
         $className = $this->getMapPageClass($mapper_class);
         // get action from mapping rule
         if (strpos($mapper_class, '*') === false) {
             $actionName = $this->getMapPageAction($mapper_class);
             // get action from url path
         } else {
             $actionName = $this->getDefaultPageAction();
         }
     } else {
         // get default class & action from url
         $className = $this->getDefaultPageClass();
         $actionName = $this->getDefaultPageAction();
     }
     /* MAIN PROCESS
      * Get action args
      */
     $actionArgs = $this->getActionArgs();
     /* MAIN PROCESS
      * Get template name
      */
     $tplName = $this->getTemplateName($className, $actionName);
     // app dispatch time
     if (Hush_Debug::showDebug('time')) {
         $this->end_time = microtime(true);
         $debug = Hush_Debug::getInstance();
         $debug->addWriter(new Hush_Debug_Writer_Html());
         $debug->debug($this->end_time - $this->start_time, '<span style="color:red">Hush App Dispatch Time >>></span>', Hush_Debug::INFO);
     }
     /* MAIN PROCESS
      * Enter page scope
      */
     try {
         // load page class
         @Zend_Loader::loadClass($className, $app_dir);
         // debug should be closed
         if (!class_exists($className)) {
             require_once 'Hush/App/Exception.php';
             throw new Hush_App_Exception('Can not find definition for class \'' . $className . '\'');
         }
         /* USE PAGE VIEW PROCESS
          * close auto-load for page view class
          */
         if (self::$pageViewClass) {
             require_once 'Hush/Page.php';
             Hush_Page::closeAutoLoad();
             // close page autoload mechanism
         }
         // create page
         $page = new $className();
         /* USE PAGE VIEW PROCESS
          * set template for page view class
          */
         if (self::$pageViewClass) {
             if ($tpl_dir) {
                 $page->setTemplateDir($tpl_dir);
             }
             $page->__prepare();
         }
         // set page's debug level
         if ($this->_debugLevel) {
             $page->setDebugLevel($this->_debugLevel);
         }
         // callback method implemented in page class
         if (method_exists($page, '__init')) {
             $page->__init();
         }
         // call page action method
         $page->{$actionName}($actionArgs);
         // callback method implemented in page class
         if (method_exists($page, '__done')) {
             $page->__done();
         }
         /* USE PAGE VIEW PROCESS
          * display template for page view class
          */
         if (self::$pageViewClass) {
             $page->__display($tplName);
         }
     } catch (Exception $e) {
         require_once 'Hush/Util.php';
         if (!$this->_debug) {
             Hush_Util::HTTPStatus(404);
             if (file_exists($this->_epage)) {
                 include_once $this->_epage;
                 exit;
             }
         } else {
             echo '<b>Dispatch Debug Info >>></b>' . "<br/>\n" . "<br/>\n";
             echo 'Class Name : ' . $className . "<br/>\n";
             echo 'Action Name : ' . $actionName . "<br/>\n";
             echo 'Action Args : ' . json_encode($actionArgs) . "<br/>\n";
             echo 'Template Name : ' . $tplName . "<br/>\n" . "<br/>\n";
             echo '<b>Dispatch Exception Info >>></b>' . "<br/>\n";
             Hush_Util::trace($e);
         }
     }
 }
示例#3
0
 /**
  * Print debug information
  * @param array $debugInfo
  * @param object $e
  */
 private function _printDebugInfo($debugInfo, $e)
 {
     echo '<b>Dispatch Debug Info >>></b>' . "<br/>\n" . "<br/>\n";
     echo 'Class Name : ' . $debugInfo['className'] . "<br/>\n";
     echo 'Action Name : ' . $debugInfo['actionName'] . "<br/>\n";
     echo 'Action Args : ' . json_encode($debugInfo['actionArgs']) . "<br/>\n";
     echo 'Template Name : ' . $debugInfo['templateName'] . "<br/>\n" . "<br/>\n";
     echo '<b>Dispatch Exception Info >>></b>' . "<br/>\n";
     Hush_Util::trace($e);
     exit;
 }
示例#4
0
 /**
  * Process main logic
  */
 public function run()
 {
     // init first time
     if (!$this->port) {
         $ports = $this->ports;
         $this->port = array_pop($ports);
         // current process's port (no shared)
         $this->ports = $ports;
         // store children process pid
         // do only once !!!
         $this->__pid(true);
     } else {
         echo "\n";
     }
     echo "Listening on : " . $this->port . "\n";
     try {
         // start socket message queue server
         $server = Pms_Adaptor::server(array('host' => $this->host, 'port' => $this->port));
         $server->daemon();
     } catch (Exception $e) {
         Hush_Util::trace($e);
         $server->close();
         $this->run();
     }
 }