コード例 #1
0
ファイル: Route.php プロジェクト: jinchunguang/swoole-doc
 public static function route($server, $socket)
 {
     $action = Config::get('ctrl_path', 'ctrl') . '\\' . $server['ctrl'];
     $class = new $action($socket);
     $before = $class->_before();
     $view = $exception = null;
     if ($before) {
         try {
             $method = $server['method'];
             if (\method_exists($class, $method)) {
                 $view = $class->{$method}($server);
             } else {
                 throw new \Exception("no method {$method}");
             }
         } catch (\Exception $e) {
             $exception = $e;
         }
     }
     $class->_after();
     if ($exception !== null) {
         throw $exception;
     }
     if (null === $view) {
         return null;
     }
     return json_encode($view, JSON_UNESCAPED_UNICODE);
 }
コード例 #2
0
ファイル: Route.php プロジェクト: hytzxd/swoole-doc
 public static function route($server)
 {
     $action = Config::get('ctrl_path', 'ctrl') . '\\' . $server->getCtrl();
     $class = Factory::getInstance($action);
     if (!$class instanceof IController) {
         throw new \Exception("ctrl error");
     }
     $class->setServer($server);
     $before = $class->_before();
     $view = $exception = null;
     if ($before) {
         try {
             $method = $server->getMethod();
             if (\method_exists($class, $method)) {
                 $view = $class->{$method}();
             } else {
                 throw new \Exception("no method {$method}");
             }
         } catch (\Exception $e) {
             $exception = $e;
         }
     }
     $class->_after();
     if ($exception !== null) {
         throw $exception;
     }
     if (null === $view) {
         return;
     }
     return $server->display($view);
 }
コード例 #3
0
ファイル: Chat.php プロジェクト: hytzxd/swoole-doc
 public function __construct()
 {
     if (empty($this->redis)) {
         $this->redis = ZRedis::getInstance(ZConfig::get('redis'));
         $db = ZConfig::getField('redis', 'db', 0);
         if (!empty($db)) {
             $this->redis->select($db);
         }
     }
 }
コード例 #4
0
ファイル: Socket.php プロジェクト: hytzxd/swoole-doc
 public function run()
 {
     $config = Config::get('socket');
     if (empty($config)) {
         throw new \Exception("socket config empty");
     }
     $socket = SFactory::getInstance($config['socket_adapter'], $config);
     $client = CFactory::getInstance($config['client_class']);
     $socket->setClient($client);
     $socket->run();
 }
コード例 #5
0
ファイル: Entrance.php プロジェクト: hytzxd/swoole-doc
 public static function run($rootPath)
 {
     if (!defined('DS')) {
         define('DS', DIRECTORY_SEPARATOR);
     }
     self::$rootPath = $rootPath;
     self::$configPath = self::$rootPath . DS . 'config' . DS . $_SERVER['argv'][1];
     \spl_autoload_register(__CLASS__ . '::autoLoader');
     \set_exception_handler(__CLASS__ . '::exceptionHandler');
     Config::load(self::$configPath);
     $serverMode = Config::get('server_mode', 'Socket');
     $server = SFactory::getInstance($serverMode);
     $server->run();
 }