/** * @return HttpUrl **/ protected function processPath(HttpRequest $request) { if ($request->hasServerVar('REQUEST_URI')) { $path = $this->getPath(HttpUrl::create()->parse($request->getServerVar('REQUEST_URI'))); } else { throw new RouterException('Cannot resolve path'); } return $path; }
public function store($file, $desiredName) { if (!$this->uploadUrl) { throw new UnsupportedMethodException('Don`t know how to store file!'); } $sendRequest = HttpRequest::create()->setMethod(HttpMethod::post())->setUrl(HttpUrl::create()->parse($this->uploadUrl)); $options = array_merge($this->uploadOptions, array($this->uploadFieldName => '@' . $file)); $curl = CurlHttpClient::create()->setOption(CURLOPT_POSTFIELDS, $options); $upload = function () use($curl, $sendRequest) { $resp = $curl->send($sendRequest); return $resp; }; $resp = $this->tryToDo($upload, "Tried to upload file but something happened: %s"); return $resp->getBody(); }
protected function unlink($file) { $sendRequest = HttpRequest::create()->setMethod(HttpMethod::delete())->setUrl(HttpUrl::create()->parse($this->getUploadLink($file))); /** @var CurlHttpResponse $resp */ $curl = CurlHttpClient::create()->setOption(CURLOPT_CUSTOMREQUEST, "DELETE")->setOption(CURLOPT_TIMEOUT, 25); if (is_array($this->uploadOptions) && isset($this->uploadOptions['userpwd'])) { $curl->setOption(CURLOPT_HTTPAUTH, CURLAUTH_ANY)->setOption(CURLOPT_USERPWD, $this->uploadOptions['userpwd']); } $delete = function () use($curl, $sendRequest) { $response = $curl->send($sendRequest); $status = $response->getStatus()->getId(); if ($status < 200 || $status >= 400) { throw new MissingElementException("Got HTTP response code {$status}"); } }; $this->tryToDo($delete, "File ({$file}) was not deleted, reason: %s"); return true; }
/** * check_authentication mode request **/ private function checkAuthentication(array $parameters, $manager = null) { $credentials = new OpenIdCredentials(HttpUrl::create()->parse($parameters['openid.identity']), $this->httpClient); $request = HttpRequest::create()->setMethod(HttpMethod::post())->setUrl($credentials->getServer()); if (isset($parameters['openid.invalidate_handle']) && $manager) { $request->setPostVar('openid.invalidate_handle', $parameters['openid.invalidate_handle']); } foreach (explode(',', $parameters['openid.signed']) as $key) { $key = 'openid.' . $key; $request->setPostVar($key, $parameters[$key]); } $request->setPostVar('openid.mode', 'check_authentication')->setPostVar('openid.assoc_handle', $parameters['openid.assoc_handle'])->setPostVar('openid.sig', $parameters['openid.sig'])->setPostVar('openid.signed', $parameters['openid.signed']); $response = $this->httpClient->send($request); if ($response->getStatus()->getId() != HttpStatus::CODE_200) { throw new OpenIdException('bad response code from server'); } $result = $this->parseKeyValueFormat($response->getBody()); if (!isset($result['is_valid']) || $result['is_valid'] !== 'true' && $result['is_valid'] !== 'false') { throw new OpenIdException('strange response given'); } if ($result['is_valid'] === 'true') { if (isset($result['invalidate_handle']) && $manager) { $manager->purgeByHandle($result['invalidate_handle']); } return true; } elseif ($result['is_valid'] === 'false') { return false; } }
protected function httpStat($url) { $result = array(); try { $sendRequest = HttpRequest::create()->setMethod(HttpMethod::get())->setUrl(HttpUrl::create()->parse($url)); $res = CurlHttpClient::create()->setOption(CURLOPT_RETURNTRANSFER, true)->setOption(CURLOPT_NOBODY, true)->send($sendRequest); $result['mime'] = $res->getHeader('content-type'); $result['size'] = $res->getHeader('content-length'); } catch (Exception $e) { } return $result; }
public function toValue(ProtoDAO $dao = null, $array, $prefix = null) { $raw = $array[$prefix . $this->columnName]; if ($this->type == 'binary') { return DBPool::getByDao($dao)->getDialect()->unquoteBinary($raw); } if ($this->className == 'HttpUrl') { return HttpUrl::create()->parse($raw); } if ($this->type === 'json' || $this->type === 'jsonb') { return json_decode($raw, true); //associative array instead of object } if (!$this->identifier && $this->generic && $this->className) { return call_user_func([$this->className, 'create'], $raw); } elseif (!$this->identifier && $this->className) { // BOVM: prevents segfault on >=php-5.2.5 Assert::classExists($this->className); if (!is_subclass_of($this->className, Enumeration::class) && !is_subclass_of($this->className, Enum::class) && !is_subclass_of($this->className, Registry::class)) { $remoteDao = call_user_func([$this->className, 'dao']); $joinPrefix = $remoteDao->getJoinPrefix($this->columnName, $prefix); $joined = $this->strategyId == FetchStrategy::JOIN || isset($array[$joinPrefix . $remoteDao->getIdName()]); if ($joined) { return $remoteDao->makeObject($array, $joinPrefix); } else { // will be fetched later // by AbstractProtoClass::fetchEncapsulants $object = new $this->className(); $object->setId($raw); return $object; } } else { return new $this->className($raw); } } // veeeeery "special" handling, by tradition. // MySQL returns 0/1, others - t/f if ($this->type == 'boolean') { return (bool) strtr($raw, ['f' => null]); } return $raw; }
public function poorReference($url) { Assert::isNotNull($this->base, 'set base url first'); $parsedUrl = HttpUrl::create()->parse($url); return $this->base->transform($parsedUrl); }
protected function loadXRDS($url) { $response = $this->httpClient->send(HttpRequest::create()->setHeaderVar('Accept', self::HEADER_ACCEPT)->setMethod(HttpMethod::get())->setUrl(HttpUrl::create()->parse($url))); if ($response->getStatus()->getId() != 200) { throw new OpenIdException('can\'t fetch document'); } $this->parseXRDS($response->getBody()); return $this; }
public function apply($value) { $url = HttpUrl::create()->parse($value)->ensureAbsolute()->normalize(); return $url->toString(); }