Engine

Class System\Engine performs tasks of management of the connection of the necessary entities, content generation and wrapper generation for content. All requests for php files and folders should be redirected to a file /core/engine.php, which launches the engine.

The engine works in two stages:

Constructor

  • Initializes a session
  • Loads configuration
  • Registers autolader for classes
  • Loads the Systemmodule
  • Initializes a global database connection instance

Work Method

  • Loads information about the requested section
  • Initializes the global instance of the current user
  • Checks for access to the section
  • Generates page content (or content that displays an error that occurred during the generation of page content)
  • If required, generates a page wrapper and wraps content in it

Content Generation

The content of the requested page is generated in a pair of ShowContentand MakeContent.
The ShowContentmethod calls the method MakeContentand processes all exceptions that come from it, being thus an error-free wrapper method that displays content in any case, even if an error occurs.
The MakeContentmethod sequentially tries to generate content for the requested page:

  1. Looks for the requested file or the index.phpfile in the requested folder
  2. Looks for the .router.phpfile up the directory hierarchy (sorting through all the virtual roots)
  3. Searches for a redirect or content page in the database

In case of fail, it throws ExceptionPageNotFound, which is handled by the method ShowContent.

For more information, see Virtual Root.

Useful properties and methods of the engine

Since the engine is a common repository of all dynamically generated data, it is subject to an exception in terms of allowing modifications to the internal state of the global instance.

Access to the following properties and methods of the engine is carried out:

Properties

Title Type Description
$TITLE string Page Title
$KEYWORDS string Page Keywords
$DESCRIPTION string Page Description
$HEADERS * structure Headers to be placed in the html head block
$TEMPLATE * string Template Code
$WRAPPER string Template wrapper code
$TEMPLATE_PATH * string The path to the template folder, relative to the server root, is used to connect the template files
$SECTION * dictionary Data loaded from .section.php file
$BREADCRUMBS * dictionary Breadcrumbs
$DB object Global instance of connecting to database
$USER object The global instance of the current user
* it is not recommended to change these properties directly, use methods if possible

Methods

Title Options Description Exceptions
SetTemplate $template Installs a new template ($TEMPLATE), updates the relative path to it ($TEMPLATE_PATH)
AddHeaderStyle $path Adds a script to the headers ($HEADERS)
AddHeaderScript $path Adds style to headers ($HEADERS)
AddHeaderString $string Adds a custom string to the headers ($HEADERS)
AddDelayedCall $callable, $params = [] Creates a deferred call, returning a unique string, which will later be replaced by the result of the call
GetHeader Calls MakeHeader in deferred mode, which allows you to manipulate headers anywhere in the application
MakeHeader Combines the headers ($HEADERS) into a single line, which is printed in the html head block
ShowAuthForm $message Displays the login form
ShowErrors $errors Displays errors by including the errors.php file in the root of the active template
Show404 Displays 404 error
Show403 Displays 403 error
GetCoreFile $path Searches for a file across all active kernels, returning an absolute path to it file not found
GetCoreDirectoryAbsolute $path Searches a folder for all active kernels, returning an absolute path to it folder not found
GetCoreDirectoryRelative $path Searches the folder for all active kernels, returning the path to it relative to the server root folder not found
SearchAncestorFile $uri, $filename Searches for a file up the hierarchy of virtual root directories
GetRelativePath $absolute_path, $root_path = null Converts an absolute path to a relative
AddBreadcrumb $name, $link = null Adds breadcrumbs to the chain ($BREADCRUMBS)
GetLanguage Returns the character code of the current language
SetLanguage $language Sets the character code of the current language unknown language

Own engine

In order to supplement \ redefine the behavior of engine methods, it must be inherited to its core (and namespace) and register in the configuration in the 'redirects' section.

namespace MySite;
class Engine extends \System\Engine {

	public function Show403() {
		require($this->GetCoreFile('templates/' . $this->TEMPLATE . '/403.php'));
	}

	public function Show404() {
		require($this->GetCoreFile('templates/' . $this->TEMPLATE . '/404.php'));
	}

	public function ShowAuthForm($message = null) {
		UnitLogin::Run([
			'LINK_SUCCESS'  => '/profile/',
			'LINK_FORGOT'   => '/auth/forgot.php',
			'LINK_REGISTER' => '/auth/registration.php',
			'MESSAGE'       => $message,
		]);
	}

}

Ask question