Example #1
0
 /**
  * @param string $response
  */
 public function __construct($response)
 {
     parent::__construct($response);
     $this->name = $this->getResponseValue('name');
     $this->newMessages = $this->getResponseValue('new_messages');
     $this->oldMessages = $this->getResponseValue('old_messages');
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function __construct(\SimpleXMLElement $response)
 {
     parent::__construct($response);
     if (!empty($response->EndTime)) {
         $this->end_time = (string) $response->EndTime;
     }
 }
Example #3
0
    /**
     * Initializes the `Location` header.
     *
     * @param string $url URL to redirect to.
     * @param int $status Status code (default to {@link Status::FOUND}).
     * @param array $headers Additional headers.
     *
     * @throws \InvalidArgumentException if the provided status code is not a redirect.
     */
    public function __construct($url, $status = Status::FOUND, array $headers = [])
    {
        parent::__construct(function (Response $response) {
            $location = $response->location;
            $title = \ICanBoogie\escape($location);
            echo <<<EOT
<!DOCTYPE html>
<html>
<head>
\t<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\t<meta http-equiv="refresh" content="1;url={$location}" />

\t<title>Redirecting to {$title}</title>
</head>
<body>
\tRedirecting to <a href="{$location}">{$title}</a>.
</body>
</html>
EOT;
            // @codeCoverageIgnore
        }, $status, ['Location' => $url] + $headers);
        if (!$this->status->is_redirect) {
            throw new StatusCodeNotValid($this->status->code, "The HTTP status code is not a redirect: {$status}.");
        }
    }
Example #4
0
 /**
  * @param string $response
  */
 public function __construct($response)
 {
     parent::__construct($response);
     $this->context = $this->getResponseValue('context');
     $this->exten = $this->getResponseValue('exten');
     $this->priority = $this->getResponseValue('priority');
 }
Example #5
0
 /**
  * @param string $appName: the name of your app
  */
 public function __construct($appName)
 {
     parent::__construct();
     $this->appName = $appName;
     $this->data = array();
     $this->error = false;
 }
Example #6
0
 /**
  * Constructor.
  *
  * @param mixed $data    The response data
  * @param int   $status  The response status code
  * @param array $headers An array of response headers
  */
 public function __construct(array $data, $status = 200, $headers = array())
 {
     parent::__construct('', $status, $headers);
     $data = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
     $this->header->set('Content-Type', 'application/json; charset=utf-8;');
     $this->setContent($data);
 }
Example #7
0
 /**
  * Construct the Info object by parsing the XML.
  * @param xml_doc the DOM XML document
  * @exception if the response is not valid
  */
 public function __construct(\DOMDocument $xml_doc)
 {
     parent::__construct($xml_doc);
     $xpath = new \DOMXPath($xml_doc);
     $this->campaign_id = $xpath->evaluate('/response/campaign_id')->item(0)->nodeValue;
     $this->from_number = $xpath->evaluate('/response/from')->item(0)->nodeValue;
     $this->from_name = $xpath->evaluate('/response/from_name')->item(0)->nodeValue;
     $this->to_number = $xpath->evaluate('/response/to')->item(0)->nodeValue;
     $this->to_name = $xpath->evaluate('/response/to_name')->item(0)->nodeValue;
     $this->content_id = $xpath->evaluate('/response/content_id')->item(0)->nodeValue;
     $this->status = $xpath->evaluate('/response/status')->item(0)->nodeValue;
     $events = $xpath->query('/response/history/event');
     $this->history = array();
     foreach ($events as $event) {
         $timestamp = $event->getAttribute('timestamp');
         if (array_key_exists($timestamp, $this->history)) {
             array_push($this->history[$timestamp], $event->nodeValue);
         } else {
             $this->history[$timestamp] = array($event->nodeValue);
         }
     }
     if (!isset($this->campaign_id, $this->from_number, $this->from_name, $this->to_number, $this->to_name, $this->content_id, $this->content_id, $this->status, $this->status, $this->history)) {
         throw new \Exception("Invalid Lookup response.");
     }
 }
Example #8
0
 /**
  * @param string $response
  */
 public function __construct($response)
 {
     parent::__construct($response);
     $this->name = $this->response->name;
     $this->newMessages = $this->response->new_messages;
     $this->oldMessages = $this->response->old_messages;
 }
Example #9
0
 /**
  * @param string $response
  */
 public function __construct($response)
 {
     parent::__construct($response);
     $this->context = $this->response->context;
     $this->exten = $this->response->exten;
     $this->priority = $this->response->priority;
 }
 /**
  * Constructor
  *
  * @param string  $type
  * @param integer $tid
  * @param string  $action
  * @param string  $method
  */
 public function __construct($type, $tid, $action, $method)
 {
     parent::__construct($type);
     $this->tid = $tid;
     $this->action = $action;
     $this->method = $method;
 }
 /**
  * @inheritdoc
  */
 public function __construct(\SimpleXMLElement $response)
 {
     parent::__construct($response);
     if (!empty($response->SiteHostedPictureDetails->FullURL)) {
         $this->url = (string) $response->SiteHostedPictureDetails->FullURL;
     }
 }
Example #12
0
 /**
  * Constructor of StreamedResponse class.
  *
  * @param \Cygnite\Http\Responses\callable $callback
  * @param type                             $status
  * @param type                             $headers
  */
 public function __construct(callable $callback = null, $status = ResponseHeaders::HTTP_OK, $headers = [])
 {
     parent::__construct('', $status, $headers);
     if ($callback !== null) {
         $this->setCallback($callback);
     }
 }
 /**
  * @inheritdoc
  */
 public function __construct(\SimpleXMLElement $response)
 {
     parent::__construct($response);
     if (!empty($response->ItemID)) {
         $this->external_id = (string) $response->ItemID;
     }
 }
 /**
  * @param       $route
  * @param int   $status
  * @param array $headers
  */
 public function __construct($url, $status = 302, $headers = null)
 {
     parent::__construct(null, $status, $headers);
     $this->target = $url;
     $this->updateBody();
     $this->updateHeaders();
 }
Example #15
0
 /**
  * Constructs the object
  * @param \System\System\Interaction\Message The original message
  * @param \System\IO\File A file object, or the data to send
  */
 public function __construct(\System\System\Interaction\Message $originalMessage, $value)
 {
     if ($value instanceof \System\IO\File) {
         $value = @base64_encode($value->getContents());
     }
     parent::__construct($originalMessage, $value);
 }
Example #16
0
 /**
  * @param string $response
  */
 public function __construct($response)
 {
     parent::__construct($response);
     // @TODO This is not technically an optional parameter, but if the variable doesn't exist we have to
     // deal with it using try/catch, etc and that's annoying (for now)
     $this->value = property_exists($this->response, 'value') ? $this->response->value : null;
 }
 /**
  * Construct the Transactions object by parsing the XML.
  * @param xml_doc the DOM XML document
  * @exception if the response is not valid
  */
 public function __construct(\DOMDocument $xml_doc)
 {
     parent::__construct($xml_doc);
     $xpath = new \DOMXPath($xml_doc);
     $this->campaigns = array();
     $campaigns = $xpath->query('/response/campaign');
     foreach ($campaigns as $campaign) {
         $campaign_id = $campaign->getAttribute('id');
         if (!isset($campaign_id)) {
             throw new \Exception("An error occured while parsing the XML data for the TRANSACTIONS call");
         }
         if (in_array($campaign_id, $this->campaigns)) {
             exit;
         }
         $transactions = $xpath->query('./transaction', $campaign);
         $this->campaigns[$campaign_id]["name"] = $campaign->getAttribute('name');
         foreach ($transactions as $transaction) {
             $message_id = $xpath->evaluate('./@message_id', $transaction)->item(0)->nodeValue;
             if (!isset($message_id)) {
                 throw new \Exception("An error occured while parsing the XML data for the TRANSACTIONS call");
             }
             $this->campaigns[$campaign_id]["transactions"][$message_id]["hash"] = $xpath->evaluate('./@hash', $transaction)->item(0)->nodeValue;
             $this->campaigns[$campaign_id]["transactions"][$message_id]["datestamp"] = $xpath->evaluate('./@datestamp', $transaction)->item(0)->nodeValue;
             $this->campaigns[$campaign_id]["transactions"][$message_id]["to"] = $xpath->evaluate('./to', $transaction)->item(0)->nodeValue;
             $this->campaigns[$campaign_id]["transactions"][$message_id]["to_number"] = $xpath->evaluate('./to/@number', $transaction)->item(0)->nodeValue;
             $this->campaigns[$campaign_id]["transactions"][$message_id]["from"] = $xpath->evaluate('./from', $transaction)->item(0)->nodeValue;
             $this->campaigns[$campaign_id]["transactions"][$message_id]["from_number"] = $xpath->evaluate('./from/@number', $transaction)->item(0)->nodeValue;
             foreach ($this->campaigns[$campaign_id]["transactions"][$message_id] as $info) {
                 if (!isset($info)) {
                     throw new \Exception("An error occured while parsing the XML data for the TRANSACTIONS call");
                 }
             }
         }
     }
 }
 public function __construct($generator = null)
 {
     parent::__construct($generator);
     $this->setResponseCode(Response::HTTP_STATUS_CLIENT_ERROR_UNAUTHORIZED);
     $this->setResponseMessage("401 Unauthorized");
     $this->setContent("Sorry, you are not authorised to access this resource.");
 }
Example #19
0
 /**
  * @param \Sherlock\common\tmp\RollingCurl\Request $response
  */
 public function __construct($response)
 {
     parent::__construct($response);
     if (isset($this->responseData['found'])) {
         $this->ok = $this->responseData['found'];
     }
 }
Example #20
0
 public function __construct($allowOriginArg = '*', $allowHeadersArg = null, $allowMethodsArg = null, $maxAgeArg = 100)
 {
     $allowMethods = $allowMethodsArg ? $allowMethodsArg : 'GET,POST,PUT,PATCH,DELETE';
     $allowHeaders = $allowHeadersArg ? $allowHeadersArg : 'Content-Type,Accept';
     $headers = ['Access-Control-Allow-Origin' => $allowOriginArg, 'Access-Control-Allow-Methods' => $allowMethods, 'Access-Control-Allow-Headers' => $allowHeaders, 'Access-Control-Max-Age' => $maxAgeArg];
     parent::__construct('', 200, $headers);
 }
Example #21
0
 /**
  * Constructor.
  *
  * @param mixed   $callback A valid PHP callback
  * @param integer $status   The response status code
  * @param array   $headers  An array of response headers
  */
 public function __construct(callable $callback = NULL, $status = 200, $headers = [])
 {
     parent::__construct(NULL, $status, $headers);
     if (NULL !== $callback) {
         $this->setCallback($callback);
     }
     $this->streamed = FALSE;
 }
Example #22
0
 /**
  * Constructor.
  *
  * @param callable|null $callback A valid PHP callback or null to set it later
  * @param int           $status   The response status code
  * @param array         $headers  An array of response headers
  */
 public function __construct($callback = null, $status = 200, $headers = array())
 {
     parent::__construct(null, $status, $headers);
     if (null !== $callback) {
         $this->setCallback($callback);
     }
     $this->streamed = false;
 }
Example #23
0
 /**
  * Creates a redirect response so that it conforms to the rules defined for a redirect status code.
  *
  * @param string $url     The URL to redirect to
  * @param int    $status  The status code (302 by default)
  * @param array  $headers The headers (Location is always set to the given URL)
  *
  * @throws \InvalidArgumentException
  *
  * @see http://tools.ietf.org/html/rfc2616#section-10.3
  */
 public function __construct($url, $status = 302, $headers = array())
 {
     parent::__construct('', $status, $headers);
     $this->setTargetUrl($url);
     if (!$this->isRedirect()) {
         throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
     }
 }
Example #24
0
 /**
  * Constructor
  * @param mixed   $data    The response data
  * @param int     $status  The response status code
  * @param array   $headers An array of response headers
  */
 public function __construct($data = null, $status = 200)
 {
     parent::__construct('', $status);
     if ($data === null) {
         $data = array();
     }
     $this->setData($data);
 }
 /**
  * SignResponse constructor
  *
  * @param CancelRequest $request
  * @param mixed $data
  */
 public function __construct(CancelRequest $request, $data)
 {
     foreach ($data as $key => $value) {
         $data[strtolower($key)] = $value;
     }
     print_r($data);
     parent::__construct($request, $data);
 }
Example #26
0
 /**
  * @param string $response
  */
 public function __construct($response)
 {
     parent::__construct($response);
     $this->body = $this->getResponseValue('body');
     $this->from = $this->getResponseValue('from');
     $this->to = $this->getResponseValue('to');
     $this->variables = $this->getResponseValue('variables');
 }
Example #27
0
 /**
  * @param mixed $data    The response data
  * @param int   $status  The response status code
  * @param array $headers An array of response headers
  * @param bool  $json    If the data is already a JSON string
  */
 public function __construct($data = null, $status = 200, $headers = array(), $json = false)
 {
     parent::__construct('', $status, $headers);
     if (null === $data) {
         $data = new \ArrayObject();
     }
     $json ? $this->setJson($data) : $this->setData($data);
 }
Example #28
0
 /**
  * Constructor.
  *
  * @param mixed   $data    The response data
  * @param integer $status  The response status code
  * @param array   $headers An array of response headers
  */
 public function __construct($data = array(), $status = 200, $headers = array())
 {
     // root should be JSON object, not array
     if (is_array($data) && 0 === count($data)) {
         $data = new \ArrayObject();
     }
     parent::__construct(json_encode($data), $status, array_merge(array('Content-Type' => 'application/json'), $headers));
 }
Example #29
0
 public function __construct($charset = null)
 {
     parent::__construct();
     if (is_null($charset)) {
         $charset = self::DEFAULT_CHARSET;
     }
     parent::setContentType('text/plain', $charset);
 }
 /**
  * ExceptionResponse Constructor.
  * @param Exception $ex Exception to wrap.
  */
 public function __construct(Exception $ex, $inclStackTrace = true)
 {
     $data = array('exception_message' => $ex->getMessage(), 'exception_line' => $ex->getLine(), 'exception_file' => $ex->getFile());
     if ($inclStackTrace) {
         //$data['exception_trace'] = $ex->getTrace();
     }
     parent::__construct(Response::EXCEPTION, "Exception was caught.", $data);
 }