<commit_before><?php

require_once "SparkCore/Util.php";
require_once "SparkCore/Framework.php";
require_once "SparkCore/Request.php";
require_once "SparkCore/Response.php";
require_once "SparkCore/FilterChain.php";

use SparkCore\Request,
	SparkCore\Response,
	SparkCore\FilterChain,
	SparkCore\Framework;

function SparkCore()
{
    static $instance;

    if (null === $instance) {
        $instance = new SparkCore;
    }
    return $instance;
}

class SparkCore
{
    /** @var FilterChain */
	protected $stack;

	/** @var FilterChain */
	protected $errorHandlers;

	/** @var Request */
	protected $request;

	/** @var Response */
	protected $response;
	
	function __construct()
	{
		$this->stack = new FilterChain;
		$this->errorHandlers = new FilterChain;
	}
    
    function run($framework = null)
    {
        $request  = $this->getRequest();
		$response = $this->getResponse();

        if (null !== $framework) {
            if (is_string($framework) and !empty($framework)) {
                $framework = new $framework;
            }
            if (!$framework instanceof Framework) {
                throw new \InvalidArgumentException("Initializers must implement the"
                    . " SparkCore\Framework Interface");
            }
            $framework->setUp($this);
        }
        
        if (0 === count($this->stack)) {
            trigger_error("Stack is empty, no handlers set", E_USER_NOTICE);
        }

		ob_start();
		try {
			$returnValues = $this->stack->filterUntil(
			    $request, $response, array($request, "isDispatched")
			);
		} catch (\Exception $e) {
			$response->setException($e);
			$this->errorHandlers->filter($request, $response);
		}
	    $response->append(ob_get_clean())->send();
		return $returnValues;
    }
	
	function __invoke()
	{
		return $this->run();
	}

    function prepend($middleware)
	{
	    if (func_num_args() > 1) {
            foreach (func_get_args() as $middleware) {
                $this->stack->prepend($middleware);<commit_msg>Added some docblocks<commit_after><?php

require_once "SparkCore/Util.php";
require_once "SparkCore/Framework.php";
require_once "SparkCore/Request.php";
require_once "SparkCore/Response.php";
require_once "SparkCore/FilterChain.php";

use SparkCore\Request,
	SparkCore\Response,
	SparkCore\FilterChain,
	SparkCore\Framework;

function SparkCore()
{
    static $instance;

    if (null === $instance) {
        $instance = new SparkCore;
    }
    return $instance;
}

class SparkCore
{
    /** @var FilterChain */
	protected $stack;

	/** @var FilterChain */
	protected $errorHandlers;

	/** @var Request */
	protected $request;

	/** @var Response */
	protected $response;

	function __construct()
	{
		$this->stack = new FilterChain;
		$this->errorHandlers = new FilterChain;
	}

    /**
     * Runs the Request Handlers
     *
     * @param string|Framework $framework Class or object which is used to bootstrap
     *                                    the Request Handler stack
     * @return ReturnValues
     */
    function run($framework = null)
    {
        $request  = $this->getRequest();
		$response = $this->getResponse();

        if (null !== $framework) {
            if (is_string($framework) and !empty($framework)) {
                $framework = new $framework;
            }
            if (!$framework instanceof Framework) {
                throw new \InvalidArgumentException("Initializers must implement the"
                    . " SparkCore\Framework Interface");
            }
            $framework->setUp($this);
        }
        
        if (0 === count($this->stack)) {
            trigger_error("Stack is empty, no handlers set", E_USER_NOTICE);
        }

		ob_start();
		try {
			$returnValues = $this->stack->filterUntil(
			    $request, $response, array($request, "isDispatched")
			);
		} catch (\Exception $e) {
			$response->setException($e);
			$this->errorHandlers->filter($request, $response);
		}
	    $response->append(ob_get_clean())->send();
		return $returnValues;
    }
	
    function prepend($middleware)
	{
	    if (func_num_args() > 1) {
            foreach (func_get_args() as $middleware) {
                $this->stack->prepend($middleware);
{'fraction_non_alphanumeric': 0.13817663817663817, 'fraction_numerical': 0.000949667616334283, 'mean_word_length': 2.5885860306643953, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7440748', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1239, 'n_words': 268}