<commit_before><?php
/**
 * Created by PhpStorm.
 * User: janhuang
 * Date: 15/6/2
 * Time: 下午7:01
 * Github: https://www.github.com/janhuang 
 * Coding: https://www.coding.net/janhuang
 * SegmentFault: http://segmentfault.com/u/janhuang
 * Blog: http://segmentfault.com/blog/janhuang
 * Gmail: <EMAIL>
 */

namespace Kernel\Events;

use Dobee\Http\JsonResponse;
use Dobee\Http\Response;

/**
 * Class RestEvent
 *
 * @package Kernel\Events
 */
class RestEvent extends EventAbstract
{
    /**
     * @var string
     */
    protected $version = 'v1';

    /**
     * @var string
     */
    protected $title = '';

    /**
     * @var string
     */
    protected $accept = 'application/vnd.%s.%s+json';

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

    /**
     *
     */
    public function __construct()
    {
        $this->headers = [
            'Accept'    => sprintf($this->getAccept(), $this->getTitle(), $this->getVersion()),
            'Version'   => $this->getVersion(),
        ];
    }

    /**
     * @return string
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * @param string $title
     * @return $this
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

    /**
     * @param array $responseData
     * @param int   $status
     * @param array $headers
     * @return JsonResponse
     */
    public function responseJson(array $responseData, $status  = Response::HTTP_OK, array $headers = array())
    {
        return new JsonResponse($responseData, $status, array_merge(
            $this->headers,
            $headers
        ));<commit_msg>add allow origin<commit_after><?php
/**
 * Created by PhpStorm.
 * User: janhuang
 * Date: 15/6/2
 * Time: 下午7:01
 * Github: https://www.github.com/janhuang 
 * Coding: https://www.coding.net/janhuang
 * SegmentFault: http://segmentfault.com/u/janhuang
 * Blog: http://segmentfault.com/blog/janhuang
 * Gmail: <EMAIL>
 */

namespace Kernel\Events;

use Dobee\Http\JsonResponse;
use Dobee\Http\Response;

/**
 * Class RestEvent
 *
 * @package Kernel\Events
 */
class RestEvent extends EventAbstract
{
    /**
     * @var string
     */
    protected $version = 'v1';

    /**
     * @var string
     */
    protected $title = '';

    /**
     * @var string
     */
    protected $accept = 'application/vnd.%s.%s+json';

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

    protected $allowOrigin = null;

    /**
     *
     */
    public function __construct()
    {
        $this->headers = [
            'Accept'    => sprintf($this->getAccept(), $this->getTitle(), $this->getVersion()),
            'Version'   => $this->getVersion(),
            'X-' . $this->getTitle() . '-Media-Type' => $this->getTitle() . '.' . $this->getVersion(),
        ];
    }

    /**
     * @return null
     */
    public function getAllowOrigin()
    {
        return $this->allowOrigin;
    }

    /**
     * @param null $allowOrigin
     * @return $this
     */
    public function setAllowOrigin($allowOrigin)
    {
        $this->allowOrigin = $allowOrigin;

        return $this;
    }

    /**
     * @return string
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * @param string $title
     * @return $this
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

    /**
     * @param array $responseData
     * @param int   $status
     * @param array $headers
     * @return JsonResponse
     */
    public function responseJson(array $responseData, $status  = Response::HTTP_OK, array $headers = array())
    {
        if (null !== $this->getAllowOrigin()) {
            $headers = array_merge($headers, [
                'Access-Control-Allow-Origin' => $this->getAllowOrigin(),
            ]);
        }
        return new JsonResponse($responseData, $status, array_merge(
            $this->headers,
            $headers
        ));
{'fraction_non_alphanumeric': 0.15738678544914625, 'fraction_numerical': 0.003959415986142044, 'mean_word_length': 1.9503649635036497, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 34, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5262676', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1251, 'n_words': 252}