1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295:
<?php
/**
* MvcCore
*
* This source file is subject to the BSD 3 License
* For the full copyright and license information, please view
* the LICENSE.md file that are distributed with this source code.
*
* @copyright Copyright (c) 2016 Tom Flidr (https://github.com/mvccore)
* @license https://mvccore.github.io/docs/mvccore/5.0.0/LICENCE.md
*/
namespace MvcCore\Application;
/**
* Trait as partial class for `\MvcCore\Application`:
* - Main application objects container (request, response, controller, etc.).
* - MvcCore compile mode managing (single file mode, php, phar, or no package).
* - Global store for all main core class names, to use them as modules,
* to be changed any time (request class, response class, debug class, etc.).
*/
trait Props {
/***********************************************************************************
* `\MvcCore\Application` - Properties *
***********************************************************************************/
/**
* Application instance for current request. Singleton instance storage.
* @var \MvcCore\Application
*/
protected static $instance;
/**
* Describes if application is running as standard php project or as single file application.
* It should has values from:
* - `\MvcCore\IApplication::COMPILED_PHP`
* - `\MvcCore\IApplication::COMPILED_PHAR`
* - `\MvcCore\IApplication::COMPILED_SFU`
* - `\MvcCore\IApplication::NOT_COMPILED`
* Read more about every mode in interface: `\MvcCore\IApplication`.
* @var string
*/
protected $compiled = NULL;
/**
* Environment detection instance.
* @var \MvcCore\Environment
*/
protected $environment = NULL;
/**
* Top most parent controller instance currently dispatched by application.
* @var \MvcCore\Controller
*/
protected $controller = NULL;
/**
* Request object - parsed URI, query params, app paths...
* @var \MvcCore\Request
*/
protected $request = NULL;
/**
* Response object - storage for response headers and rendered body.
* @var \MvcCore\Response
*/
protected $response = NULL;
/**
* Application http router to route request and build URL addresses.
* @var \MvcCore\Router
*/
protected $router = NULL;
/**
* Pre route custom closure calls storage.
* Every item in this array has to be `callable`.
* Params in callable should be two with following types:
* - `\MvcCore\Request`
* - `\MvcCore\Response`
* Example:
* `\MvcCore\Application::GetInstance()->AddPreRouteHandler(function(
* \MvcCore\Request $request,
* \MvcCore\Response $response
* ) {
* $request->customVar = 'custom_value';
* });`
* @var \array[]
*/
protected $preRouteHandlers = [];
/**
* Post route custom closure calls storage.
* Every item in this array has to be `callable`.
* Params in callable should be two with following types:
* - `\MvcCore\Request`
* - `\MvcCore\Response`
* Example:
* `\MvcCore\Application::GetInstance()->AddPostRouteHandler(function(
* \MvcCore\Request $request,
* \MvcCore\Response $response
* ) {
* $request->customVar = 'custom_value';
* });`
* @var \array[]
*/
protected $postRouteHandlers = [];
/**
* Pre dispatch custom calls storage.
* Every item in this array has to be `callable`.
* Params in `callable` should be two with following types:
* - `\MvcCore\Request`
* - `\MvcCore\Response`
* Example:
* `\MvcCore\Application::GetInstance()->AddPreDispatchHandler(function(
* \MvcCore\Request $request,
* \MvcCore\Response $response
* ) {
* $request->customVar = 'custom_value';
* });`
* @var \array[]
*/
protected $preDispatchHandlers = [];
/**
* Post dispatch custom calls storage.
* Every item in this array has to be `callable`.
* Params in `callable` should be two with following types:
* - `\MvcCore\Request`
* - `\MvcCore\Response`
* Example:
* `\MvcCore\Application::GetInstance()->AddPostDispatchHandler(function(
* \MvcCore\Request $request,
* \MvcCore\Response $response
* ) {
* $request->customVar = 'custom_value';
* });`
* @var \array[]
*/
protected $postDispatchHandlers = [];
/**
* Post terminate custom calls storage.
* Every item in this array has to be `callable`.
* Params in `callable` should be two with following types:
* - `\MvcCore\Request`
* - `\MvcCore\Response`
* Example:
* `\MvcCore\Application::GetInstance()->AddPostTerminateHandler(function(
* \MvcCore\Request $request,
* \MvcCore\Response $response
* ) {
* // close connection by previously configured
* // header: header('Connection: close');
* // and run background process now:
* });`
* @var \array[]
*/
protected $postTerminateHandlers = [];
/**
* Class to detect and manage environment name.
* @var string
*/
protected $environmentClass = '\MvcCore\Environment';
/**
* Class to load and parse (system) config(s).
* @var string
*/
protected $configClass = '\MvcCore\Config';
/**
* Class to create default controller for request targeting views only
* and to handle small assets inside packed application.
* @var string
*/
protected $controllerClass = '\MvcCore\Controller';
/**
* Class to handle any application error to render the error in browser or log in HDD.
* @var string
*/
protected $debugClass = '\MvcCore\Debug';
/**
* Class to create describing HTTP request object.
* @var string
*/
protected $requestClass = '\MvcCore\Request';
/**
* Class to create HTTP response object to store response headers and response content.
* @var string
*/
protected $responseClass = '\MvcCore\Response';
/**
* Class to describe single route with match and replace pattern,
* controller, action, params default values and params constraints.
* @var string
*/
protected $routeClass = '\MvcCore\Route';
/**
* Class to store all routes, dispatch request by routes and generate URL addresses by routes.
* @var string
*/
protected $routerClass = '\MvcCore\Router';
/**
* Class to configure session namespaces, session opening, writing and expirations.
* @var string
*/
protected $sessionClass = '\MvcCore\Session';
/**
* Class to handle helper calls from MvcCore core modules.
* @var string
*/
protected $toolClass = '\MvcCore\Tool';
/**
* Class to prepare and render controller view, sub-views and wrapper layout.
* @var string
*/
protected $viewClass = '\MvcCore\View';
/**
* Application scripts and views directory name as `"App"` by default,
* where are following subdirectories by default:
* - `/App/Controllers`
* - `/App/Models`
* - `/App/Views`
* It should by reconfigured to custom value in the very application beginning.
* @var string
*/
protected $appDir = 'App';
/**
* Controllers directory name as `"Controllers"` by default, for all controller classes,
* it's placed directly in application directory by default.
* It should by reconfigured to custom value in the very application beginning.
* @var string
*/
protected $controllersDir = 'Controllers';
/**
* Views directory name as `"views"` by default, for all view elements,
* it's placed directly in application directory above by default.
* It should by reconfigured to custom value in the very application beginning.
* @var string
*/
protected $viewsDir = 'Views';
/**
* Default controller name, `"Index"` by default.
* @var string
*/
protected $defaultControllerName = 'Index';
/**
* Default controller default action name, `"Index"` by default.
* @var string
*/
protected $defaultControllerDefaultActionName = 'Index';
/**
* Default controller error action name, `"Error"` by default.
* @var string
*/
protected $defaultControllerErrorActionName = 'Error';
/**
* Default controller not found error action name, `"NotFound"` by default.
* @var string
*/
protected $defaultControllerNotFoundActionName = 'NotFound';
/**
* Boolean flag if request has been already terminated or not
* to process `\MvcCore\Application::Terminate();` only once.
* Default value is `FALSE`.
* @var bool
*/
protected $terminated = FALSE;
}