<commit_before><?php


abstract class AController
{
    protected $db;
    protected $request;
    protected $controllerName;
    protected $isProcessed;
    protected $log;
    protected $sessionUser;

    protected $documentRoot;
    
    protected $model = [];
    
    public function __construct($request , $name) {
        $this->request = $request;
        $this->controllerName = $name;
        $this->isProcessed = false;
        $this->documentRoot = $_SERVER["DOCUMENT_ROOT"];
       
        //initialize database connection
        global $config;
        $this->db = new MySQLClass($config['db']['server'], $config['db']['user'], $config['db']['pass'], $config['db']['name']);
    }
    abstract protected function setActions();

    public function processRequest()
    {
        try {
            $this->setActions();

        } catch (InternalException $e) {
            $this->showError("500", $e->getMessage() );
            exit;

        } catch (BadRequestException $e) {
            $this->showError("400", $e->getMessage() );
            exit;

        }  catch (ForbiddentException $e) {
            $this->showError("403", $e->getMessage() );
            exit;

        } catch (UnauthorizedException $e) {
            if($e->isSowError){
                $this->showError("401", $e->getMessage() );
                exit;
            }

            $redirectTo = "";
            if(isset($e->redirectUrl) &&  $e->redirectUrl!=""){
                $redirectTo = "?redirect=".$e->redirectUrl;
            }

            global $config;
            header("Location: ".$config['common']['login_url'].$redirectTo);
            exit;
        }

        if (!$this->isProcessed) {
            $this->showError("400", "Bad request parameters!" );
            exit;
        }

        $this->closeDBConnection();
    }

    protected function showView($viewClass, $parameters = null)
    {
        
        $viewData = [];
        if (isset($parameters) && is_array($parameters)) {
            $viewData = $parameters;
        }else{
            $viewData = $this->model;
        }

        //set mandatory modelData for all Views  
        $viewData['session_user'] = $this->sessionUser;
        
        if (!class_exists($viewClass)) {
            throw new InternalException("View class \"" . $viewClass . "\" not found ! ");
        }

        $view = new $viewClass($viewData);
        $view->render();
    }

    private function showError($code, $text){
        $errorController = new RCError($this->request);
        $errorController->showErrorPage($code, $text , $this->request->isAjax);
    }

    private function closeDBConnection(){
        if ($this->db) {<commit_msg>processRequest<commit_after><?php


abstract class AController
{
    protected $db;
    protected $request;
    protected $controllerName;
    protected $isProcessed;
    protected $log;
    protected $sessionUser;

    protected $documentRoot;
    
    protected $model = [];
    
    public function __construct($request , $name) {
        $this->request = $request;
        $this->controllerName = $name;
        $this->isProcessed = false;
        $this->documentRoot = $_SERVER["DOCUMENT_ROOT"];
       
        //initialize database connection
        global $config;
        $this->db = new MySQLClass($config['db']['server'], $config['db']['user'], $config['db']['pass'], $config['db']['name']);
    }
    abstract protected function setActions();

    public function processRequest() {
        try {
            $this->setActions();

            if (!$this->isProcessed) {
                //can't find the right processor
                throw new BadRequestException("Bad request parameters!");
            }
            
        } catch (InternalException $e) {
            $this->showError("500", $e->getMessage());
            
        } catch (BadRequestException $e) {
            $this->showError("400", $e->getMessage());
            
        } catch (ForbiddentException $e) {
            $this->showError("403", $e->getMessage());
            
        } catch (UnauthorizedException $e) {
            
            if ($e->isSowError) {
                $this->showError("401", $e->getMessage());
            }else{
                $redirectTo = "";
                if (isset($e->redirectUrl) && $e->redirectUrl != "") {
                    $redirectTo = "?redirect=" . $e->redirectUrl;
                }
                
                global $config;
                header("Location: " . $config['common']['login_url'] . $redirectTo);
            }
        } finally {
            $this->closeDBConnection();
        }
    }

    protected function showView($viewClass, $parameters = null) {

        $viewData = [];
        if (isset($parameters) && is_array($parameters)) {
            $viewData = $parameters;
        } else {
            $viewData = $this->model;
        }

        //set mandatory modelData for all Views  
        $viewData['session_user'] = $this->sessionUser;

        if (!class_exists($viewClass)) {
            throw new InternalException("View class \"" . $viewClass . "\" not found ! ");
        }

        $view = new $viewClass($viewData);
        $view->render();
    }

    private function showError($code, $text){
        $errorController = new RCError($this->request);
        $errorController->showErrorPage($code, $text , $this->request->isAjax);
    }

    private function closeDBConnection(){
        if ($this->db) {
{'fraction_non_alphanumeric': 0.15124977193942712, 'fraction_numerical': 0.0049261083743842365, 'mean_word_length': 1.9378349410503752, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 60, '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': '4470869', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1450, 'n_words': 296}