<commit_before><?php
namespace AnhNhan\ModHub\Web\Application;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * @author <NAME> <<EMAIL>>
 */
abstract class BaseApplicationController
{
    /**
     * @var BaseApplication
     */
    private $app;

    /**
     * @var RequestStack
     */
    private $requestStack;

    final public function __construct(BaseApplication $app)
    {
        $this->app = $app;
    }

    final public function app()
    {
        return $this->app;
    }

    final protected function externalApp($name)
    {
        return $this->app->getService('app.list')->app($name);
    }

    protected function getRepository($entityName)
    {
        $app = $this->app();
        $entityManager = $app->getEntityManager();
        return $entityManager->getRepository($entityName);
    }

    /**
     * @return Request
     */
    final public function request()
    {
        return $this->requestStack->getCurrentRequest();
    }

    final public function setRequestStack(RequestStack $requestStack)
    {
        $this->requestStack = $requestStack;
        return $this;
    }

    /**
     * Override this method if you want to handle multiple types of data
     *
     * @return AnhNhan\ModHub\Web\HttpPayload|Symfony\Component\HttpFoundation\Response
     */
    public function process()
    {
        return $this->handle();
    }

    /**
     * @return AnhNhan\ModHub\Web\HttpPayload|Symfony\Component\HttpFoundation\Response
     */
    abstract public function handle();


    // Magic properties :)
    // $this->app instead of $this->app()
    public function __get($name)
    {
        if (method_exists($this, $name)) {
            return $this->$name();
        }

        throw new \RunTimeException(sprintf(
            "Ayo, you tried to access '%s::%s' that does not exist in here!\n" .
            "Better check your code!",
            get_class($this),
            $name
        ));
    }
}<commit_msg>Adding a few convenience methods to BaseApplicationController<commit_after><?php
namespace AnhNhan\ModHub\Web\Application;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * @author <NAME> <<EMAIL>>
 */
abstract class BaseApplicationController
{
    /**
     * @var BaseApplication
     */
    private $app;

    /**
     * @var RequestStack
     */
    private $requestStack;

    final public function __construct(BaseApplication $app)
    {
        $this->app = $app;
    }

    final public function app()
    {
        return $this->app;
    }

    final protected function externalApp($name)
    {
        return $this->app->getService('app.list')->app($name);
    }

    protected function getRepository($entityName)
    {
        $app = $this->app();
        $entityManager = $app->getEntityManager();
        return $entityManager->getRepository($entityName);
    }

    /**
     * @return Request
     */
    final public function request()
    {
        return $this->requestStack->getCurrentRequest();
    }

    final public function setRequestStack(RequestStack $requestStack)
    {
        $this->requestStack = $requestStack;
        return $this;
    }

    /**
     * Override this method if you want to handle multiple types of data
     *
     * @return AnhNhan\ModHub\Web\HttpPayload|Symfony\Component\HttpFoundation\Response
     */
    public function process()
    {
        return $this->handle();
    }

    /**
     * @return AnhNhan\ModHub\Web\HttpPayload|Symfony\Component\HttpFoundation\Response
     */
    abstract public function handle();


    // Magic properties :)
    // $this->app instead of $this->app()
    public function __get($name)
    {
        if (method_exists($this, $name)) {
            return $this->$name();
        }

        throw new \RunTimeException(sprintf(
            "Ayo, you tried to access '%s::%s' that does not exist in here!\n" .
            "Better check your code!",
            get_class($this),
            $name
        ));
    }

    // |-----------------------------------------------------------------------|
    // |----  Various stuff, service location etc.  ---------------------------|
    // |-----------------------------------------------------------------------|

    protected function resMgr()
    {
        return $this->app->getService("resource_manager");
    }

    protected function stopwatch()
    {
        return $this->app->getService("stopwatch");
    }
}
{'fraction_non_alphanumeric': 0.16046923417441344, 'fraction_numerical': 0.0, 'mean_word_length': 2.008655126498003, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 43, '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': '5011760', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1219, 'n_words': 273}