/** * @param string $command * @return mixed * @throws Exception on error */ private function parseResponse($command) { if (($line = fgets($this->_socket)) === false) { throw new SocketException("Failed to read from socket.\nRedis command was: " . $command); } $type = $line[0]; $line = mb_substr($line, 1, -2, '8bit'); switch ($type) { case '+': // Status reply if ($line === 'OK' || $line === 'PONG') { return true; } else { return $line;
if ($written === false) { throw new SocketException("Failed to write to socket.\nRedis command was: " . $command); } if ($written !== ($len = mb_strlen($command, '8bit'))) { throw new SocketException("Failed to write to socket. $written of $len bytes written.\nRedis command was: " . $command); } return $this->parseResponse(implode(' ', $params)); } /** * @param string $command * @return mixed * @throws Exception on error
$this->close(); $this->open(); $this->retries = $retries; } } } return $this->sendCommandInternal($command, $params); } /** * Sends RAW command string to the server. * @throws SocketException on connection error. */
); if ($this->_socket) { if ($this->dataTimeout !== null) { stream_set_timeout($this->_socket, $timeout = (int) $this->dataTimeout, (int) (($this->dataTimeout - $timeout) * 1000000)); } if ($this->password !== null) { $this->executeCommand('AUTH', [$this->password]); } if ($this->database !== null) { $this->executeCommand('SELECT', [$this->database]); } $this->initConnection(); } else {
* See [redis protocol description](http://redis.io/topics/protocol) * for details on the mentioned reply types. * @throws Exception for commands that return [error reply](http://redis.io/topics/protocol#error-reply). */ public function executeCommand($name, $params = []) { $this->open(); $params = array_merge(explode(' ', $name), $params); $command = ''; $paramsCount = 0; foreach ($params as $arg) { if ($arg === null) {
/** * @inheritdoc */ protected function getValue($key) { return $this->getReplica()->executeCommand('GET', [$key]); } /** * @inheritdoc */ protected function getValues($keys)
* @return mixed the value stored in cache, false if the value is not in the cache, expired, * or the dependency associated with the cached data has changed. */ public function get($key) { $key = $this->buildKey($key); $value = $this->getValue($key); if ($value === false || $this->serializer === false) { return $value; } elseif ($this->serializer === null) { $value = unserialize($value); } else { $value = call_user_func($this->serializer[1], $value);
{ $cache = $this->ensureCache(); if (!$cache) { return false; } return $cache->get([$this->cacheKey, $this->ruleConfig, $ruleDeclarations]); } /** * Parses the user request. * @param Request $request the request component * @return array|bool the route and the associated parameters. The latter is always empty
* Please refer to [[rules]] for the acceptable rule formats. * @return UrlRuleInterface[] the rule objects built from the given rule declarations * @throws InvalidConfigException if a rule declaration is invalid */ protected function buildRules($ruleDeclarations) { $builtRules = $this->getBuiltRulesFromCache($ruleDeclarations); if ($builtRules !== false) { return $builtRules; } $builtRules = []; $verbs = 'GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS';
if (!$this->enablePrettyUrl) { return; } if (!empty($this->rules)) { $this->rules = $this->buildRules($this->rules); } } /** * Adds additional URL rules. *
*/ 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.
$config = $this->resolveDependencies($config); if (!empty($dependencies) && $reflection->implementsInterface('yii\base\Configurable')) { // set $config as the last parameter (existing one will be overwritten) $dependencies[count($dependencies) - 1] = $config; return $reflection->newInstanceArgs($dependencies); } $object = $reflection->newInstanceArgs($dependencies); foreach ($config as $name => $value) { $object->$name = $value; }
$class = $class->id; } 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));
return static::$container->get($class, $params, $type); } if (isset($type['class'])) { $class = $type['class']; unset($type['class']); return static::$container->get($class, $params, $type); } throw new InvalidConfigException('Object configuration must be an array containing a "class" or "__class" element.'); } private static $_logger;
if (isset($this->_definitions[$id])) { $definition = $this->_definitions[$id]; if (is_object($definition) && !$definition instanceof Closure) { return $this->_components[$id] = $definition; } return $this->_components[$id] = Yii::createObject($definition); } elseif ($throwException) { throw new InvalidConfigException("Unknown component ID: $id"); } return null; }
* Since version 2.0.13, if a component isn't defined in the module, it will be looked up in the parent module. * The parent module may be the application. */ public function get($id, $throwException = true) { if (!isset($this->module)) { return parent::get($id, $throwException); } $component = parent::get($id, false); if ($component === null) { $component = $this->module->get($id, $throwException); }
/** * Returns the URL manager for this application. * @return \yii\web\UrlManager the URL manager for this application. */ public function getUrlManager() { return $this->get('urlManager'); } /** * Returns the internationalization (i18n) component. * @return \yii\i18n\I18N the internationalization application component. */
// delay attaching event handler to the view component after it is fully configured $app->on(Application::EVENT_BEFORE_REQUEST, function () use ($app) { $app->getView()->on(View::EVENT_END_BODY, [$this, 'renderToolbar']); $app->getResponse()->on(Response::EVENT_AFTER_PREPARE, [$this, 'setDebugHeaders']); }); $app->getUrlManager()->addRules([ [ 'class' => 'yii\web\UrlRule', 'route' => $this->id, 'pattern' => $this->id, 'suffix' => false ],
if (!isset($component)) { $component = Yii::createObject($mixed); } if ($component instanceof BootstrapInterface) { Yii::debug('Bootstrap with ' . get_class($component) . '::bootstrap()', __METHOD__); $component->bootstrap($this); } else { Yii::debug('Bootstrap with ' . get_class($component), __METHOD__); } } }
protected function bootstrap() { $request = $this->getRequest(); Yii::setAlias('@webroot', dirname($request->getScriptFile())); Yii::setAlias('@web', $request->getBaseUrl()); parent::bootstrap(); } /** * Handles the specified request. * @param Request $request the request to be handled * @return Response the resulting response
/** * {@inheritdoc} */ public function init() { $this->state = self::STATE_INIT; $this->bootstrap(); } /** * Initializes extensions and executes bootstrap components. * This method is called by [[init()]] after the application has been fully configured. * If you override this method, make sure you also call the parent implementation.
*/ 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.
$this->state = self::STATE_BEGIN; $this->preInit($config); $this->registerErrorHandler($config); Component::__construct($config); } /** * Pre-initializes the application. * This method is called at the beginning of the application constructor. * It initializes several important application properties.
) { header("HTTP/1.1 301 Moved Permanently"); header("Location: $url" . "/"); exit(); } (new yii\web\Application($config))->run();