Overview

Namespaces

  • MvcCore
    • Ext
      • Auth
        • Virtual
      • Debug
        • Tracy
      • Form
        • Core
        • Validators
      • Request
      • Router
        • Lang
      • View
        • Helpers
  • None

Classes

  • MvcCore
  • Overview
  • Namespace
  • Class
  • Tree

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

Copyright: Copyright (c) 2016 Tom Flídr (https://github.com/mvccore/mvccore)
License: https://mvccore.github.io/docs/mvccore/4.0.0/LICENCE.md
Located at mvccore/src/MvcCore.php
Methods summary
public static
# StaticInit( )

Static constructor (called internaly - do not call this in application). It initializes application compilation mode before \MvcCore::GetInstance()->Run();

Static constructor (called internaly - do not call this in application). It initializes application compilation mode before \MvcCore::GetInstance()->Run();

public static MvcCore &
# GetInstance( )

Returns singleton \MvcCore application instance.

Returns singleton \MvcCore application instance.

Returns

MvcCore
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

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

Parameters

$handler
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

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

Parameters

$handler
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

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

Parameters

$handler
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.

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
# GetCompiled( )

Get application compilation state value.

Get application compilation state value.

Returns

string
public string
# GetRequestClass( )

Get application request class, extended from \MvcCore\Request.

Get application request class, extended from \MvcCore\Request.

Returns

string
public string
# GetResponseClass( )

Get application response class, extended from \MvcCore\Response.

Get application response class, extended from \MvcCore\Response.

Returns

string
public string
# GetRouterClass( )

Get application router class, extended from \MvcCore\Router.

Get application router class, extended from \MvcCore\Router.

Returns

string
public string
# GetConfigClass( )

Get application config class, extended from \MvcCore\Config.

Get application config class, extended from \MvcCore\Config.

Returns

string
public string
# GetSessionClass( )

Get application session class, extended from \MvcCore\Session.

Get application session class, extended from \MvcCore\Session.

Returns

string
public string
# GetViewClass( )

Get application view class, extended from \MvcCore\View.

Get application view class, extended from \MvcCore\View.

Returns

string
public string
# GetDebugClass( )

Get application debug class, extended from \MvcCore\Debug.

Get application debug class, extended from \MvcCore\Debug.

Returns

string
public string
# GetMicrotime( )

Get microtime, when MvcCore.php has been declarated.

Get microtime, when MvcCore.php has been declarated.

Returns

string
public MvcCore\Router
# GetRouter( )

Returns currently used instance of \MvcCore\Router

Returns currently used instance of \MvcCore\Router

Returns

MvcCore\Router
public MvcCore\Controller &
# GetController( )

Returns instance of \MvcCore\Controller, currently dispatched by request.

Returns instance of \MvcCore\Controller, currently dispatched by request.

Returns

MvcCore\Controller
public MvcCore\Request &
# GetRequest( )

Get application request instance, extended from \MvcCore\Request

Get application request instance, extended from \MvcCore\Request

Returns

MvcCore\Request
public MvcCore\Response &
# GetResponse( )

Get application response instance, extended from \MvcCore\Response

Get application response instance, extended from \MvcCore\Response

Returns

MvcCore\Response
public string
# GetAppDir( )

Get application directory, where are 'Controllers', 'Models' and 'Views' directories located. 'App' value by default.

Get application directory, where are 'Controllers', 'Models' and 'Views' directories located. 'App' value by default.

Returns

string
public string
# GetControllersDir( )

Get controllers directory, where are controllers located. 'Controllers' directory shoud be located in Application directory. 'Controllers' value by default.

Get controllers directory, where are controllers located. 'Controllers' directory shoud be located in Application directory. 'Controllers' value by default.

Returns

string
public string
# GetViewsDir( )

Get views directory, where are views located. 'Views' directory shoud be located in Application directory. 'Views' value by default.

Get views directory, where are views located. 'Views' directory shoud be located in Application directory. 'Views' value by default.

Returns

string
public array
# GetDefaultControllerAndActionNames( )

Returns array with default controller name and default action nam.

Returns array with default controller name and default action nam.

Returns

array
public MvcCore
# SetCompiled( string $compiled = '' )

Set application compilation state value.

Set application compilation state value.

Parameters

$compiled

Returns

MvcCore
public MvcCore
# SetConfigClass( string $configClass )

Set config class, extended from \MvcCore\Config. Core configuration method.

Set config class, extended from \MvcCore\Config. Core configuration method.

Parameters

$configClass

Returns

MvcCore
public MvcCore
# SetSessionClass( string $sessionClass )

Set session class, extended from \MvcCore\Session. Core configuration method.

Set session class, extended from \MvcCore\Session. Core configuration method.

Parameters

$sessionClass

Returns

MvcCore
public MvcCore
# SetRequestClass( string $requestClass )

Set request class, extended from \MvcCore\Request. Core configuration method.

Set request class, extended from \MvcCore\Request. Core configuration method.

Parameters

$requestClass

Returns

MvcCore
public MvcCore
# SetResponseClass( string $responseClass )

Set request class, extended from \MvcCore\Response. Core configuration method.

Set request class, extended from \MvcCore\Response. Core configuration method.

Parameters

$responseClass

Returns

MvcCore
public MvcCore
# SetRouterClass( string $routerClass )

Set router class, extended from \MvcCore\Router. Core configuration method.

Set router class, extended from \MvcCore\Router. Core configuration method.

Parameters

$routerClass

Returns

MvcCore
public MvcCore
# SetViewClass( string $viewClass )

Set view class, extended from \MvcCore\View. Core configuration method.

Set view class, extended from \MvcCore\View. Core configuration method.

Parameters

$viewClass

Returns

MvcCore
public MvcCore
# SetDebugClass( string $debugClass )

Set debug class, extended from \MvcCore\Debug. Core configuration method.

Set debug class, extended from \MvcCore\Debug. Core configuration method.

Parameters

$debugClass

Returns

MvcCore
public MvcCore
# SetAppDir( string $appDir )

Set application directory, where are 'Controllers', 'Models' and 'Views' directories located. 'App' value by default. Core configuration method.

Set application directory, where are 'Controllers', 'Models' and 'Views' directories located. 'App' value by default. Core configuration method.

Parameters

$appDir

Returns

MvcCore
public MvcCore
# 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.

Set controllers directory, where are controllers located. 'Controllers' directory shoud be located in Application directory. 'Controllers' value by default. Core configuration method.

Parameters

$controllersDir

Returns

MvcCore
public MvcCore
# 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.

Set views directory, where are views located. 'Views' directory shoud be located in Application directory. 'Views' value by default. Core configuration method.

Parameters

$viewsDir

Returns

MvcCore
public MvcCore
# SetDefaultControllerName( string $defaultControllerName )

Set default controller name. 'Default' value by default. Core configuration method.

Set default controller name. 'Default' value by default. Core configuration method.

Parameters

$defaultControllerName

Returns

MvcCore
public MvcCore
# SetDefaultControllerDefaultActionName( string $defaultActionName )

Set default controller default action name. 'Default' value by default. Core configuration method.

Set default controller default action name. 'Default' value by default. Core configuration method.

Parameters

$defaultActionName

Returns

MvcCore
public MvcCore
# SetDefaultControllerErrorActionName( string $defaultControllerErrorActionName )

Set default controller common error action name. 'Error' value by default. Core configuration method.

Set default controller common error action name. 'Error' value by default. Core configuration method.

Parameters

$defaultControllerErrorActionName

Returns

MvcCore
public MvcCore
# SetDefaultControllerNotFoundActionName( string $defaultControllerNotFoundActionName )

Set default controller not found error action name. 'NotFound' value by default. Core configuration method.

Set default controller not found error action name. 'NotFound' value by default. Core configuration method.

Parameters

$defaultControllerNotFoundActionName

Returns

MvcCore
public MvcCore
# Run( boolean $singleFileUrl = FALSE )

Run application.

Run application.

Parameters

$singleFileUrl
Set 'Single File Url' mode to compile assets and test everything before compilation

Returns

MvcCore
protected MvcCore
# 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

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

Returns

MvcCore
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();

Route request by router obtained by \MvcCore\Router::GetInstance(); Store requested route inside router class to get it later by: MvcCore\Router::GetCurrentRoute();

Returns

boolean
protected boolean
# processCustomHandlers( callable[] & $handlers = array() )

Process preroute, prerequest and postdispatch handlers queue by queues index

Process preroute, prerequest and postdispatch handlers queue by queues index

Parameters

$handlers

Returns

boolean
public boolean
# DispatchMvcRequest( MvcCore\Route & $route = NULL, MvcCore\Route $route,… )

If controller class exists - try to dispatch controller, if only view file exists - try to render this view file.

If controller class exists - try to dispatch controller, if only view file exists - try to render this view file.

Parameters

$route
$request
$route,…

Returns

boolean
public boolean
# DispatchControllerAction( string $controllerClassFullName, string $actionName, callable $viewScriptFullPath, callable $exceptionCallback )

Dispatch controller by full class name and by action name.

Dispatch controller by full class name and by action name.

Parameters

$controllerClassFullName
$actionName
$viewScriptFullPath
$exceptionCallback
$exceptionCallback

Returns

boolean
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)

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)

Parameters

$controllerActionOrRouteName
Should be 'Controller:Action' combination or just any route name as custom specific string
$params
optional

Returns

string
public
# Terminate( )

Terminates any request, writes session and exits. The only place in application where is called 'echo ....';

Terminates any request, writes session and exits. The only place in application where is called 'echo ....';

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

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

Parameters

$e

Returns

boolean
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.

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.

Parameters

$e
public
# RenderNotFound( $exceptionMessage = '' )

Render not found controller action or not found plain text response.

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.

Process very simple internal server error (500) as plain text response.

Parameters

$text
public
# RenderError404PlainText( )

Process very simple not found error (404) as plain text response.

Process very simple not found error (404) as plain text response.

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.

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.

Parameters

$actionName

Returns

string
public string
# CompleteControllerName( string $controllerNamePascalCase )

Complete MvcCore application controller full name always in form: 'App_Controller_$controllerNamePascalCase'

Complete MvcCore application controller full name always in form: 'App_Controller_$controllerNamePascalCase'

Parameters

$controllerNamePascalCase

Returns

string
public boolean
# IsErrorDispatched( )

Return if this is default controller error action dispatching process

Return if this is default controller error action dispatching process

Returns

boolean
public boolean
# IsNotFoundDispatched( )

Return if this is default controller not found action dispatching process

Return if this is default controller not found action dispatching process

Returns

boolean
public boolean
# IsAppRequest( )

Return true if request is on any application script, return false if request is on any asset

Return true if request is on any application script, return false if request is on any asset

Returns

boolean
Constants summary
string VERSION

MvcCore - version: Comparation by PHP function version_compare();

MvcCore - version: Comparation by PHP function version_compare();

See

http://php.net/manual/en/function.version-compare.php
# '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();

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.

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.

See

http://php.net/manual/en/phar.creating.php
# '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.

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.

MvcCore application mode describing that the application is running as standard php project in many files using autoloading or anything else.

# ''
Properties summary
protected static MvcCore $instance

Application instance for current request.

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 ''.

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.

Time when \MvcCore::Run has been called.

# 0
protected MvcCore\Controller $controller

Application currently dispatched controller instance

Application currently dispatched controller instance

# NULL
protected MvcCore\Request $request

Request object - parsed uri, query params, app paths...

Request object - parsed uri, query params, app paths...

#
protected MvcCore\Response $response

Response object - headers and rendered body

Response object - headers and rendered body

#
protected MvcCore\Router $router

Application http route.

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

Pre route custom closure calls. Params in closure function has to be: - reference for request - reference for response

Example

\MvcCore::AddPreRouteHandler(function (\MvcCore\Request & $request, \MvcCore\Response & $response) { $request->customVar = 'custom_value'; });


# array()
protected callable[] $preDispatchHandlers

Pre dispatch custom closure calls. Params in closure function has to be: - reference for request - reference for response

Pre dispatch custom closure calls. Params in closure function has to be: - reference for request - reference for response

Example

\MvcCore::AddPreDispatchHandler(function (\MvcCore\Request & $request, \MvcCore\Response & $response) { $request->customVar = 'custom_value'; });


# array()
protected callable[] $postDispatchHandlers

Post dispatch custom closure calls. Params in closure function has to be: - reference for request - reference for response

Post dispatch custom closure calls. Params in closure function has to be: - reference for request - reference for response

Example

\MvcCore::AddPostDispatchHandler(function (\MvcCore\Request & $request, \MvcCore\Response & $response) { $response->Output = 'custom_value'; });


# array()
protected string $configClass

Class to load and parse system config.

Class to load and parse system config.

# '\MvcCore\Config'
protected string $sessionClass

Class to configure session proxy class.

Class to configure session proxy class.

# '\MvcCore\Session'
protected string $requestClass

Class to create http request object.

Class to create http request object.

# '\MvcCore\Request'
protected string $responseClass

Class to create http response object.

Class to create http response object.

# '\MvcCore\Response'
protected string $routerClass

Class to create and dispatch request by its routes.

Class to create and dispatch request by its routes.

# '\MvcCore\Router'
protected string $viewClass

Class to create and render controller view.

Class to create and render controller view.

# '\MvcCore\View'
protected string $debugClass

Class to handle any application error to render or log.

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'.

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 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 directory name for all view elements, it has to be placed directly in application directory.

# 'Views'
protected string $defaultControllerName

Default controller name.

Default controller name.

# 'Index'
protected string $defaultControllerDefaultActionName

Default controller action name.

Default controller action name.

# 'Index'
protected string $defaultControllerErrorActionName

Default controller error action name.

Default controller error action name.

# 'Error'
protected string $defaultControllerNotFoundActionName

Default controller error action name.

Default controller error action name.

# 'NotFound'
MvcCore API documentation generated by ApiGen