Pimcore\Tool::getHttpData PHP Метод

getHttpData() публичный статический Метод

public static getHttpData ( $url, array $paramsGet = [], array $paramsPost = [] ) : boolean | string
$url
$paramsGet array
$paramsPost array
Результат boolean | string
    public static function getHttpData($url, $paramsGet = [], $paramsPost = [])
    {
        $client = self::getHttpClient();
        $client->setUri($url);
        $requestType = \Zend_Http_Client::GET;
        if (is_array($paramsGet) && count($paramsGet) > 0) {
            foreach ($paramsGet as $key => $value) {
                $client->setParameterGet($key, $value);
            }
        }
        if (is_array($paramsPost) && count($paramsPost) > 0) {
            foreach ($paramsPost as $key => $value) {
                $client->setParameterPost($key, $value);
            }
            $requestType = \Zend_Http_Client::POST;
        }
        try {
            $response = $client->request($requestType);
            if ($response->isSuccessful()) {
                return $response->getBody();
            }
        } catch (\Exception $e) {
        }
        return false;
    }

Usage Example

Пример #1
0
 /**
  * @param $imagePath
  * @param array $options
  * @return $this|bool|self
  */
 public function load($imagePath, $options = [])
 {
     // support image URLs
     if (preg_match("@^https?://@", $imagePath)) {
         $tmpFilename = "imagick_auto_download_" . md5($imagePath) . "." . File::getFileExtension($imagePath);
         $tmpFilePath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $tmpFilename;
         $this->tmpFiles[] = $tmpFilePath;
         File::put($tmpFilePath, \Pimcore\Tool::getHttpData($imagePath));
         $imagePath = $tmpFilePath;
     }
     if ($this->resource) {
         unset($this->resource);
         $this->resource = null;
     }
     try {
         $i = new \Imagick();
         $this->imagePath = $imagePath;
         if (method_exists($i, "setcolorspace")) {
             $i->setcolorspace(\Imagick::COLORSPACE_SRGB);
         }
         $i->setBackgroundColor(new \ImagickPixel('transparent'));
         //set .png transparent (print)
         if (isset($options["resolution"])) {
             // set the resolution to 2000x2000 for known vector formats
             // otherwise this will cause problems with eg. cropPercent in the image editable (select specific area)
             // maybe there's a better solution but for now this fixes the problem
             $i->setResolution($options["resolution"]["x"], $options["resolution"]["y"]);
         }
         $imagePathLoad = $imagePath;
         if (!defined("HHVM_VERSION")) {
             $imagePathLoad .= "[0]";
             // not supported by HHVM implementation - selects the first layer/page in layered/pages file formats
         }
         if (!$i->readImage($imagePathLoad) || !filesize($imagePath)) {
             return false;
         }
         $this->resource = $i;
         // this is because of HHVM which has problems with $this->resource->readImage();
         // set dimensions
         $dimensions = $this->getDimensions();
         $this->setWidth($dimensions["width"]);
         $this->setHeight($dimensions["height"]);
         // check if image can have alpha channel
         if (!$this->reinitializing) {
             $alphaChannel = $i->getImageAlphaChannel();
             if ($alphaChannel) {
                 $this->setIsAlphaPossible(true);
             }
         }
         $this->setColorspaceToRGB();
     } catch (\Exception $e) {
         \Logger::error("Unable to load image: " . $imagePath);
         \Logger::error($e);
         return false;
     }
     $this->setModified(false);
     return $this;
 }
All Usage Examples Of Pimcore\Tool::getHttpData