$message = sprintf( 'cURL error %s: %s (%s)', $ctx['errno'], $ctx['error'], 'see http://curl.haxx.se/libcurl/c/libcurl-errors.html' ); // Create a connection exception if it was a specific error code. $error = isset($connectionErrors[$easy->errno]) ? new ConnectException($message, $easy->request, null, $ctx) : new RequestException($message, $easy->request, $easy->response, null, $ctx); return \GuzzleHttp\Promise\rejection_for($error); } private function getDefaultConf(EasyHandle $easy) { $conf = [ '_headers' => $easy->request->getHeaders(),
if (empty($easy->options['_err_message']) && (!$easy->errno || $easy->errno == 65) ) { return self::retryFailedRewind($handler, $easy, $ctx); } return self::createRejection($easy, $ctx); } private static function createRejection(EasyHandle $easy, array $ctx) { static $connectionErrors = [ CURLE_OPERATION_TIMEOUTED => true,
) { if (isset($easy->options['on_stats'])) { self::invokeStats($easy); } if (!$easy->response || $easy->errno) { return self::finishError($handler, $easy, $factory); } // Return the response if it is present and there is no error. $factory->release($easy); // Rewind the body of the response if possible.
} $easy = $this->factory->create($request, $options); curl_exec($easy->handle); $easy->errno = curl_errno($easy->handle); return CurlFactory::finish($this, $easy, $this->factory); } }
callable $default, callable $sync ) { return function (RequestInterface $request, array $options) use ($default, $sync) { return empty($options[RequestOptions::SYNCHRONOUS]) ? $default($request, $options) : $sync($request, $options); }; } /** * Sends streaming requests to a streaming compatible handler while sending * all other requests to a default handler.
public static function wrapStreaming( callable $default, callable $streaming ) { return function (RequestInterface $request, array $options) use ($default, $streaming) { return empty($options['stream']) ? $default($request, $options) : $streaming($request, $options); }; } }
public function __invoke(RequestInterface $request, array $options) { $fn = $this->nextHandler; // Don't do anything if the request has no body. if ($request->getBody()->getSize() === 0) { return $fn($request, $options); } $modify = []; // Add a default content-type if possible. if (!$request->hasHeader('Content-Type')) {
*/ public static function cookies() { return function (callable $handler) { return function ($request, array $options) use ($handler) { if (empty($options['cookies'])) { return $handler($request, $options); } elseif (!($options['cookies'] instanceof CookieJarInterface)) { throw new \InvalidArgumentException('cookies must be an instance of GuzzleHttp\Cookie\CookieJarInterface'); } $cookieJar = $options['cookies']; $request = $cookieJar->withCookieHeader($request); return $handler($request, $options)
} if (empty($options['allow_redirects']['max'])) { return $fn($request, $options); } return $fn($request, $options) ->then(function (ResponseInterface $response) use ($request, $options) { return $this->checkRedirect($request, $options, $response); }); } /**
{ return function (callable $handler) { return function ($request, array $options) use ($handler) { if (empty($options['http_errors'])) { return $handler($request, $options); } return $handler($request, $options)->then( function (ResponseInterface $response) use ($request, $handler) { $code = $response->getStatusCode(); if ($code < 400) { return $response; } throw RequestException::create($request, $response);
* @param array $options */ public function __invoke(RequestInterface $request, array $options) { $handler = $this->resolve(); return $handler($request, $options); } /** * Dumps a string representation of the stack. * * @return string
} $request = $this->applyOptions($request, $options); $handler = $options['handler']; try { return Promise\promise_for($handler($request, $options)); } catch (\Exception $e) { return Promise\rejection_for($e); } } /**
$this->invalidBody(); } $request = new Psr7\Request($method, $uri, $headers, $body, $version); // Remove the option so that they are not doubly-applied. unset($options['headers'], $options['body'], $options['version']); return $this->transfer($request, $options); } public function request($method, $uri = '', array $options = []) { $options[RequestOptions::SYNCHRONOUS] = true; return $this->requestAsync($method, $uri, $options)->wait();
return $this->transfer($request, $options); } public function request($method, $uri = '', array $options = []) { $options[RequestOptions::SYNCHRONOUS] = true; return $this->requestAsync($method, $uri, $options)->wait(); } public function getConfig($option = null) { return $option === null ? $this->config
$uri = $args[0]; $opts = isset($args[1]) ? $args[1] : []; return substr($method, -5) === 'Async' ? $this->requestAsync(substr($method, 0, -5), $uri, $opts) : $this->request($method, $uri, $opts); } public function sendAsync(RequestInterface $request, array $options = []) { // Merge the base URI into the request URI if needed. $options = $this->prepareDefaults($options);
"timeout" => Settings::TIMEOUT_SEC ]); } protected function get($url, $query = []) { $response = $this->client->get($url, ["query" => $query]); return json_decode($response->getBody(), true); } protected function post($url, $data) { $response = $this->client->post($url, [
public function iplocate($ip, $kwargs = []) { $url = "iplocate/address"; $query = ["ip" => $ip]; $query = $query + $kwargs; $response = $this->get($url, $query); return $response["location"]; } public function suggest($name, $query, $count = Settings::SUGGESTION_COUNT, $kwargs = []) { $url = "suggest/$name";
{ return $this->profile->getVersions(); } public function iplocate($ip, $kwargs = []) { return $this->suggestions->iplocate($ip, $kwargs); } public function suggest($name, $query, $count = Settings::SUGGESTION_COUNT, $kwargs = []) { return $this->suggestions->suggest($name, $query, $count, $kwargs); }
public function initCity() { if (!$this->hasCity()) { $token = "887bf0294055e54fe5a5a731d586ae4c32e873c9"; $dadata = new \Dadata\DadataClient($token, null); $result = $dadata->iplocate($_SERVER['REMOTE_ADDR']); $cityDaData = (string)$result['data']['city']; if (Yii::$app->user->isGuest) { // $city = Yii::$app->ipgeobase->getLocation(); // $this->add($city['city']); $this->add($cityDaData);
if (($action->controller->id == 'lk' and ! Yii::$app->user->isGuest and Yii::$app->user->identity->userData->type_user == 2) or ( $action->controller->id == 'test') or ( $action->controller->id == 'video-lesson')) { Yii::$app->params['typeHeader'] = 'shop'; } Yii::$app->city->initCity(); if (!parent::beforeAction($action)) { return false; } return true; }
break; } } $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules
$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); if ($oldController !== null) { Yii::$app->controller = $oldController; } return $result; }
$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();
require __DIR__ . '/../../common/config/main.php', require __DIR__ . '/../../common/config/main-local.php', require __DIR__ . '/../config/main.php', require __DIR__ . '/../config/main-local.php' ); (new yii\web\Application($config))->run();
$_GET = [ 'id' => 147, ];