<commit_before><?php
namespace Ouzo;

use Ouzo\Routing\RouteRule;
use Ouzo\Utilities\Arrays;
use Ouzo\Utilities\Path;
use Ouzo\Utilities\Strings;

class Controller
{
    public $view;
    public $layout;
    public $before = array();
    public $after = array();
    public $currentController = '';
    public $currentAction = '';
    public $params;

    private $_statusResponse = 'show';
    private $_redirectLocation = '';
    private $_fileData = array();
    private $_headers = array();
    private $_routeRule = null;
    private $_authCredentials = array();
    private $_keepMessage = false;

    public function __construct(RouteRule $routeRule)
    {
        $this->_routeRule = $routeRule;
        $uri = new Uri();
        $this->currentController = $routeRule->getController();
        $this->currentAction = $routeRule->isActionRequired() ? $routeRule->getAction() : $uri->getAction();

        $viewName = Path::join(Strings::underscoreToCamelCase($this->currentController), $this->currentAction) ? : '/';

        $this->view = new View($viewName);
        $this->layout = new Layout();
        $requestParameters = Uri::getRequestParameters();
        $parameters = $routeRule->getParameters() ? $routeRule->getParameters() : $uri->getParams();
        $this->params = array_merge($_POST, $_GET, $requestParameters, $parameters);
    }

    public function header($header)
    {
        $this->_headers[] = $header;
    }

    public function getHeaders()
    {
        return $this->_headers;
    }

    public function redirect($url, $messages = array())
    {
        $this->notice($messages);

        $this->_redirectLocation = $url;
        $this->_statusResponse = 'redirect';
    }

    public function downloadFile($label, $mime, $path, $type = 'file')
    {
        $this->_fileData = array('label' => $label, 'mime' => $mime, 'path' => $path);
        $this->_statusResponse = $type;
    }

    public function setRedirectLocation($redirectLocation)
    {
        $this->_redirectLocation = $redirectLocation;
    }

    public function setStatusResponse($statusResponse)
    {
        $this->_statusResponse = $statusResponse;
    }

    public function getStatusResponse()
    {
        return $this->_statusResponse;
    }

    public function getRedirectLocation()
    {
        return $this->_redirectLocation;
    }

    public function getFileData()
    {
        return $this->_fileData;
    }

    public function display()
    {
        $renderedView = $this->view->getRenderedView();
        if ($renderedView) {
            $this->layout->setRenderContent($renderedView);
        }

        $this->layout->renderLayout();
        $this->_removeMessages();
    }

    private function _removeMessages()
    {
        if (!$this->_keepMessage) {
            Session::remove('messages');
        }
    }

    public function renderAjaxView($viewName)
    {
        $view = $this->view->render($viewName);
        $this->layout->renderAjax($view);
    }

    public function notice($messages, $keep = false)
    {
        if (!empty($messages)) {
            Session::set('messages', Arrays::toArray($messages));
            $this->_keepMessage = $keep;
        }
    }

    public static function getTab()
    {
        $noController = str_replace('Controller', '', get_called_class());
        $noSlashes = str_replace('\\', '', $noController);
        return Strings::camelCaseToUnderscore($noSlashes);
    }

    public function isAjax()
    {
        return Uri::isAjax();
    }

    public function getRouteRule()
    {
        return $this->_routeRule;
    }

    function __call($name, $args)
    {
        throw new NoControllerActionException('No action [' . $name . '] defined in controller [' . get_called_class() . '].');
    }

    public function httpAuthBasic($login, $password)
    {
        $this->setStatusResponse('httpAuthBasic');
        $this->_authCredentials = array('login' => $login, 'password' => $password);
    }

    public function getAuthCredentials()
    {
        return $this->_authCredentials;
    }
}

class NoControllerActionException extends \Exception
{
}<commit_msg>Fix loading views for the #80 issue.<commit_after><?php
namespace Ouzo;

use Ouzo\Routing\RouteRule;
use Ouzo\Utilities\Arrays;
use Ouzo\Utilities\ClassName;
use Ouzo\Utilities\Path;
use Ouzo\Utilities\Strings;

class Controller
{
    public $view;
    public $layout;
    public $before = array();
    public $after = array();
    public $currentController = '';
    public $currentAction = '';
    public $params;

    private $_statusResponse = 'show';
    private $_redirectLocation = '';
    private $_fileData = array();
    private $_headers = array();
    private $_routeRule = null;
    private $_authCredentials = array();
    private $_keepMessage = false;

    public function __construct(RouteRule $routeRule)
    {
        $this->_routeRule = $routeRule;
        $uri = new Uri();
        $this->currentController = $routeRule->getController();
        $this->currentAction = $routeRule->isActionRequired() ? $routeRule->getAction() : $uri->getAction();

        $viewName = Path::join(ClassName::pathToFullyQualifiedName($this->currentController), $this->currentAction) ? : '/';

        $this->view = new View($viewName);
        $this->layout = new Layout();
        $requestParameters = Uri::getRequestParameters();
        $parameters = $routeRule->getParameters() ? $routeRule->getParameters() : $uri->getParams();
        $this->params = array_merge($_POST, $_GET, $requestParameters, $parameters);
    }

    public function header($header)
    {
        $this->_headers[] = $header;
    }

    public function getHeaders()
    {
        return $this->_headers;
    }

    public function redirect($url, $messages = array())
    {
        $this->notice($messages);

        $this->_redirectLocation = $url;
        $this->_statusResponse = 'redirect';
    }

    public function downloadFile($label, $mime, $path, $type = 'file')
    {
        $this->_fileData = array('label' => $label, 'mime' => $mime, 'path' => $path);
        $this->_statusResponse = $type;
    }

    public function setRedirectLocation($redirectLocation)
    {
        $this->_redirectLocation = $redirectLocation;
    }

    public function setStatusResponse($statusResponse)
    {
        $this->_statusResponse = $statusResponse;
    }

    public function getStatusResponse()
    {
        return $this->_statusResponse;
    }

    public function getRedirectLocation()
    {
        return $this->_redirectLocation;
    }

    public function getFileData()
    {
        return $this->_fileData;
    }

    public function display()
    {
        $renderedView = $this->view->getRenderedView();
        if ($renderedView) {
            $this->layout->setRenderContent($renderedView);
        }

        $this->layout->renderLayout();
        $this->_removeMessages();
    }

    private function _removeMessages()
    {
        if (!$this->_keepMessage) {
            Session::remove('messages');
        }
    }

    public function renderAjaxView($viewName)
    {
        $view = $this->view->render($viewName);
        $this->layout->renderAjax($view);
    }

    public function notice($messages, $keep = false)
    {
        if (!empty($messages)) {
            Session::set('messages', Arrays::toArray($messages));
            $this->_keepMessage = $keep;
        }
    }

    public static function getTab()
    {
        $noController = str_replace('Controller', '', get_called_class());
        $noSlashes = str_replace('\\', '', $noController);
        return Strings::camelCaseToUnderscore($noSlashes);
    }

    public function isAjax()
    {
        return Uri::isAjax();
    }

    public function getRouteRule()
    {
        return $this->_routeRule;
    }

    function __call($name, $args)
    {
        throw new NoControllerActionException('No action [' . $name . '] defined in controller [' . get_called_class() . '].');
    }

    public function httpAuthBasic($login, $password)
    {
        $this->setStatusResponse('httpAuthBasic');
        $this->_authCredentials = array('login' => $login, 'password' => $password);
    }

    public function getAuthCredentials()
    {
        return $this->_authCredentials;
    }
}

class NoControllerActionException extends \Exception
{
}
{'fraction_non_alphanumeric': 0.1423611111111111, 'fraction_numerical': 0.00023946360153256704, 'mean_word_length': 2.7390331244404655, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 101, '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': '5251384', 'n_tokens_mistral': 2367, 'n_tokens_neox': 2322, 'n_words': 470}