Beispiel #1
1
 function fetch_img($url)
 {
     $response = ClientStatic::get($url);
     if ($response->isSuccess()) {
         return $response->getBody();
     }
     return;
 }
Beispiel #2
0
 /**
  * Test POST with header Content-Type
  */
 public function testHttpPostContentType()
 {
     $response = HTTPClient::post($this->baseuri . 'testPostData.php', array('foo' => 'bar'), array('Content-Type' => Client::ENC_URLENCODED));
     $this->assertTrue($response->isSuccess());
     $this->assertContains('foo', $response->getBody());
     $this->assertContains('bar', $response->getBody());
 }
 public static function getStudentsByMst(&$response, array $getParam = array(), array $additionalHeaders = array())
 {
     $view_url = "http://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}" . APP_NAME . "core/modules/attendance/getStudents/";
     $headers = self::initHeaders($additionalHeaders);
     $response = json_decode(ClientStatic::get($view_url, $getParam, $headers)->getContent(), true);
     if (isset($response['status']) || !isset($response)) {
         return false;
     }
     return true;
 }
 /**
  * @return \Zend\Paginator\Paginator
  */
 public function read()
 {
     $results = [];
     $getResults = function ($offset = null, $itemCountPerPage = null) use(&$results) {
         if (empty($results)) {
             $client = ClientStatic::get($this->getUrl(), ['offset' => $offset, 'limit' => $itemCountPerPage]);
             $results = json_decode($client->getBody(), true);
         }
         return $results;
     };
     $adapter = new Callback(function ($offset, $itemCountPerPage) use($getResults) {
         return $getResults($offset, $itemCountPerPage)['data'];
     }, function () use($getResults) {
         return $getResults()['total'];
     });
     return new Paginator($adapter);
 }
Beispiel #5
0
 public function testGetResources()
 {
     $response = ClientStatic::get(self::HOST . '/resources', [], ['Accept' => 'application/hal+json']);
     echo Json::prettyPrint($response->getBody());
 }
Beispiel #6
0
 /**
  * リンク元にアクセスして自サイトへのアドレスが存在するかのチェック
  * @return boolean
  */
 private function is_not_valid_referer()
 {
     static $condition;
     // 本来は正規化されたアドレスでチェックするべきだろうが、
     // めんどうだからスクリプトのアドレスを含むかでチェック
     // global $vars;
     // $script = get_page_absuri(isset($vars['page']) ? $vars['page'] : '');
     if (empty($condition)) {
         $parse_url = Router::get_script_uri();
         $condition = $parse_url['host'] . $parse_url['path'];
         // QueryStringは評価しない。
     }
     $response = ClientStatic::get($this->referer);
     if (!$response->isSuccess()) {
         return true;
     }
     $dom = new Query($response->getBody());
     $results = $dom->execute('a[href=^"' . $condition . '"]');
     foreach ($results as $element) {
         // hrefがhttpから始まるaタグを走査
         if (preg_match('/' . $condition . '/i', $element->href) !== 0) {
             return false;
             break;
         }
     }
     return true;
 }