コード例 #1
0
ファイル: App.php プロジェクト: rickogden/zf2
 /**
  * This method enables logging of requests by changing the
  * Zend_Http_Client_Adapter used for performing the requests.
  * NOTE: This will not work if you have customized the adapter
  * already to use a proxy server or other interface.
  *
  * @param $logfile The logfile to use when logging the requests
  */
 public function enableRequestDebugLogging($logfile)
 {
     $this->_httpClient->setConfig(array(
         'adapter' => 'Zend\GData\App\LoggingHttpClientAdapterSocket',
         'logfile' => $logfile
         ));
 }
コード例 #2
0
ファイル: StaticTest.php プロジェクト: navtis/xerxes-pazpar2
 /**
  * Test sending cookie header with raw value
  *
  * @group fix-double-encoding-problem-about-cookie-value
  */
 public function testRawCookiesInRequestHeaders()
 {
     $this->_client->setConfig(array('encodecookies' => false));
     $this->_client->addCookie('foo', 'bar=baz');
     $this->_client->send();
     $cookieValue = 'Cookie: foo=bar=baz';
     $this->assertContains($cookieValue, $this->_client->getLastRawRequest(), 'Request is expected to contain the entire cookie "keyname=raw_value"');
 }
コード例 #3
0
ファイル: PrivateDataTest.php プロジェクト: rafalwrzeszcz/zf2
 /**
  *
  * @return void
  */
 public function setUp()
 {
     if (!constant('TESTS_ZEND_SERVICE_DELICIOUS_ENABLED')) {
         $this->markTestSkipped('\\Zend\\Service\\Delicious online tests are not enabled');
     }
     $httpClient = new Http\Client();
     $httpClient->setConfig(array('useragent' => 'Zend\\Service\\Delicious - Unit tests/0.1', 'keepalive' => true));
     RestClient\RestClient::setDefaultHttpClient($httpClient);
     $this->_delicious = new Delicious\Delicious(self::TEST_UNAME, self::TEST_PASS);
 }
コード例 #4
0
ファイル: StaticTest.php プロジェクト: nevvermind/zf2
 /**
  * Check we get an exception if there's an error in the socket
  *
  */
 public function testSocketErrorException()
 {
     $this->setExpectedException('Zend\\Http\\Client\\Adapter\\Exception\\RuntimeException', 'Unable to Connect to tcp://255.255.255.255:80');
     // Try to connect to an invalid host
     $this->_client->setUri('http://255.255.255.255');
     // Reduce timeout to 3 seconds to avoid waiting
     $this->_client->setConfig(array('timeout' => 3));
     // This call should cause an exception
     $this->_client->send();
 }
コード例 #5
0
ファイル: CommonHttpTests.php プロジェクト: rafalwrzeszcz/zf2
 /**
  * Test we can properly redirect to a relative path
  *
  */
 public function testRelativePathRedirect()
 {
     $this->client->setUri($this->baseuri . 'testRelativeRedirections.php');
     $this->client->setParameterGet(array('redirect' => 'relpath'));
     $this->client->setConfig(array('maxredirects' => 1));
     // Set the new expected URI
     $uri = clone $this->client->getUri();
     $uri->setPath(rtrim(dirname($uri->getPath()), '/') . '/path/to/fake/file.ext');
     $uri = $uri->__toString();
     $res = $this->client->send();
     $this->assertEquals("{$uri}?redirect=relpath", $this->client->getUri()->toString(), "The new location is not as expected: {$this->client->getUri()->toString()}");
 }
コード例 #6
0
ファイル: SlideShare.php プロジェクト: bradley-holt/zf2
 /**
  * Returns the instance of the Zend\Http\Client which will be used. Creates an instance
  * of Zend\Http\Client if no previous client was set.
  *
  * @return Zend\Http\Client The HTTP client which will be used
  */
 public function getHttpClient()
 {
     if (!$this->httpclient instanceof Http\Client) {
         $client = new Http\Client();
         $client->setConfig(array('maxredirects' => 2, 'timeout' => 5));
         $this->setHttpClient($client);
     }
     $this->httpclient->resetParameters();
     return $this->httpclient;
 }
コード例 #7
0
ファイル: Result.php プロジェクト: navtis/xerxes
 /**
  * Fetch item and holding records from an ILS for this record
  */
 public function fetchHoldings()
 {
     $xerxes_record = $this->getXerxesRecord();
     $id = $xerxes_record->getRecordID();
     // id from the record
     $cache_id = $xerxes_record->getSource() . "." . $id;
     // to identify this in the cache
     $url = $this->config->getConfig("LOOKUP");
     // url to availability server
     // mark that we've checked holdings either way
     $this->holdings->checked = true;
     // no holdings source defined or somehow id's are blank
     if ($xerxes_record->hasPhysicalHoldings() == false || $url == "" || $id == "") {
         return null;
     }
     // get the data
     $url .= "?action=status&id=" . urlencode($id);
     // @todo this needs to be gotten from a factory or something
     $client = new Client();
     $client->setUri($url);
     $client->setConfig(array('timeout' => 5));
     $data = $client->send()->getBody();
     // echo $url; exit;
     // no data, what's up with that?
     if ($data == "") {
         throw new \Exception("could not connect to availability server");
     }
     // response is (currently) an array of json objects
     $results = json_decode($data);
     // parse the response
     if (is_array($results)) {
         if (count($results) > 0) {
             // now just slot them into our item object
             foreach ($results as $holding) {
                 $is_holding = property_exists($holding, "holding");
                 if ($is_holding == true) {
                     $item = new Holding();
                     $this->holdings->addHolding($item);
                 } else {
                     $item = new Item();
                     $this->holdings->addItem($item);
                 }
                 foreach ($holding as $property => $value) {
                     $item->setProperty($property, $value);
                 }
             }
         }
     }
     // cache it for the future
     // @todo: zend\cache
     $cache = new Cache();
     $expiry = $this->config->getConfig("HOLDINGS_CACHE_EXPIRY", false, 2 * 60 * 60);
     // expiry set for two hours
     $expiry += time();
     $cache->set($cache_id, serialize($this->holdings), $expiry);
     return null;
 }