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 route($server) { $action = 'task\\Adapter\\' . $this->ctrl; $class = Factory::getInstance($action); if (!$class instanceof Task) { throw new \Exception("ctrl error"); } $class->setParams($this->data); $class->setServer($server); $result = $exception = null; try { $task = $this->task; if (\method_exists($class, $task)) { $result = $class->{$task}(); } else { throw new \Exception("no method {$task}"); } } catch (\Exception $e) { $exception = $e; } if ($exception !== null) { throw $exception; } if (null === $result) { return; } return $result; }
public static function getInstance($adapter = 'Base') { if ('Base' == $adapter) { $class_name = __NAMESPACE__ . "\\{$adapter}Parser"; } else { $class_name = __NAMESPACE__ . "\\Adapter\\{$adapter}Parser"; } return CFactory::getInstance($class_name); }
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 getInstance($adapter = 'Http') { $className = __NAMESPACE__ . "\\{$adapter}"; return CFactory::getInstance($className); }
public static function getInstance($adapter = 'Swoole', $config) { $className = __NAMESPACE__ . "\\{$adapter}"; return CFactory::getInstance($className, $config); }