Class MvcCore
Application MVC core: - main application objects container - MvcCore compile mode managing - store for main core class names to use them later for run, creating instances or static usage - application run processing: - completing request and response - calling pre/post handlers - controller/action dispatching - error handling and error responses
License: https://mvccore.github.io/docs/mvccore/4.0.0/LICENCE.md
Located at mvccore/src/MvcCore.php
public static
|
#
StaticInit( )
Static constructor (called internaly - do not call this in application). It initializes application compilation mode before \MvcCore::GetInstance()->Run(); |
public static
|
|
public static
|
#
AddPreRouteHandler( callable $handler )
Add pre route handler into queue. Closure functions has to be void. Params in closure function has to be: - reference for request - reference for response |
public static
|
#
AddPreDispatchHandler( callable $handler )
Add pre dispatch handler into queue. Closure functions has to be void. Params in closure function has to be: - reference for request - reference for response |
public static
|
#
AddPostDispatchHandler( callable $handler )
Add post dispatch handler into queue. Closure functions has to be void. Params in closure function has to be: - reference for request - reference for response |
public static
|
#
SessionStart( )
Starts a session, standardly called in \MvcCore\Controller::Init(); But is shoud be called anywhere before, for example in any prerequest handler to redesign request before MVC dispatching. |
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
string
|
|
public
string
|
#
GetControllersDir( )
Get controllers directory, where are controllers located. 'Controllers' directory shoud be located in Application directory. 'Controllers' value by default. |
public
string
|
#
GetViewsDir( )
Get views directory, where are views located. 'Views' directory shoud be located in Application directory. 'Views' value by default. |
public
array
|
#
GetDefaultControllerAndActionNames( )
Returns array with default controller name and default action nam. |
public
|
|
public
|
#
SetConfigClass( string $configClass )
Set config class, extended from \MvcCore\Config. Core configuration method. |
public
|
#
SetSessionClass( string $sessionClass )
Set session class, extended from \MvcCore\Session. Core configuration method. |
public
|
#
SetRequestClass( string $requestClass )
Set request class, extended from \MvcCore\Request. Core configuration method. |
public
|
#
SetResponseClass( string $responseClass )
Set request class, extended from \MvcCore\Response. Core configuration method. |
public
|
#
SetRouterClass( string $routerClass )
Set router class, extended from \MvcCore\Router. Core configuration method. |
public
|
#
SetViewClass( string $viewClass )
Set view class, extended from \MvcCore\View. Core configuration method. |
public
|
#
SetDebugClass( string $debugClass )
Set debug class, extended from \MvcCore\Debug. Core configuration method. |
public
|
|
public
|
#
SetControllersDir( string $controllersDir )
Set controllers directory, where are controllers located. 'Controllers' directory shoud be located in Application directory. 'Controllers' value by default. Core configuration method. |
public
|
#
SetViewsDir( string $viewsDir )
Set views directory, where are views located. 'Views' directory shoud be located in Application directory. 'Views' value by default. Core configuration method. |
public
|
#
SetDefaultControllerName( string $defaultControllerName )
Set default controller name. 'Default' value by default. Core configuration method. |
public
|
#
SetDefaultControllerDefaultActionName( string $defaultActionName )
Set default controller default action name. 'Default' value by default. Core configuration method. |
public
|
#
SetDefaultControllerErrorActionName( string $defaultControllerErrorActionName )
Set default controller common error action name. 'Error' value by default. Core configuration method. |
public
|
#
SetDefaultControllerNotFoundActionName( string $defaultControllerNotFoundActionName )
Set default controller not found error action name. 'NotFound' value by default. Core configuration method. |
public
|
|
protected
|
#
process( )
Process request. 1. Init debuginf and loging handlers if necessary 2. Complete request. 3. Call pre route handlers queue. 4. Route request by configured router. 5. Call pre dispatch handlers queue. 6. Dispatch request - process controller methods - render and send view result 7. Call post dispatch handlers queue. 8. Write session and exit |
protected
boolean
|
#
routeRequest( )
Route request by router obtained by \MvcCore\Router::GetInstance(); Store requested route inside router class to get it later by: MvcCore\Router::GetCurrentRoute(); |
protected
boolean
|
#
processCustomHandlers( callable[] & $handlers = array() )
Process preroute, prerequest and postdispatch handlers queue by queues index |
public
boolean
|
#
DispatchMvcRequest(
If controller class exists - try to dispatch controller, if only view file exists - try to render this view file. |
public
boolean
|
#
DispatchControllerAction( string $controllerClassFullName, string $actionName, callable $viewScriptFullPath, callable $exceptionCallback )
Dispatch controller by full class name and by action name. |
public
string
|
#
Url( string $controllerActionOrRouteName = 'Index:Index', array $params = array() )
Generates url by: - 'Controller:Action' name and params array (for routes configuration when routes array has keys with 'Controller:Action' strings and routes has not controller name and action name defined inside) - route name and params array (route name is key in routes configuration array, should be any string but routes must have information about controller name and action name inside) Result address should have two forms: - nice rewrited url by routes configuration (for apps with .htaccess supporting url_rewrite and when first param is key in routes configuration array) - for all other cases is url form: index.php?controller=ctrlName&action=actionName (when first param is not founded in routes configuration array) |
public
|
|
public
boolean
|
#
DispatchException( Exception $e )
Process exception: - if PHP package packing to determinate dependencies - do not log or render nothing - if production mode - log error and try to render error page by App_Controller_Default::Error(); - if development - print exception into browser |
public
|
#
RenderError( Exception $e )
Render error by Default controller Error action, if there is no controller/action like that or any other exception happends, it is processed very simple response with 500 http code. |
public
|
#
RenderNotFound( $exceptionMessage = '' )
Render not found controller action or not found plain text response. |
public
|
#
RenderError500PlainText( string $text = '' )
Process very simple internal server error (500) as plain text response. |
public
|
|
public
string
|
#
GetDefaultControllerIfHasAction( string $actionName )
Check if Default application controller ('App_Controllers_Default') has specific action. If default controller has specific action - return default controller full name, else empty string. |
public
string
|
#
CompleteControllerName( string $controllerNamePascalCase )
Complete MvcCore application controller full name always in form: 'App_Controller_$controllerNamePascalCase' |
public
boolean
|
|
public
boolean
|
|
public
boolean
|
#
IsAppRequest( )
Return true if request is on any application script, return false if request is on any asset |
string |
VERSION
MvcCore - version: Comparation by PHP function version_compare(); |
#
'4.2.0'
|
string |
COMPILED_PHP
MvcCore application mode describing that the application is compiled in one big php file. In PHP app mode should be packed php files or any asset files - phtml templates, ini files or any static files. Unknown asset files or binary files are included as binary or base64 string. This mode has always best speed, because it shoud not work with hard drive if you dont want. Only with many or with large asset files, there may be greater demands on memory and processor, which shouldn't be good for your application. Be aware to do that. Result application packed in PHP mode has special '\Packager_Php_Wrapper' class included before any application content. This special class handles allowed file operations and assets as binary or base64 encoded. Everything shoud be configured before PHP packing. This mode has always four submodes started with PHP substring. All PHP package modes are: 'PHP_PRESERVE_HDD', 'PHP_PRESERVE_PACKAGE', 'PHP_STRICT_HDD' and 'PHP_STRICT_PACKAGE'. So to check if app is in PHP package mode - check it by substr(); |
#
'PHP'
|
string |
COMPILED_PHAR
MvcCore application mode describing that the application is compiled in one big phar file. There could be any content included but there is no speed advantages, but it is still good way to pack your app into single file tool for any web-hosting needs:-) This mode has always lower speed then PHP mode, because it fully emulates hard drive for content of this file and it costs a time. But it has lower memory usage then PHP mode. |
#
'PHAR'
|
string |
COMPILED_SFU
MvcCore application mode describing that the application is in the state before their own compilation into PHP or PHAR archive. This mode is always used to generate final javascript and css files into teporary directory to pack them into result php/phar file. Shortcut SFU means "Single File Url". Application running in this mode has to generate single file urls in form: "index.php?..." and everithing has to work properly before application will be compiled into PHP/PHAR package. Use this mode in index.php before application compilation to generate and test everything necessary before app compilation by: MvcCore::GetInstance()->Run(TRUE); --> true means switch temporary into SFU mode. |
#
'SFU'
|
string |
NOT_COMPILED
MvcCore application mode describing that the application is running as standard php project in many files using autoloading or anything else. |
#
''
|
protected static
|
$instance
Application instance for current request. |
|
protected
string
|
$compiled
Describes application running as standard php project or as single file. It shoud has values 'PHP', 'PHAR', 'SFU' or ''. |
#
null
|
protected
integer
|
$microtime
Time when \MvcCore::Run has been called. |
#
0
|
protected
|
$controller
Application currently dispatched controller instance |
#
NULL
|
protected
|
$request
Request object - parsed uri, query params, app paths... |
|
protected
|
$response
Response object - headers and rendered body |
|
protected
|
$router
Application http route. |
#
null
|
protected
callable[]
|
$preRouteHandlers
Pre route custom closure calls. Params in closure function has to be: - reference for request - reference for response |
#
array()
|
protected
callable[]
|
$preDispatchHandlers
Pre dispatch custom closure calls. Params in closure function has to be: - reference for request - reference for response |
#
array()
|
protected
callable[]
|
$postDispatchHandlers
Post dispatch custom closure calls. Params in closure function has to be: - reference for request - reference for response |
#
array()
|
protected
string
|
$configClass
Class to load and parse system config. |
#
'\MvcCore\Config'
|
protected
string
|
$sessionClass
Class to configure session proxy class. |
#
'\MvcCore\Session'
|
protected
string
|
$requestClass
Class to create http request object. |
#
'\MvcCore\Request'
|
protected
string
|
$responseClass
Class to create http response object. |
#
'\MvcCore\Response'
|
protected
string
|
$routerClass
Class to create and dispatch request by its routes. |
#
'\MvcCore\Router'
|
protected
string
|
$viewClass
Class to create and render controller view. |
#
'\MvcCore\View'
|
protected
string
|
$debugClass
Class to handle any application error to render or log. |
#
'\MvcCore\Debug'
|
protected
string
|
$appDir
Application directory with subdirectories by default: 'Controllers', 'Models' and 'Views'. |
#
'App'
|
protected
string
|
$controllersDir
Controllers directory name for all controller classes, it has to be placed directly in application directory. |
#
'Controllers'
|
protected
string
|
$viewsDir
Views directory name for all view elements, it has to be placed directly in application directory. |
#
'Views'
|
protected
string
|
$defaultControllerName
Default controller name. |
#
'Index'
|
protected
string
|
$defaultControllerDefaultActionName
Default controller action name. |
#
'Index'
|
protected
string
|
$defaultControllerErrorActionName
Default controller error action name. |
#
'Error'
|
protected
string
|
$defaultControllerNotFoundActionName
Default controller error action name. |
#
'NotFound'
|