Skip to content
eblludu247@gmail.com edited this page Oct 16, 2021 · 5 revisions

Class: Application

Namespace: Afoslt\Core

Parent: -

Modifiers: -

Afoslt framework application class.


Constants

  • RESPONSE_OK: 0

Response code: everything is cool.

  • RESPONSE_ERROR_NO_MANIFEST: -1

Error code: application could not find manifest file.

  • RESPONSE_ERROR_NO_MATCH_ROUTE: 404

Error code: application could not find routes matching with client's request.

  • RESPONSE_ERROR_NO_MATCH_ROUTE: -2

Error code: application could not find requested controller class.

  • RESPONSE_ERROR_ACTION_DOEST_EXISTS: -3

Error code: requested controller does not have requested action.

Fields

$manifest

Modifiers: static private

Associative array of properties, that defines how application will initialize.

By default value for array stored in \config\manifest.php.

Default keys:

  • "routesDirectory" - Relative path to directory with routes files. _DEFAULT VALUE: _ "config\\routes\\"
  • "readGetPost" - Add keys and values from arrays $_GET and $_POST. _DEFAULT VALUE: _ true
  • "addKeywords" - Tells application to add keywords to controllers and actions name, when search for them. _DEFAULT VALUE: _ true
  • "controllersKeyword" - Keyword for Controllers. _DEFAULT VALUE: _ "Controller"
  • "actionsKeyword" - Keyword for Actions. _DEFAULT VALUE: _ "Action"
  • "build" - Defines work mode that application will use. _DEFAULT VALUE: _ BUILD_DEBUG
  • "startupSession" - Defines that session_start() will be called or not.

If default key is not defined in manifest file, application will use default value for that key.

$arguments

Modifiers: static private

Associative array with arguments that application gets on startup from client request.

Arguments collect all values from GET, POST and Routes.

Priority of variables source:

  1. Routes
  2. POST
  3. GET

This priority list means that arguments with same keys will replace one another.

$router

Modifiers: private

Instance of class Router for instance of Application.

$configuration

Modifiers: static private

Associative array for storing values from configurations files.

$requestURI

Modifiers: static private

Client's request to application. By default it's equals to $_SERVER_["REQUEST_URI"].

$layoutName

Modifiers: static private

Name of layout's file that will be used for view render.

Properties

SetManifest (array $manifest): void

Modifiers: static protected final

Setter for field $manifest.

GetArguments (): array

Modifiers: static public final

Getter for field $arguments.

AddArguments (string $name, mixed $value): void

Modifiers: static public final

Add for field $arguments.

Adds new arguments with key $key and value $value.

SetRouter(Router $router): void

Modifiers: protected final

Setter for field $router.

GetRouter(): Router

Modifiers: protected final

Getter for field $router.

AddConfiguration (array $configValues): void

Modifiers: static protected final

Add for field $configuration.

Adds all keys their values from incoming array to configuration associative array of an applicaiton.

GetConfiguration(): array

Modifiers: static public final

Getter for field $configuration.

SetRequestURI(string $requestURI): void

Modifiers: static private

Setter for field $requestURI.

GetRequestURI(): string

Modifiers: static public final

Getter for field $requestURI.

SetLayout(?string $layoutName):

Modifiers: static protected final

Setter for field $layoutName.

GetLayout(): string

Modifiers: static public final

Getter for field $layoutName.

Methods

__construct ()

Modifiers: public final

Constructor method of application class instance.

In first place constructor will define constants:

  • PATH_APPLICATION - path to application directory.

And load other constants defined in file Constants.php

Then constructor will call instance's methods in order:

  • LoadManifest()
  • SetRouter()
  • OnReady()
  • Main()

After loading application manifest and before calling method OnReady() application will create instance of Router for reading avaible routes and client's request.

LoadManifest (): void

Modifiers: private

Loading settings from manifest file by default path \config\manifest.php.

LoadRoutes (): array

Modifiers: private

Loading routes from all files in application routes directory. This method will also scan subdirectories for routes files.

Returns merge associative array of all associative arrays in routes directory.

LoadConfiguration (string $relativeCfgPath): bool

Modifiers: public final

Loading configuration file from configuration folder. Configuration files must have php extension and return an associative array.

Path to configuration file must be relative to configurations directory.

Returns true if configuration from file loaded successfully.

DropApplication(int $code, string $message): bool

Modifiers: protected

Application errors handler.

OnReady(mixed $result): void

Modifiers: protected

This method will get result of controller's action method and show it to the client.

If action returns instance of View, this method will echo layout and view.

If action return array, application will encode it as JSON and return to the client.

OnReady(): void

Modifiers: protected

This method executes before Main.

This is method where you can set up environment, before application will create controller and call action.

Main(): void

Modifiers: private

Entry point of Application.

It will call method to read user's request and create controller.