Overview

Namespaces

  • Baguette
    • Application
    • Response
    • Serializer
    • Session
  • Overview
  • Namespace
  • Class
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 
<?php

namespace Baguette\Response;

use Baguette;

/**
 * Serialized data Response class
 *
 * @author    USAMI Kenta <tadsan@zonu.me>
 * @copyright 2016 Baguette HQ
 * @license   http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
 */
final class SerializedResponse implements ResponseInterface
{
    /** @var array */
    public $value;
    /** @var \Baguette\Serializer\SerializerInterface */
    public $serializer;
    /** @var int */
    private $status_code;

    /**
     * @param array $value
     * @param \Baguette\Serializer\SerializerInterface $serializer
     * @param int   $status_code
     */
    public function __construct(array $value, Baguette\Serializer\SerializerInterface $serializer, $status_code = 200)
    {
        $this->value = $value;
        $this->serializer = $serializer;
        $this->status_code = $status_code;
    }

    /**
     * @return array[]
     */
    public function getResponseHeaders()
    {
        return [
            'content-type' => [$this->serializer->getContentType()],
        ];
    }

    /**
     * @return int
     */
    public function getHttpStatusCode()
    {
        return $this->status_code;
    }

    /**
     * @return string
     */
    public function render(Baguette\Application $_)
    {
        return $this->serializer->serialize($this->value);
    }
}
ξ ^ω^)ξ < Baguette Not Framework API documentation generated by ApiGen