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); }
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); }
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); } } }
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(); }
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(); }