예제 #1
1
 function fetch_img($url)
 {
     $response = ClientStatic::get($url);
     if ($response->isSuccess()) {
         return $response->getBody();
     }
     return;
 }
예제 #2
0
 /**
  * Test GET with query as params
  */
 public function testHttpMultiGetWithParam()
 {
     $response = HTTPClient::get($this->baseuri . 'testGetData.php', array('foo' => 'bar'));
     $this->assertTrue($response->isSuccess());
     $this->assertContains('foo', $response->getBody());
     $this->assertContains('bar', $response->getBody());
 }
예제 #3
0
 /**
  * Test GET with body
  */
 public function testHttpGetWithBody()
 {
     $getBody = 'baz';
     $response = HTTPClient::get($this->baseuri . 'testRawGetData.php', array('foo' => 'bar'), array(), $getBody);
     $this->assertTrue($response->isSuccess());
     $this->assertContains('foo', $response->getBody());
     $this->assertContains('bar', $response->getBody());
     $this->assertContains($getBody, $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;
 }
예제 #5
0
 /**
  * @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);
 }
예제 #6
0
 public function testGetResources()
 {
     $response = ClientStatic::get(self::HOST . '/resources', [], ['Accept' => 'application/hal+json']);
     echo Json::prettyPrint($response->getBody());
 }
예제 #7
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;
 }