2014-11-20 17:22:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Application_Common_HTTPHelper
|
|
|
|
{
|
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* Returns start and end DateTime vars from given
|
|
|
|
* HTTP Request object.
|
2014-11-20 17:22:53 +01:00
|
|
|
*
|
|
|
|
* @param Request
|
2021-10-11 16:10:47 +02:00
|
|
|
* @param mixed $request
|
|
|
|
*
|
2014-11-20 17:22:53 +01:00
|
|
|
* @return array(start DateTime, end DateTime)
|
|
|
|
*/
|
|
|
|
public static function getStartEndFromRequest($request)
|
|
|
|
{
|
|
|
|
return Application_Common_DateHelper::getStartEnd(
|
2021-10-11 16:10:47 +02:00
|
|
|
$request->getParam('start', null),
|
|
|
|
$request->getParam('end', null),
|
|
|
|
$request->getParam('timezone', null)
|
2014-11-20 17:22:53 +01:00
|
|
|
);
|
|
|
|
}
|
2015-02-20 20:27:16 +01:00
|
|
|
|
2015-11-24 19:36:54 +01:00
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* Execute a cURL POST.
|
2015-11-24 19:36:54 +01:00
|
|
|
*
|
2021-10-11 16:10:47 +02:00
|
|
|
* @param string $url the URL to POST to
|
|
|
|
* @param string[] $userPwd array of user args of the form ['user', 'pwd']
|
|
|
|
* @param array $formData array of form data kwargs
|
2015-11-24 19:36:54 +01:00
|
|
|
*
|
|
|
|
* @return mixed the cURL result
|
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function doPost($url, $userPwd, $formData)
|
|
|
|
{
|
|
|
|
$params = '';
|
|
|
|
foreach ($formData as $key => $value) {
|
|
|
|
$params .= $key . '=' . $value . '&';
|
2015-11-24 19:36:54 +01:00
|
|
|
}
|
|
|
|
rtrim($params, '&');
|
|
|
|
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
2021-10-11 16:10:47 +02:00
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
2015-11-24 19:36:54 +01:00
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
|
|
|
curl_setopt($ch, CURLOPT_USERPWD, implode(':', $userPwd));
|
|
|
|
$result = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2015-11-24 19:36:54 +01:00
|
|
|
return $result;
|
|
|
|
}
|
2014-11-20 17:22:53 +01:00
|
|
|
}
|
2015-06-05 17:55:06 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
class ZendActionHttpException extends Exception
|
|
|
|
{
|
2015-06-05 17:55:06 +02:00
|
|
|
/**
|
2023-08-15 18:28:18 +02:00
|
|
|
* @param int $statusCode
|
|
|
|
* @param string $message
|
|
|
|
* @param int $code
|
2015-06-05 17:55:06 +02:00
|
|
|
*
|
|
|
|
* @throws Zend_Controller_Response_Exception
|
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
public function __construct(
|
|
|
|
Zend_Controller_Action $action,
|
|
|
|
$statusCode,
|
|
|
|
$message,
|
|
|
|
$code = 0,
|
2024-04-13 14:36:31 +02:00
|
|
|
?Exception $previous = null
|
2021-10-11 16:10:47 +02:00
|
|
|
) {
|
|
|
|
Logging::error('Error in action ' . $action->getRequest()->getActionName()
|
2022-04-17 14:38:49 +02:00
|
|
|
. " with status code {$statusCode}: {$message}");
|
2015-06-05 17:55:06 +02:00
|
|
|
$action->getResponse()
|
|
|
|
->setHttpResponseCode($statusCode)
|
2022-01-23 19:15:55 +01:00
|
|
|
->appendBody($message);
|
2015-06-05 17:55:06 +02:00
|
|
|
parent::__construct($message, $code, $previous);
|
|
|
|
}
|
2017-09-28 11:23:32 +02:00
|
|
|
}
|