MagratheaPHP
extends Singleton
in package
Base class for a Magrathea project.
It handles paths, configurations, database connections, and environments.
Table of Contents
Properties
- $appRoot : string
- $codeFolder : array<string|int, string>
- $magRoot : string
- $versionRequired : string|null
- $instance : array<string|int, mixed>|null
Methods
- __wakeup() : mixed
- AddCodeFolder() : MagratheaPHP
- Adds one or more code folders for the autoloader.
- AddFeature() : MagratheaPHP
- Adds feature folders based on the application root.
- AppPath() : MagratheaPHP
- Sets the application's root path.
- AppVersion() : string
- Gets the version of the application from the `version` file in the project root.
- Connect() : MagratheaPHP
- Connects to the database using credentials from the configuration.
- Debug() : MagratheaPHP
- Enables the debugger.
- Dev() : MagratheaPHP
- Sets the environment to development mode.
- GetAppRoot() : string
- Returns the root path of the application.
- GetConfigRoot() : string
- Gets the path to the configuration directory.
- GetDB() : Database
- Gets the singleton instance of the Database object.
- GetDocumentationLink() : string
- Returns the link to Magrathea's official documentation.
- GetMagratheaRoot() : string
- Gets the root directory of the MagratheaPHP library.
- Instance() : static|Singleton
- Load() : MagratheaPHP
- Starts Magrathea
- LoadVendor() : void
- Includes the Composer autoloader.
- MinVersion() : MagratheaPHP
- Checks if the current Magrathea version meets a minimum requirement.
- MockClass() : static|Singleton
- Prod() : MagratheaPHP
- Sets the environment to production mode.
- SetInstance() : mixed
- StartDB() : MagratheaPHP
- Connects to the database. Alias for `Connect()`.
- StartSession() : MagratheaPHP
- Starts a PHP session if one is not already active.
- Test() : void
- A simple test function to check if MagratheaPHP is working.
- Version() : string
- Gets Magrathea Version
- __clone() : mixed
- __construct() : mixed
Properties
$appRoot
public
string
$appRoot
= ""
Root of the application.
$codeFolder
public
array<string|int, string>
$codeFolder
= []
Folders to be included in the autoloader.
$magRoot
public
string
$magRoot
= ""
Root of the Magrathea Structure (usually one level above appRoot).
$versionRequired
public
string|null
$versionRequired
= null
Minimum version of Magrathea required.
$instance
protected
static array<string|int, mixed>|null
$instance
= []
Methods
__wakeup()
public
final __wakeup() : mixed
AddCodeFolder()
Adds one or more code folders for the autoloader.
public
AddCodeFolder(string ...$folder) : MagratheaPHP
Parameters
- $folder : string
-
One or more folder paths to add.
Return values
MagratheaPHPAddFeature()
Adds feature folders based on the application root.
public
AddFeature(string ...$features) : MagratheaPHP
For each feature, it adds features/[name] and features/[name]/Base.
Parameters
- $features : string
-
One or more feature names.
Return values
MagratheaPHPAppPath()
Sets the application's root path.
public
AppPath(string $path) : MagratheaPHP
Also defines the magRoot as the parent directory.
Parameters
- $path : string
-
Root path of the project.
Return values
MagratheaPHPAppVersion()
Gets the version of the application from the `version` file in the project root.
public
AppVersion() : string
Return values
string —Application version, or "???" if not found.
Connect()
Connects to the database using credentials from the configuration.
public
Connect() : MagratheaPHP
Return values
MagratheaPHPDebug()
Enables the debugger.
public
Debug() : MagratheaPHP
This will also log database queries.
Return values
MagratheaPHPDev()
Sets the environment to development mode.
public
Dev() : MagratheaPHP
Enables error reporting and display.
Return values
MagratheaPHPGetAppRoot()
Returns the root path of the application.
public
GetAppRoot() : string
Return values
string —Application root path.
GetConfigRoot()
Gets the path to the configuration directory.
public
GetConfigRoot() : string
Tags
Return values
string —The path to the /configs directory.
GetDB()
Gets the singleton instance of the Database object.
public
GetDB() : Database
Return values
Database —The database instance.
GetDocumentationLink()
Returns the link to Magrathea's official documentation.
public
static GetDocumentationLink() : string
Return values
string —URL for the documentation.
GetMagratheaRoot()
Gets the root directory of the MagratheaPHP library.
public
GetMagratheaRoot() : string
Return values
string —The path to the MagratheaPHP source directory.
Instance()
public
static Instance() : static|Singleton
Return values
static|SingletonLoad()
Starts Magrathea
public
Load() : MagratheaPHP
Return values
MagratheaPHPLoadVendor()
Includes the Composer autoloader.
public
static LoadVendor() : void
MinVersion()
Checks if the current Magrathea version meets a minimum requirement.
public
MinVersion(string $version[, bool $throwEx = false ]) : MagratheaPHP
Parameters
- $version : string
-
Minimum version required (e.g., "2.1.0").
- $throwEx : bool = false
-
If true, throws a MagratheaException if the version is not met. Otherwise, it displays an error message.
Tags
Return values
MagratheaPHPMockClass()
public
static MockClass(mixed $mocker) : static|Singleton
Parameters
- $mocker : mixed
Return values
static|SingletonProd()
Sets the environment to production mode.
public
Prod() : MagratheaPHP
Errors will be sent to the logger instead of being displayed.
Return values
MagratheaPHPSetInstance()
public
SetInstance(mixed $inst) : mixed
Parameters
- $inst : mixed
StartDB()
Connects to the database. Alias for `Connect()`.
public
StartDB() : MagratheaPHP
Return values
MagratheaPHPStartSession()
Starts a PHP session if one is not already active.
public
StartSession() : MagratheaPHP
Return values
MagratheaPHPTest()
A simple test function to check if MagratheaPHP is working.
public
static Test() : void
Version()
Gets Magrathea Version
public
static Version() : string
Return values
string —version
__clone()
protected
final __clone() : mixed
__construct()
private
final __construct() : mixed