getHttpClient() public static method

public static getHttpClient ( string $type = "Zend_Http_Client", array $options = [] ) : Zend_Http_Client
$type string
$options array
return Zend_Http_Client
コード例 #1
1
 public function proxyAction()
 {
     if ($this->getParam("url")) {
         header("Content-Type: application/javascript");
         $client = Tool::getHttpClient();
         $client->setUri($this->getParam("url"));
         try {
             $response = $client->request(\Zend_Http_Client::GET);
             if ($response->isSuccessful()) {
                 echo $this->getParam("callback") . "(" . \Zend_Json::encode("data:" . $response->getHeader("Content-Type") . ";base64," . base64_encode($response->getBody())) . ");";
             } else {
                 throw new \Exception("Invalid response");
             }
         } catch (\Exception $e) {
             echo $this->getParam("callback") . "(" . \Zend_Json::encode("error:Application error") . ")";
         }
     }
     exit;
 }
コード例 #2
0
ファイル: Http.php プロジェクト: solverat/pimcore
 /**
  * @param null $options
  * @return bool|void
  * @throws \Exception
  * @throws \Zend_Http_Client_Exception
  */
 public function send($options = null)
 {
     $sourceFile = $this->getSourceFile();
     $destinationFile = $this->getDestinationFile();
     if (!$sourceFile) {
         throw new \Exception("No sourceFile provided.");
     }
     if (!$destinationFile) {
         throw new \Exception("No destinationFile provided.");
     }
     if (is_array($options)) {
         if ($options['overwrite'] == false && file_exists($destinationFile)) {
             throw new \Exception("Destination file : '" . $destinationFile . "' already exists.");
         }
     }
     if (!$this->getHttpClient()) {
         $httpClient = \Pimcore\Tool::getHttpClient(null, ['timeout' => 3600 * 60]);
     } else {
         $httpClient = $this->getHttpClient();
     }
     $httpClient->setUri($this->getSourceFile());
     $response = $httpClient->request();
     if ($response->isSuccessful()) {
         $data = $response->getBody();
         File::mkdir(dirname($destinationFile));
         $result = File::put($destinationFile, $data);
         if ($result === false) {
             throw new \Exception("Couldn't write destination file:" . $destinationFile);
         }
     } else {
         throw new \Exception("Couldn't download file:" . $sourceFile);
     }
     return true;
 }
コード例 #3
0
ファイル: Importer.php プロジェクト: ascertain/NGshop
 public function __construct()
 {
     $this->logger = Logging::getInstance();
     $this->client = \Pimcore\Tool::getHttpClient();
     $overrideConfig = new \Zend_Config(array("maxredirects" => 5));
     $this->client->setConfig($overrideConfig);
 }
コード例 #4
0
ファイル: Api.php プロジェクト: sfie/pimcore
 /**
  * @return mixed
  * @throws \Exception
  * @throws \Zend_Http_Client_Exception
  * @throws \Zend_Json_Exception
  */
 public static function getAnalyticsMetadata()
 {
     $client = \Pimcore\Tool::getHttpClient();
     $client->setUri(self::ANALYTICS_API_URL . 'metadata/ga/columns');
     $result = $client->request();
     return \Zend_Json::decode($result->getBody());
 }
コード例 #5
0
ファイル: RestClient.php プロジェクト: ChristophWurst/pimcore
 public function getAssetById($id, $decode = true, $idMapper = null, $light = false, $thumbnail = null, $tolerant = false, $protocol = "http://")
 {
     $uri = $this->buildEndpointUrl("asset/id/" . $id);
     if ($light) {
         $uri .= "&light=1";
     }
     $response = $this->doRequest($uri, "GET");
     $response = $response->data;
     if ($response->type == "folder") {
         $wsDocument = $this->fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Asset\\Folder\\In", $response);
         if (!$decode) {
             return $wsDocument;
         }
         $asset = new Asset\Folder();
         $wsDocument->reverseMap($asset, $this->getDisableMappingExceptions(), $idMapper);
         return $asset;
     } else {
         $wsDocument = $this->fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Asset\\File\\In", $response);
         if (!$decode) {
             return $wsDocument;
         }
         $type = $wsDocument->type;
         if (!empty($type)) {
             $type = "\\Pimcore\\Model\\Asset\\" . ucfirst($type);
             if (!Tool::classExists($type)) {
                 throw new Exception("Asset class " . $type . " does not exist");
             }
             $asset = new $type();
             $wsDocument->reverseMap($asset, $this->getDisableMappingExceptions(), $idMapper);
             if ($light) {
                 $client = Tool::getHttpClient();
                 $client->setMethod("GET");
                 $assetType = $asset->getType();
                 $data = null;
                 if ($assetType == "image" && strlen($thumbnail) > 0) {
                     // try to retrieve thumbnail first
                     // http://example.com/website/var/tmp/thumb_9__fancybox_thumb
                     $tmpPath = preg_replace("@^" . preg_quote(PIMCORE_DOCUMENT_ROOT, "@") . "@", "", PIMCORE_TEMPORARY_DIRECTORY);
                     $uri = $protocol . $this->getHost() . $tmpPath . "/thumb_" . $asset->getId() . "__" . $thumbnail;
                     $client->setUri($uri);
                     if ($this->getLoggingEnabled()) {
                         print "    =>" . $uri . "\n";
                     }
                     $result = $client->request();
                     if ($result->getStatus() == 200) {
                         $data = $result->getBody();
                     }
                     $mimeType = $result->getHeader("Content-Type");
                     $filename = $asset->getFilename();
                     switch ($mimeType) {
                         case "image/tiff":
                             $filename = $this->changeExtension($filename, "tiff");
                             break;
                         case "image/jpeg":
                             $filename = $this->changeExtension($filename, "jpg");
                             break;
                         case "image/gif":
                             $filename = $this->changeExtension($filename, "gif");
                             break;
                         case "image/png":
                             $filename = $this->changeExtension($filename, "png");
                             break;
                     }
                     \Logger::debug("mimeType: " . $mimeType);
                     $asset->setFilename($filename);
                 }
                 if (!$data) {
                     $path = $wsDocument->path;
                     $filename = $wsDocument->filename;
                     $uri = $protocol . $this->getHost() . "/website/var/assets" . $path . $filename;
                     $client->setUri($uri);
                     $result = $client->request();
                     if ($result->getStatus() != 200 && !$tolerant) {
                         throw new Exception("Could not retrieve asset");
                     }
                     $data = $result->getBody();
                 }
                 $asset->setData($data);
             }
             return $asset;
         }
     }
 }