try { $zkServer = empty($zkServer) ? RpcConfig::getZooConfig() : $zkServer; PhpLibLog::info("ZookeeperComponent::getServer serverName:$serverName , zkServer:$zkServer"); $this->zk = new \Zookeeper($zkServer); $serverStr = $this->zk->getChildren("/" . $serverName); PhpLibLog::info("ZookeeperComponent::getServer getChildren success:".json_encode($serverStr)); } catch (Exception $e) { $msg = $e->getMessage(); PhpLibLog::emergency("ZookeeperComponent::getServer ZooException message:$msg"); Throw new ZooException('zookeeper exception:' .$msg); } if (empty($serverStr)) { PhpLibLog::emergency("ZookeeperComponent::getServer RPC service $serverName empty!"); Throw new RpcServiceNotFoundException("未发现RPC服务:" . $serverName . " !"); } //从服务列表中随机取一个 $randKey = array_rand($serverStr, 1);
*/ public function getServer($serverName, $zkServer = null) { $serverData = $this->getServerFromClient($serverName); if (empty($serverData)) { $serverData = $this->getServerFromPhpZk($serverName, $zkServer); } return $serverData; }
* 获取服务地址和端口号 * @return array * @throws \Exception */ protected function getServer() { return $this->zoo->getServer($this->zkServiceName); } /** * 获取连接对象 * @return TSocket */
* BasicService constructor. */ public function __construct() { PhpLibLog::info("zk服务名:" . $this->zkServiceName); $this->zoo = new ZookeeperService(); $this->server = $this->getServer(); $this->connectObj = $this->getConnectObj(); $this->transport = $this->getTransPort(); $this->protocol = $this->getProtocol(); $this->rpcClient = $this->setRpcClient(); $this->transport->open(); }
const LOGIN_STATUS_SUCCESS = 1; /** @var \vso\phplib\rpc\thrift\account\AccountServiceClient $accountRpcService */ private $accountRpcService; public function __construct() { $this->accountRpcService = new AccountService(); } public function loginStatus($username, $vso_token) { $params = [ 'appid' => Yii::$app->params['Api']['app_id'],
$dependencies = $this->resolveDependencies($dependencies, $reflection); if (!$reflection->isInstantiable()) { throw new NotInstantiableException($reflection->name); } if (empty($config)) { return $reflection->newInstanceArgs($dependencies); } $config = $this->resolveDependencies($config); if (!empty($dependencies) && $reflection->implementsInterface('yii\base\Configurable')) { // set $config as the last parameter (existing one will be overwritten)
public function get($class, $params = [], $config = []) { if (isset($this->_singletons[$class])) { // singleton return $this->_singletons[$class]; } elseif (!isset($this->_definitions[$class])) { return $this->build($class, $params, $config); } $definition = $this->_definitions[$class]; if (is_callable($definition, true)) { $params = $this->resolveDependencies($this->mergeParams($class, $params));
$config = array_merge($definition, $config); $params = $this->mergeParams($class, $params); if ($concrete === $class) { $object = $this->build($class, $params, $config); } else { $object = $this->get($concrete, $params, $config); } } elseif (is_object($definition)) { return $this->_singletons[$class] = $definition; } else { throw new InvalidConfigException('Unexpected object definition type: ' . gettype($definition)); }
} //获取用户登录信息 private function _get_user_login() { /** @var \frontend\modules\user\services\foundation\User $userService */ $userService = Yii::$container->get('User'); //验证登录用户信息 $userLoginInfo = $userService->userLoginStatus(); //获取登录用户信息 $this->_user = $userService->getUserInfo($userLoginInfo['username']); if (!$this->_user) { setcookie('vso_uid', null);
} //初始化方法 public function init() { parent::init(); $this->_get_user_login(); } //获取用户登录信息 private function _get_user_login() { /** @var \frontend\modules\user\services\foundation\User $userService */
*/ public function __construct($config = []) { if (!empty($config)) { Yii::configure($this, $config); } $this->init(); } /** * Initializes the object. * This method is invoked at the end of the constructor after the object is initialized with the * given configuration.
* @param array $config name-value pairs that will be used to initialize the object properties. */ public function __construct($id, $module, $config = []) { $this->id = $id; $this->module = $module; parent::__construct($config); } /** * Declares external actions for the controller. * * This method is meant to be overwritten to declare external actions for the controller.
$dependencies = $this->resolveDependencies($dependencies, $reflection); if (!$reflection->isInstantiable()) { throw new NotInstantiableException($reflection->name); } if (empty($config)) { return $reflection->newInstanceArgs($dependencies); } $config = $this->resolveDependencies($config); if (!empty($dependencies) && $reflection->implementsInterface('yii\base\Configurable')) { // set $config as the last parameter (existing one will be overwritten)
public function get($class, $params = [], $config = []) { if (isset($this->_singletons[$class])) { // singleton return $this->_singletons[$class]; } elseif (!isset($this->_definitions[$class])) { return $this->build($class, $params, $config); } $definition = $this->_definitions[$class]; if (is_callable($definition, true)) { $params = $this->resolveDependencies($this->mergeParams($class, $params));
* @throws InvalidConfigException if the configuration is invalid. * @see \yii\di\Container */ public static function createObject($type, array $params = []) { if (is_string($type)) { return static::$container->get($type, $params); } elseif (is_array($type) && isset($type['class'])) { $class = $type['class']; unset($type['class']); return static::$container->get($class, $params, $type); } elseif (is_callable($type, true)) { return static::$container->invoke($type, $params);
$className = ltrim($this->controllerNamespace . '\\' . str_replace('/', '\\', $prefix) . $className, '\\'); if (strpos($className, '-') !== false || !class_exists($className)) { return null; } if (is_subclass_of($className, 'yii\base\Controller')) { $controller = Yii::createObject($className, [$id, $this]); return get_class($controller) === $className ? $controller : null; } elseif (YII_DEBUG) { throw new InvalidConfigException('Controller class must extend from \\yii\\base\\Controller.'); } return null;
if (($pos = strrpos($route, '/')) !== false) { $id .= '/' . substr($route, 0, $pos); $route = substr($route, $pos + 1); } $controller = $this->createControllerByID($id); if ($controller === null && $route !== '') { $controller = $this->createControllerByID($id . '/' . $route); $route = ''; } return $controller === null ? false : [$controller, $route];
if (isset($this->controllerMap[$id])) { $controller = Yii::createObject($this->controllerMap[$id], [$id, $this]); return [$controller, $route]; } $module = $this->getModule($id); if ($module !== null) { return $module->createController($route); } if (($pos = strrpos($route, '/')) !== false) { $id .= '/' . substr($route, 0, $pos); $route = substr($route, $pos + 1); }
* @param array $params the parameters to be passed to the action * @return mixed the result of the action. * @throws InvalidRouteException if the requested route cannot be resolved into an action successfully. */ public function runAction($route, $params = []) { $parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params);
$params = $this->catchAll; unset($params[0]); } try { Yii::debug("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } $response = $this->getResponse(); if ($result !== null) {
{ try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
'views' => ['class' => 'task\libs\ViewsPanel'], ], ]; } $application = new yii\web\Application($config); $application->run();
$_GET = [ 'bn' => '3384338740259', ];