Overview

Namespaces

  • Core
    • BaseClasses
    • Cookie
    • Crontab
    • DB
    • Input
    • Mailer
    • Middleware
      • Auth
      • CSRF
    • Route
    • Session
    • System
  • None

Classes

  • Bridge
  • Core\BaseClasses\BaseAuth
  • Core\BaseClasses\BaseController
  • Core\BaseClasses\BaseCSRF
  • Core\Cookie\Cookie
  • Core\Crontab\Crontab
  • Core\DB\DB
  • Core\Input\Input
  • Core\Mailer\Mailer
  • Core\Middleware\Auth\Auth
  • Core\Middleware\CSRF\CSRF
  • Core\Route\Route
  • Core\Session\Session
  • Core\System\System

Functions

  • back
  • ControllerAutoload
  • dbd
  • ErrorHandler
  • ExceptionHandler
  • json
  • loadConfig
  • MiddlewareAutoload
  • redirect
  • SPAutoload
  • view
  • Overview
  • Namespace
  • Class
  1: <?php
  2: /**
  3:  * Created by PhpStorm.
  4:  * @Author : Shakti Phartiyal
  5:  * Date: 12/1/16
  6:  * Time: 12:50 PM
  7:  */
  8: namespace Core\BaseClasses;
  9: 
 10: use Core\System\System;
 11: use Twig_Environment;
 12: use Twig_Function;
 13: use Twig_Loader_Filesystem;
 14: use Core\Middleware\CSRF\CSRF;
 15: 
 16: class BaseController
 17: {
 18:     public $requestUri;
 19:     public $requestMethod;
 20:     public $requestData;
 21:     public $rawData;
 22: 
 23:     /**
 24:      * BaseController constructor. Sets the request data which can be accessed in all controllers extending this class.
 25:      * @param $request
 26:      */
 27:     public function __construct($request)
 28:     {
 29:         $this->requestUri = $request[0];
 30:         $this->requestMethod = $request[1];
 31:         $this->requestData = $request[2];
 32:         $this->rawData = $request[3];
 33:         if($this->requestMethod == "POST")
 34:         {
 35:             CSRF::verifyCSRFToken($this->requestUri);
 36:         }
 37:     }
 38: 
 39: 
 40:     /**
 41:      * Returns the view from the template engine.
 42:      * @param $view
 43:      * @param array $arrayParams
 44:      * @param bool $exit
 45:      */
 46:     public static function view($view, $arrayParams = [], $exit = false)
 47:     {
 48:         $loader = new Twig_Loader_Filesystem(__DIR__.'/../../Views');
 49:         $cache = __DIR__.'/../../Storage/Cache/Views';
 50:         if(!$_ENV['cache_template'])
 51:         {
 52:             $cache = false;
 53:         }
 54:         $twig = new Twig_Environment($loader, array(
 55:             'cache' => $cache,
 56:             'auto_reload' => $_ENV['debug'],
 57:         ));
 58:         $csrfFunction = new Twig_Function('csrf_token', function () {
 59:             $csrf = new BaseCSRF();
 60:             return $csrf->generateToken();
 61:         });
 62:         $twig->addFunction($csrfFunction);
 63:         $template = $twig->load($view.'.vu.php');
 64:         if($exit === true)
 65:         {
 66:             echo $template->display($arrayParams);
 67:             exit(1);
 68:         }
 69:         return $template->display($arrayParams);
 70:     }
 71: 
 72: /*    public static function view($viewName899lkks, $inArray65fyghed3s=null, $exit=false)
 73:     {
 74:         if($inArray65fyghed3s!=null)
 75:         {
 76:             foreach (array_keys($inArray65fyghed3s) as $variable65fyghed3s)
 77:             {
 78:                 $$variable65fyghed3s=$inArray65fyghed3s[$variable65fyghed3s];
 79:             }
 80:         }
 81:         $viewFileLoaded12wes=include __DIR__."/../../Views/".$viewName899lkks.".vu.php";
 82:         $viewFileLoaded12wes=substr($viewFileLoaded12wes, 0,-1);
 83:         if($exit) //only for error pages
 84:         {
 85:             echo $viewFileLoaded12wes;
 86:             exit(1);
 87:         }
 88:         return $viewFileLoaded12wes;
 89:     }*/
 90: 
 91:     /**
 92:      * Redirects a user to a particular URL.
 93:      * @param $path
 94:      */
 95:     public static function redirect($path)
 96:     {
 97:         $path="location: ".$path;
 98:         header($path);
 99:     }
100: 
101:     /**
102:      * Returns the JSON value of the passed array
103:      * @param $inArray
104:      */
105:     public static function json($inArray)
106:     {
107:         System::GiveJSON($inArray);
108:     }
109: 
110:     /**
111:      *Brings the user back to the requesting page.
112:      */
113:     public static function back()
114:     {
115:         $ref = "location: ".$_SERVER['HTTP_REFERER'];
116:         header($ref);
117:     }
118: }
API documentation generated by ApiGen