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:
<?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\Controller;
trait Props {
/**
* Path to all static files - css, js, images and fonts.
* @var string
*/
protected static $staticPath = '/static';
/**
* Path to temporary directory with generated css and js files.
* @var string
*/
protected static $tmpPath = '/Var/Tmp';
/**
* Reference to `\MvcCore\Application` singleton object.
* @var \MvcCore\Application
*/
protected $application;
/**
* Environment object to detect and manage environment name.
* @var \MvcCore\Environment
*/
protected $environment;
/**
* Request object - parsed URI, query params, app paths...
* @var \MvcCore\Request
*/
protected $request;
/**
* Response object - storage for response headers and rendered body.
* @var \MvcCore\Response
*/
protected $response;
/**
* Application router object - reference storage for application router to crate URL addresses.
* @var \MvcCore\Router
*/
protected $router;
/**
* Requested controller name - `"dashed-controller-name"`.
* @var string
*/
protected $controllerName = '';
/**
* Requested action name - `"dashed-action-name"`.
* @var string
*/
protected $actionName = '';
/**
* Boolean about AJAX request.
* `TRUE` if request is requested from browser by `XmlHttpRequest` object
* with http header: `X-Requested-With: AnyJavascriptFrameworkName`, `FALSE` otherwise.
* @var boolean
*/
protected $ajax = FALSE;
/**
* Class store object for view properties.
* Before `\MvcCore\Controller::PreDispatch();` is called
* in controller lifecycle, this property will be still `NULL`.
* @var \MvcCore\View
*/
protected $view = NULL;
/**
* Rendering mode switch to render views in two ways:
* `\MvcCore\IView::RENDER_WITH_OB_FROM_ACTION_TO_LAYOUT`:
* - Render action view first into output buffer, then render layout view
* wrapped around rendered action view string also into output buffer.
* Then set up rendered content from output buffer into response object
* and then send HTTP headers and content after all.
* `\MvcCore\IView::RENDER_WITHOUT_OB_CONTINUOUSLY`:
* - Special rendering mode to continuously sent larger data to client.
* Render layout view and render action view together inside it without
* output buffering. There is not used reponse object body property for
* this rendering mode. Http headers are sent before view rendering.
* @var int
*/
protected $renderMode = \MvcCore\IView::RENDER_WITH_OB_FROM_ACTION_TO_LAYOUT;
/**
* Layout name to render html wrapper around rendered action view.
* @var string
*/
protected $layout = 'layout';
/**
* This property is to customize sub-controllers template path. `NULL` by default.
* You need to set into this property any custom string as relative path to
* your template file placed somewhere in `/App/Views/Scripts/`.
* For example if you want to render template file placed in:
* `/App/Views/Scripts/something/completely/custom.phtml`, you need to set
* up this property to value `something/completely` and then there is
* necessary to render your template only by calling controller rendering by:
* `$subcontrollerInstance->Render('custom');`
* @var string|NULL
*/
protected $viewScriptsPath = NULL;
/**
* If `TRUE`, view object is automatically created in base controller
* `PreDispatch()` method and view is automatically rendered with wrapping
* layout view around after controller action is called. Default value is
* `TRUE` for all non-ajax requests.
* @var boolean
*/
protected $viewEnabled = TRUE;
/**
* User model instance. Template property.
* @var \MvcCore\Model
*/
protected $user = NULL;
/**
* If `TRUE`, start session automatically in `Init()` method.
* @var bool
*/
protected $autoStartSession = TRUE;
/**
* If `TRUE`, automatically initialize properties with PHP docs tag
* with tha same name as this property. `FALSE` by default.
* @var bool
*/
protected $autoInitProperties = FALSE;
/**
* Controller lifecycle state:
* - 0 => Controller has been created.
* - 1 => Controller has been initialized.
* - 2 => Controller has been pre-dispatched.
* - 3 => controller has been action executed.
* - 4 => Controller has been rendered.
* - 5 => Controller has been redirected.
* @var int
*/
protected $dispatchState = \MvcCore\IController::DISPATCH_STATE_CREATED;
/**
* Parent controller instance if any.
* @var \MvcCore\Controller|NULL
*/
protected $parentController = NULL;
/**
* Registered sub-controllers instances.
* @var \MvcCore\Controller[]
*/
protected $childControllers = [];
/**
* All registered controllers instances.
* @var \MvcCore\Controller[]
*/
protected static $allControllers = [];
/**
* All asset mime types possibly called through `\MvcCore\Controller::AssetAction();`.
* @var string
*/
private static $_assetsMimeTypes = [
'js' => 'text/javascript',
'css' => 'text/css',
'ico' => 'image/x-icon',
'gif' => 'image/gif',
'png' => 'image/png',
'jpg' => 'image/jpg',
'jpeg' => 'image/jpeg',
'bmp' => 'image/bmp',
'svg' => 'image/svg+xml',
'eot' => 'application/vnd.ms-fontobject',
'ttf' => 'font/truetype',
'otf' => 'font/opentype',
'woff' => 'application/x-font-woff',
];
}