<commit_before><?php
/**
 * Controller - base controller
 *
 * @author <NAME> - <EMAIL>
 * @version 3.0
 */

namespace Core;

use Core\Config;
use Routing\Controller as BaseController;
use Support\Contracts\RenderableInterface as Renderable;
use Template\Template as Layout;

use Symfony\Component\HttpFoundation\Request as SymfonyRequest;

use Template;
use View;


/**
 * Core controller, all other controllers extend this base controller.
 */
abstract class Controller extends BaseController
{
    /**
     * The currently used Template.
     *
     * @var string
     */
    protected $template = null;

    /**
     * The currently used Layout.
     *
     * @var string
     */
    protected $layout = 'default';


    /**
     * On the initial run, create an instance of the config class and the view class.
     */
    public function __construct()
    {
        // Setup the used Template to default, if it is not already defined.
        if (($this->layout !== false) && ! isset($this->template)) {
            $this->template = Config::get('app.template');
        }
    }

    /**
     * Create from the given result a Response instance and send it.
     *
     * @param mixed  $response
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    protected function processResponse($response)
    {
        if ($response instanceof Renderable) {
            // If the response which is returned from the called Action is a Renderable instance,
            // we will assume we want to render it using the Controller's templated environment.

            if (($this->layout !== false) && (! $response instanceof Layout)) {
                $response = Template::make($this->layout, $this->template)->with('content', $response);
            }
        }

        return parent::processResponse($response);
    }

    /**
     * Return a default View instance.
     *
     * @return \View\View
     * @throw \BadMethodCallException
     */
    protected function getView(array $data = array())
    {
        list(, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);

        $method = $caller['function'];

        //
        $path = str_replace('\\', '/', static::class);

        if (preg_match('#^App/Controllers/(.*)$#i', $path, $matches)) {
            $view = $matches[1] .'/' .ucfirst($method);

            return View::make($view, $data);
        } else if (preg_match('#^App/Modules/(.+)/Controllers/(.*)$#i', $path, $matches)) {
            $view = $matches[2] .'/' .ucfirst($method);<commit_msg>Improve Core\Controller@processResponse<commit_after><?php
/**
 * Controller - base controller
 *
 * @author <NAME> - <EMAIL>
 * @version 3.0
 */

namespace Core;

use Core\Config;
use Http\Response;
use Routing\Controller as BaseController;
use Support\Contracts\RenderableInterface as Renderable;
use Template\Template as Layout;

use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

use Template;
use View;


/**
 * Core controller, all other controllers extend this base controller.
 */
abstract class Controller extends BaseController
{
    /**
     * The currently used Template.
     *
     * @var string
     */
    protected $template = null;

    /**
     * The currently used Layout.
     *
     * @var string
     */
    protected $layout = 'default';


    /**
     * On the initial run, create an instance of the config class and the view class.
     */
    public function __construct()
    {
        // Setup the used Template to default, if it is not already defined.
        if (($this->layout !== false) && ! isset($this->template)) {
            $this->template = Config::get('app.template');
        }
    }

    /**
     * Create from the given result a Response instance and send it.
     *
     * @param mixed  $response
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    protected function processResponse($response)
    {
        if ($response instanceof Renderable) {
            // If the response which is returned from the called Action is a Renderable instance,
            // we will assume we want to render it using the Controller's templated environment.

            if (($this->layout !== false) && (! $response instanceof Layout)) {
                $response = Template::make($this->layout, $this->template)->with('content', $response);
            }
        }

        // If the response is not a instance of Symfony Response, create a proper one.
        if (! $response instanceof SymfonyResponse) {
            $response = new Response($response);
        }

        return $response;
    }

    /**
     * Return a default View instance.
     *
     * @return \View\View
     * @throw \BadMethodCallException
     */
    protected function getView(array $data = array())
    {
        list(, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);

        $method = $caller['function'];

        //
        $path = str_replace('\\', '/', static::class);

        if (preg_match('#^App/Controllers/(.*)$#i', $path, $matches)) {
            $view = $matches[1] .'/' .ucfirst($method);

            return View::make($view, $data);
        } else if (preg_match('#^App/Modules/(.+)/Controllers/(.*)$#i', $path, $matches)) {
            $view = $matches[2] .'/' .ucfirst($method);
{'fraction_non_alphanumeric': 0.13298565840938723, 'fraction_numerical': 0.0018625442354255914, 'mean_word_length': 2.4008866371120963, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '3486076', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1466, 'n_words': 435}