<?php

namespace Salesloo;

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

/**
 * Request action
 */
class Response extends \WP_HTTP_Response
{

    /**
     * ajax response
     *
     * @return void
     */
    public function json()
    {
        status_header($this->status);

        foreach ($this->headers as $key => $value) {
            $value = preg_replace('/\s+/', ' ', $value);
            header(sprintf('%s: %s', $key, $value));
        }

        echo json_encode($this->data);
        exit;
    }
}
