コード例 #1
0
 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();
 }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: HttpRequest.php プロジェクト: justthefish/hesper
 /**
  * @return HttpRequest
  **/
 public static function createFromGlobals()
 {
     $request = static::create()->setGet($_GET)->setPost($_POST)->setServer($_SERVER)->setCookie($_COOKIE)->setFiles($_FILES);
     if (isset($_SESSION)) {
         $request->setSession($_SESSION);
     }
     foreach ($_SERVER as $name => $value) {
         if (strpos($name, 'HTTP_') === 0) {
             $name = str_replace('_', '-', substr($name, 5));
             $request->setHeaderVar($name, $value);
         }
     }
     if ($request->hasServerVar('CONTENT_TYPE') && $request->getServerVar('CONTENT_TYPE') !== 'application/x-www-form-urlencoded') {
         $request->setBody(file_get_contents('php://input'));
     }
     $request->setMethod(HttpMethod::createByName($request->getServerVar('REQUEST_METHOD')));
     return $request;
 }
コード例 #4
0
ファイル: OpenIdConsumer.php プロジェクト: justthefish/hesper
 /**
  * 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;
     }
 }
コード例 #5
0
ファイル: StorageEngine.php プロジェクト: justthefish/hesper
 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;
 }
コード例 #6
0
 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;
 }