本文整理汇总了PHP中Pimcore\Tool::getHttpClient方法的典型用法代码示例。如果您正苦于以下问题:PHP Tool::getHttpClient方法的具体用法?PHP Tool::getHttpClient怎么用?PHP Tool::getHttpClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore\Tool
的用法示例。
在下文中一共展示了Tool::getHttpClient方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* @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;
}
示例2: __construct
public function __construct()
{
$this->logger = Logging::getInstance();
$this->client = \Pimcore\Tool::getHttpClient();
$overrideConfig = new \Zend_Config(array("maxredirects" => 5));
$this->client->setConfig($overrideConfig);
}
示例3: proxyAction
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;
}
示例4: getAnalyticsMetadata
/**
* @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: getAssetById
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;
}
}
}