Skip to content

Commit

Permalink
added ManualResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed May 31, 2017
1 parent c309679 commit 3bd52a1
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions src/ManualResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* ActiveRecord for API
*
* @link https://github.com/hiqdev/yii2-hiart
* @package yii2-hiart
* @license BSD-3-Clause
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\hiart\curl;

use hiqdev\hiart\AbstractRequest;
use hiqdev\hiart\AbstractResponse;
use hiqdev\hiart\ResponseErrorException;

/**
* For creating response manually.
*/
class ManualResponse extends AbstractResponse
{
/**
* @var mixed
*/
protected $data;

/**
* @var array[]
*/
protected $headers = [];

/**
* @var string
*/
protected $statusCode;

/**
* @var string
*/
protected $reasonPhrase;

/**
* @param AbstractRequest $request
* @param mixed $data
* @param array $headers
* @param string $statusCode
* @param string $reasonPhrase
*/
public function __construct(RequestInterface $request, $data, array $headers = [], $statusCode = null, $reasonPhrase = null)
{
$this->request = $request;
$this->data = $data;
$this->headers = $headers;
$this->statusCode = $statusCode;
$this->reasonPhrase = $reasonPhrase;
}

/**
* @return mixed
*/
public function getData()
{
return $this->data;
}

/**
* @return mixed
*/
public function getRawData()
{
return $this->data;
}

/**
* @param string $name the header name
* @return array|null
*/
public function getHeader($name)
{
return isset($this->headers[strtolower($name)]) ? $this->headers[strtolower($name)] : null;
}

/**
* {@inheritdoc}
*/
public function getStatusCode()
{
return $this->statusCode;
}

/**
* {@inheritdoc}
*/
public function getReasonPhrase()
{
return $this->reasonPhrase;
}

/**
* Returns array of all headers.
* Key - Header name
* Value - array of header values. For example:.
*
* ```php
* ['Location' => ['http://example.com'], 'Expires' => ['Thu, 01 Jan 1970 00:00:00 GMT']]
* @return array
*/
public function getHeaders()
{
return $this->headers;
}
}

0 comments on commit 3bd52a1

Please sign in to comment.