<commit_before><?php
namespace Pupcake\Plugin\Express;

use Pupcake;

class Response extends Pupcake\Object
{
  private $plugin;
  private $app_instance;
  private $route;
  private $req;
  private $in_inner_route;

  public function __construct($plugin, $route, $req)
  {
    $this->plugin = $plugin;
    $this->app_instance = $plugin->getAppInstance();
    $this->route = $route;
    $this->req = $req;
    $this->in_inner_route = false;
    $plugin->trigger("pupcake.plugin.express.response.create", "", array("response" => $this));
  }

  public function getAppInstance()
  {
    return $this->app_instance;
  }

  public function send($output)
  {
    if($this->in_inner_route){
      $this->route->storageSet('inner_route_output', $output); 
    }
    else{
      $this->route->storageSet('output', $output); 
    }
  }

  public function contentType($content_type)
  {
    $this->app_instance->setHeader("Content-type: $content_type");
    return $this;
  }

  public function redirect($uri)
  {
    $this->plugin->getAppInstance()->redirect($uri);
  }

  public function forward($request_type, $uri, $request_params = array())
  {
    return $this->app_instance->forward($request_type, $uri, $request_params);
  }

  public function toRoute($request_type, $route_pattern, $params)
  {
    $this->in_inner_route = true;
    $router = $this->plugin->getAppInstance()->getRouter();
    $route = $router->getRoute($request_type, $route_pattern);
    $route->setParams($params);
    $this->req->setRoute($route);
    $route->execute(array($this->req, $this));<commit_msg>add sendJSON method to response object<commit_after><?php
namespace Pupcake\Plugin\Express;

use Pupcake;

class Response extends Pupcake\Object
{
  private $plugin;
  private $app_instance;
  private $route;
  private $req;
  private $in_inner_route;

  public function __construct($plugin, $route, $req)
  {
    $this->plugin = $plugin;
    $this->app_instance = $plugin->getAppInstance();
    $this->route = $route;
    $this->req = $req;
    $this->in_inner_route = false;
    $plugin->trigger("pupcake.plugin.express.response.create", "", array("response" => $this));
  }

  public function getAppInstance()
  {
    return $this->app_instance;
  }

  public function send($output)
  {
    if($this->in_inner_route){
      $this->route->storageSet('inner_route_output', $output); 
    }
    else{
      $this->route->storageSet('output', $output); 
    }
  }

  public function sendJSON($data = array())
  {
    $this->contentType("application/json")->send(json_encode($data));
  }

  public function contentType($content_type)
  {
    $this->app_instance->setHeader("Content-type: $content_type");
    return $this;
  }

  public function redirect($uri)
  {
    $this->plugin->getAppInstance()->redirect($uri);
  }

  public function forward($request_type, $uri, $request_params = array())
  {
    return $this->app_instance->forward($request_type, $uri, $request_params);
  }

  public function toRoute($request_type, $route_pattern, $params)
  {
    $this->in_inner_route = true;
    $router = $this->plugin->getAppInstance()->getRouter();
    $route = $router->getRoute($request_type, $route_pattern);
    $route->setParams($params);
    $this->req->setRoute($route);
    $route->execute(array($this->req, $this));
{'fraction_non_alphanumeric': 0.1662621359223301, 'fraction_numerical': 0.0, 'mean_word_length': 4.103715170278638, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7544129', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1064, 'n_words': 185}