<commit_before><?php //-->
/**
 * This file is part of the Cradle PHP Library.
 * (c) 2016-2018 Openovate Labs
 *
 * Copyright and license information can be found at LICENSE.txt
 * distributed with this package.
 */

namespace Cradle\Http;

use Throwable;

use Cradle\Http\Router\RouterTrait;
use Cradle\Http\Request\RequestTrait;
use Cradle\Http\Response\ResponseTrait;
use Cradle\Http\Dispatcher\DispatcherTrait;
use Cradle\Http\Middleware\PreProcessorTrait;
use Cradle\Http\Middleware\PostProcessorTrait;
use Cradle\Http\Middleware\ErrorProcessorTrait;

/**
 * You can optionally adopt these methods into an existing class
 *
 * @vendor   Cradle
 * @package  Http
 * @author   <NAME> <<EMAIL>>
 * @standard PSR-2
 */
trait HttpTrait
{
    use DispatcherTrait,
        PreProcessorTrait,
        PostProcessorTrait,
        ErrorProcessorTrait,
        RequestTrait,
        ResponseTrait,
        RouterTrait;

    /**
     * Prepares the event and calls the preprocessors
     *
     * @return bool Whether if the process should continue
     */
    public function prepare()
    {
        $request = $this->getRequest();
        $response = $this->getResponse();

        try {
            //dispatch an init
            $continue = $this->getPreprocessor()->process($request, $response);
        } catch (Throwable $e) {
            //if there is an exception
            //you may not want to out
            //right throw it out

            //we are going to ignore this because
            //there is a conflict between PHP5.6 and PHP7
            //and how it deals with Throwable
            // @codeCoverageIgnoreStart
            $response->setStatus(500, HttpHandler::STATUS_500);
            $continue = $this->getErrorProcessor()->process($request, $response, $e);
            // @codeCoverageIgnoreEnd
            //if there's an error in the errorware then let it be thrown
        }

        return $continue;
    }

    /**
     * Handles the main routing process
     *
     * @return bool Whether if the process should continue
     */
    public function process()
    {
        $request = $this->getRequest();
        $response = $this->getResponse();

        try {
            //dispatch an init
            $continue = $this->getRouter()->process($request, $response);
        } catch (Throwable $e) {
            //if there is an exception
            //you may not want to out
            //right throw it out

            //there is a conflict between PHP5.6 and PHP7
            //and how it deals with Throwable
            // @codeCoverageIgnoreStart
            $response->setStatus(500, HttpHandler::STATUS_500);
            $continue = $this->getErrorProcessor()->process($request, $response, $e);
            // @codeCoverageIgnoreEnd
            //if there's an error in the error processor then let it be thrown
        }

        return $continue;
    }

    /**
     * Process and output
     *
     * @param bool $emulate  If you really want it to echo (for testing)
     *
     * @return HttpHandler
     */
    public function render($emulate = false)
    {
        if (!$this->prepare() || !$this->process()) {
            return $this;
        }

        $response = $this->getResponse();

        $continue = true;<commit_msg>hotfix process called when prepare fails<commit_after><?php //-->
/**
 * This file is part of the Cradle PHP Library.
 * (c) 2016-2018 Openovate Labs
 *
 * Copyright and license information can be found at LICENSE.txt
 * distributed with this package.
 */

namespace Cradle\Http;

use Throwable;

use Cradle\Http\Router\RouterTrait;
use Cradle\Http\Request\RequestTrait;
use Cradle\Http\Response\ResponseTrait;
use Cradle\Http\Dispatcher\DispatcherTrait;
use Cradle\Http\Middleware\PreProcessorTrait;
use Cradle\Http\Middleware\PostProcessorTrait;
use Cradle\Http\Middleware\ErrorProcessorTrait;

/**
 * You can optionally adopt these methods into an existing class
 *
 * @vendor   Cradle
 * @package  Http
 * @author   <NAME> <<EMAIL>>
 * @standard PSR-2
 */
trait HttpTrait
{
    use DispatcherTrait,
        PreProcessorTrait,
        PostProcessorTrait,
        ErrorProcessorTrait,
        RequestTrait,
        ResponseTrait,
        RouterTrait;

    /**
     * Prepares the event and calls the preprocessors
     *
     * @return bool Whether if the process should continue
     */
    public function prepare()
    {
        $request = $this->getRequest();
        $response = $this->getResponse();

        try {
            //dispatch an init
            $continue = $this->getPreprocessor()->process($request, $response);
        } catch (Throwable $e) {
            //if there is an exception
            //you may not want to out
            //right throw it out

            //we are going to ignore this because
            //there is a conflict between PHP5.6 and PHP7
            //and how it deals with Throwable
            // @codeCoverageIgnoreStart
            $response->setStatus(500, HttpHandler::STATUS_500);
            $continue = $this->getErrorProcessor()->process($request, $response, $e);
            // @codeCoverageIgnoreEnd
            //if there's an error in the errorware then let it be thrown
        }

        return $continue;
    }

    /**
     * Handles the main routing process
     *
     * @return bool Whether if the process should continue
     */
    public function process()
    {
        $request = $this->getRequest();
        $response = $this->getResponse();

        try {
            //dispatch an init
            $continue = $this->getRouter()->process($request, $response);
        } catch (Throwable $e) {
            //if there is an exception
            //you may not want to out
            //right throw it out

            //there is a conflict between PHP5.6 and PHP7
            //and how it deals with Throwable
            // @codeCoverageIgnoreStart
            $response->setStatus(500, HttpHandler::STATUS_500);
            $continue = $this->getErrorProcessor()->process($request, $response, $e);
            // @codeCoverageIgnoreEnd
            //if there's an error in the error processor then let it be thrown
        }

        return $continue;
    }

    /**
     * Process and output
     *
     * @param bool $emulate  If you really want it to echo (for testing)
     *
     * @return HttpHandler
     */
    public function render($emulate = false)
    {
        $response = $this->getResponse();

        if(!$this->prepare()) {
            return $this;
        }

        if($response->getStatus() === 200 && !$this->process()) {
            return $this;
        }

        $continue = true;
{'fraction_non_alphanumeric': 0.10483628717332533, 'fraction_numerical': 0.008561129468308802, 'mean_word_length': 2.029572338489536, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 46, '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': '6400905', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1788, 'n_words': 559}