Skip to content

Commit

Permalink
Extended ResponseInterface by
Browse files Browse the repository at this point in the history
- adding unsetHeader(), setStatus(), getStatusCode() and getStatusMessage()
- setter-methods can now be used fluently
  • Loading branch information
sigma-z committed Oct 26, 2016
1 parent abaa6a8 commit 87bc640
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 7 deletions.
60 changes: 53 additions & 7 deletions src/Jentin/Mvc/Response/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function __construct($content = '')
* @param string $name
* @param string $value
* @param bool $replace
* @return $this
*/
public function setHeader($name, $value = '', $replace = true)
{
Expand All @@ -66,15 +67,18 @@ public function setHeader($name, $value = '', $replace = true)
else {
$this->headers[$name][] = $header;
}
return $this;
}


/**
* @param string $name
* @return $this
*/
public function unsetHeader($name)
{
unset($this->headers[$name]);
return $this;
}


Expand Down Expand Up @@ -119,10 +123,11 @@ public function getHeaderSent()
* sets content type
*
* @param string $contentType
* @return $this
*/
public function setContentType($contentType)
{
$this->setHeader('Content-Type', $contentType);
return $this->setHeader('Content-Type', $contentType);
}


Expand Down Expand Up @@ -155,18 +160,33 @@ public function sendHeaders($throwExceptionOnHeadersSent = true)


/**
* appends content
* sets body/content
*
* @param string $content
* @return $this
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}


/**
* appends body/content
*
* @param string $content
* @return $this
*/
public function appendContent($content)
{
$this->content .= $content;
return $this;
}


/**
* gets content
* gets body/content
*
* @return string
*/
Expand All @@ -177,26 +197,52 @@ public function getContent()


/**
* sets content
* alias of setContent()
*
* @param string $content
* @return $this
*/
public function setContent($content)
public function setBody($content)
{
$this->content = $content;
return $this->setContent($content);
}


/**
* alias of appendContent()
*
* @param string $content
* @return $this
*/
public function appendBody($content)
{
return $this->appendContent($content);
}


/**
* alias of getContent()
*
* @return string
*/
public function getBody()
{
return $this->getContent();
}


/**
* sets http response status
*
* @param integer $code
* @param int $code
* @param string $message
* @return $this
*/
public function setStatus($code, $message = '')
{
$this->statusCode = $code;
$this->statusMessage = $message;
return $this;
}


Expand Down
27 changes: 27 additions & 0 deletions src/Jentin/Mvc/Response/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ interface ResponseInterface
* @param string $name
* @param string $value
* @param bool $replace
* @return $this
*/
public function setHeader($name, $value = '', $replace = true);


/**
* @param $name
* @return $this
*/
public function unsetHeader($name);

/**
* gets header
*
Expand All @@ -38,6 +46,7 @@ public function getHeader($name, $default = null);
* append content
*
* @param string $content
* @return $this
*/
public function appendContent($content);

Expand All @@ -52,6 +61,7 @@ public function getContent();
* sets content
*
* @param string $content
* @return $this
*/
public function setContent($content);

Expand All @@ -65,4 +75,21 @@ public function sendHeaders();
*/
public function sendResponse();

/**
* @param int $code
* @param string $message
* @return $this
*/
public function setStatus($code, $message = '');

/**
* @return int
*/
public function getStatusCode();

/**
* @return string
*/
public function getStatusMessage();

}

0 comments on commit 87bc640

Please sign in to comment.