Documentation

SC_Main
in package

The main orchestrator for SimplOn applications.

This central class is responsible for initializing the application environment, decoding incoming URLs, handling configuration, managing permissions, autoloading classes, and executing the requested actions. It serves as the primary entry point and controller for the framework.

Key Responsibilities:

  • Loading configuration from INI files or arrays.
  • Setting up global application parameters (paths, database, renderer, etc.).
  • Decoding URLs based on the SimplOn HTTP API structure: /Element/constructParam1/..!Method/methodParam1.. /Element/constructParam1/..!DataName!Method/methodParam1..
  • Managing user sessions and permissions via a configurable permission class.
  • Handling language settings and providing a translation mechanism.
  • Autoloading SimplOn core, element, data, storage, renderer, and application classes.
  • Instantiating the target Element and executing the requested method after permission checks.
Tags
author

Luca Lauretta, RSL

version
1b.1.0

Table of Contents

DEFAULT_INI  = 'dof.ini'
$App_Name  : string
$App_Name  : mixed
$App_PATH  : string
$App_PATH  : mixed
$App_web_root  : string
$App_web_root  : mixed
$class  : string
$class  : mixed
$construct_params  : array<string|int, mixed>
$construct_params  : mixed
$DATA_STORAGE  : array<string|int, mixed>|SDS_DataStorage
$DATA_STORAGE  : SDS_DataStorage
$dataName  : string|null
$dataName  : mixed
$debug_mode  : bool
$debug_mode  : mixed
$DEFAULT_ELEMENT  : string
$DEFAULT_ELEMENT  : mixed
$DEFAULT_METHOD  : string
$DEFAULT_METHOD  : mixed
$DEV_MODE  : bool
$DEV_MODE  : mixed
$LANG  : string
$LANG  : mixed
$LangArray  : array<string|int, mixed>
$LangArray  : mixed
$LIMIT_ELEMENTS  : int
$LIMIT_ELEMENTS  : mixed
$LOAD_ROLE_CLASS  : bool
$LOAD_ROLE_CLASS  : mixed
$LOCAL_ROOT  : string
$LOCAL_ROOT  : mixed
$method  : string
$method  : mixed
$method_params  : array<string|int, mixed>
$method_params  : mixed
$PERMISSIONS  : string|object|bool
$PERMISSIONS  : mixed
$QUICK_DELETE  : bool
$QUICK_DELETE  : mixed
$RENDERER  : SR_htmlJQuery
$RENDERER  : SR_htmlJQuery
$RENDERER_FLAVOR  : string
$RENDERER_FLAVOR  : mixed
$SimplOn_PATH  : string
$SimplOn_PATH  : mixed
$SystemMessage  : string
$SystemMessage  : mixed
$URL_METHOD_SEPARATOR  : string
$URL_METHOD_SEPARATOR  : mixed
$VCRSL  : array<string|int, mixed>
$VCRSL  : mixed
$VCRSLMethods  : array<string|int, string>
$VCRSLMethods  : mixed
$WEB_ROOT  : string
$WEB_ROOT  : mixed
dataStorage()  : mixed
Returns the Data Storage
decodeURL()  : mixed
Gets URL and breaks it into the class and method that needs to be executed as well as the message that has to be displayed
fillFromArray()  : mixed
Loads all the staic constants from ana array
L()  : string
Retrieves a translated string for a given key from the loaded language array.
load_obj()  : mixed
Loads objects looking for the file by looking into the first letters of the class name
render()  : mixed
run()  : void
The main execution entry point for the SimplOn application.
setup()  : void
Initializes the SimplOn application environment by loading configuration, setting up error reporting, handling permissions, and decoding the incoming URL.
writeLangFile()  : void
Writes the current contents of `self::$LangArray` to the corresponding language file based on the configured language (`self::$LANG`) and renderer path.

Constants

DEFAULT_INI

public mixed DEFAULT_INI = 'dof.ini'

Properties

$App_Name

public string $App_Name

Name of the application.

$App_Name

public static mixed $App_Name

$App_PATH

public string $App_PATH

Server's absolute path to the application's code directory.

$App_PATH

public static mixed $App_PATH

$App_web_root

public string $App_web_root

Web URL corresponding to $App_PATH (often within $WEB_ROOT).

$App_web_root

public static mixed $App_web_root

$class

public string $class

The Element class name decoded from the URL.

$construct_params

public array<string|int, mixed> $construct_params

Parameters for the Element's constructor, decoded from the URL.

$construct_params

public static mixed $construct_params

$DATA_STORAGE

public array<string|int, mixed>|SDS_DataStorage $DATA_STORAGE

Configuration array for the data storage driver or the instantiated DataStorage object.

$dataName

public string|null $dataName

The Data name if a Data method is being called, decoded from the URL.

$dataName

public static mixed $dataName

$debug_mode

public bool $debug_mode

If true, enables detailed error reporting for development.

$debug_mode

public static mixed $debug_mode

$DEFAULT_ELEMENT

public string $DEFAULT_ELEMENT

The default Element class to use if none is specified in the URL.

$DEFAULT_ELEMENT

public static mixed $DEFAULT_ELEMENT

$DEFAULT_METHOD

public string $DEFAULT_METHOD

The default method to call on an Element if none is specified.

$DEFAULT_METHOD

public static mixed $DEFAULT_METHOD

$DEV_MODE

public bool $DEV_MODE

If true, enables development-specific settings (potentially overlaps with debug_mode).

$DEV_MODE

public static mixed $DEV_MODE

$LANG

public string $LANG

The current language code (e.g., 'en', 'es').

$LangArray

public array<string|int, mixed> $LangArray

Associative array holding language translations [key => translation].

$LangArray

public static mixed $LangArray

$LIMIT_ELEMENTS

public int $LIMIT_ELEMENTS

Default limit for listing elements in administrative views.

$LIMIT_ELEMENTS

public static mixed $LIMIT_ELEMENTS

$LOAD_ROLE_CLASS

public bool $LOAD_ROLE_CLASS

Whether to load a specific subclass of the $PERMISSIONS class based on user role.

$LOAD_ROLE_CLASS

public static mixed $LOAD_ROLE_CLASS

$LOCAL_ROOT

public string $LOCAL_ROOT

Server's absolute path to the main public directory.

$LOCAL_ROOT

public static mixed $LOCAL_ROOT

$method

public string $method

The method name decoded from the URL.

$method

public static mixed $method

$method_params

public array<string|int, mixed> $method_params

Parameters for the method, decoded from the URL.

$method_params

public static mixed $method_params

$PERMISSIONS

public string|object|bool $PERMISSIONS

Class name or instance responsible for handling permissions (e.g., 'SE_User'). Set to false to disable.

$PERMISSIONS

public static mixed $PERMISSIONS

$QUICK_DELETE

public bool $QUICK_DELETE

If true, allows deletion without confirmation prompts.

$QUICK_DELETE

public static mixed $QUICK_DELETE

$RENDERER_FLAVOR

public string $RENDERER_FLAVOR

The specific flavor/directory name of the renderer being used (e.g., 'htmlJQuery').

$RENDERER_FLAVOR

public static mixed $RENDERER_FLAVOR

$SimplOn_PATH

public string $SimplOn_PATH

Server's absolute path to the SimplOn framework directory.

$SimplOn_PATH

public static mixed $SimplOn_PATH

$SystemMessage

public string $SystemMessage

A message to be displayed to the user, often set during redirects.

$SystemMessage

public static mixed $SystemMessage

$URL_METHOD_SEPARATOR

public string $URL_METHOD_SEPARATOR

Character used to separate Element/Data from Method in the URL (default: '!').

$URL_METHOD_SEPARATOR

public static mixed $URL_METHOD_SEPARATOR

$VCRSL

public array<string|int, mixed> $VCRSL

Configuration for View-Create-Read-Search-List flags (Likely internal).

$VCRSLMethods

public array<string|int, string> $VCRSLMethods

List of standard VCRSL method flags.

$VCRSLMethods

public static mixed $VCRSLMethods

$WEB_ROOT

public string $WEB_ROOT

Web URL corresponding to $LOCAL_ROOT.

$WEB_ROOT

public static mixed $WEB_ROOT

Methods

dataStorage()

Returns the Data Storage

public static dataStorage() : mixed

Since self::$DATA_STORAGE can be either the proper Data Storage objecct or an array with the connection type and dat if it's the later it istanciates a proper Data Storage object

Return values
mixed

decodeURL()

Gets URL and breaks it into the class and method that needs to be executed as well as the message that has to be displayed

public static decodeURL() : mixed

This function parses the request URI to determine the target class, method, and associated parameters based on the defined URL structure.

Tags
modifies

SC_Main::$class The Element class name decoded from the URL.

modifies

SC_Main::$construct_params Parameters for the Element's constructor, decoded from the URL.

modifies

SC_Main::$dataName The Data name if a Data method is being called, decoded from the URL.

modifies

SC_Main::$method The method name decoded from the URL.

modifies

SC_Main::$method_params Parameters for the method, decoded from the URL.

Return values
mixed

fillFromArray()

Loads all the staic constants from ana array

public static fillFromArray(array<string|int, mixed> $ini) : mixed
Parameters
$ini : array<string|int, mixed>
Return values
mixed

L()

Retrieves a translated string for a given key from the loaded language array.

public static L(string $key) : string

If the key does not exist in the current language array (self::$LangArray), the key itself is returned, and the key-value pair is added to the array for potential later writing to the language file by writeLangFile().

This function serves as the primary method for internationalization within the SimplOn framework.

Parameters
$key : string

The key of the string to retrieve from the language array.

Return values
string

The translated string if the key exists, otherwise the key itself.

load_obj()

Loads objects looking for the file by looking into the first letters of the class name

public static load_obj(mixed $classToLoad) : mixed
Parameters
$classToLoad : mixed
Return values
mixed

render()

public static render(mixed $item) : mixed
Parameters
$item : mixed
Return values
mixed

run()

The main execution entry point for the SimplOn application.

public static run([mixed $ini = null ]) : void

This method orchestrates the entire request lifecycle. It first calls the setup method to initialize the application environment, load configuration, and process the incoming URL. It then attempts to instantiate the target class identified by the URL and execute the requested method with the decoded parameters. It also incorporates permission checks if a permission class is configured and writes the language file at the end.

If the target class is not found, a 404 header is sent and a PHP error is triggered.

Parameters
$ini : mixed = null

Optional. Can be either the path to an INI file or an array containing configuration parameters to override defaults.

Return values
void

This method outputs content directly and does not return a value on successful execution, except in the case of a class not found error.

setup()

Initializes the SimplOn application environment by loading configuration, setting up error reporting, handling permissions, and decoding the incoming URL.

public static setup([mixed $ini = null ]) : void

This method first attempts to load configuration from the default INI file (dof.ini). If an $ini parameter is provided (either a path to an INI file or an associative array), it will override the default configuration.

It then configures PHP error reporting based on the DEV_MODE setting.

If a permission class is configured (self::$PERMISSIONS), it instantiates the permission class, ensures the necessary storage for it, and attempts to load a logged-in user based on the session. If no users are found in the database, a temporary AE_EmptyAdmin is instantiated to allow initial user creation. Default element and method might be overridden by the permission object's settings. It also handles loading a role-specific subclass if self::$LOAD_ROLE_CLASS is true and a user role is detected.

Finally, it calls self::decodeURL() to parse the request URI.

Parameters
$ini : mixed = null

Optional. Can be either the absolute path to an INI file (string) or an associative array containing configuration parameters. These parameters will override any settings loaded from the default INI file. Defaults to null.

Return values
void

writeLangFile()

Writes the current contents of `self::$LangArray` to the corresponding language file based on the configured language (`self::$LANG`) and renderer path.

public static writeLangFile() : void

This function serializes the associative array into a PHP file format that can be later included to load the translations. It's typically called at the end of a request lifecycle (e.g., within the run() method) to persist any new language keys encountered during the request.

Note: This method assumes the renderer object (self::$RENDERER) has a SimplOn_path() method to determine the base path for language files.

Return values
void

Search results