Main
final class Main extends Singleton
The main container class managing API singletons and running apps
Main is also a Singleton so it can be fetched anywhere with GetInstance(). A Main handles a single request, with an arbitrary number of appruns.
Properties
| static private | $instances | from Singleton | |
| private DBStats | $construct_stats | ||
| private RunContext[] | $action_stats | ||
| private DBStats[] | $commit_stats | ||
| private DBStats | $total_stats | ||
| private RequestLog | $reqlog | ||
| private float | $time | ||
| private BaseApp> | $apps | ||
| private RunContext[] | $stack | ||
| private Config | $config | ||
| private ObjectDatabase | $database | ||
| private ErrorManager | $error_manager | ||
| private IOInterface | $interface | ||
| private bool | $dirty | ||
| private | $dbException | ||
| private | $cfgException | ||
| private | $rolledback |
Methods
Gets the timestamp of when the request was started
Gets an array of instantiated apps
Returns true if the global ObjectDatabase instance is valid
Returns the global ObjectDatabase instance or throws if not configured
Returns the global config object or null if not installed
Returns the interface used for the current request
Returns a reference to the global error manager
Returns the RunContext that is currently being executed
Loads the main include file for an app and constructs it
Runs the given $func in try/catch and logs if exception
Rolls back the current transaction. Internal only, do not call via apps.
Commits the current transaction. Internal only, do not call via apps.
Commits the database or does a rollback if readOnly/dryrun
if false, requests are not allowed (always true for privileged interfaces)
Returns the configured debug level, or the interface's default
Compiles performance metrics and adds them to the given output
Details
at line 165
__construct(IOInterface $interface, ErrorManager $errorman)
Initializes the Main API
Creates the error manager, initializes the interface, initializes the database, loads global config, loads and constructs registered apps
at line 105
float
GetTime()
Gets the timestamp of when the request was started
at line 111
array
GetApps()
Gets an array of instantiated apps
at line 114
bool
HasDatabase()
Returns true if the global ObjectDatabase instance is valid
at line 117
ObjectDatabase
GetDatabase()
Returns the global ObjectDatabase instance or throws if not configured
at line 128
Config|null
TryGetConfig()
Returns the global config object or null if not installed
at line 131
Config
GetConfig()
Returns the global config object if installed else throws
at line 144
IOInterface
GetInterface()
Returns the interface used for the current request
at line 147
ErrorManager
GetErrorManager()
Returns a reference to the global error manager
at line 150
RunContext|null
GetContext()
Returns the RunContext that is currently being executed
at line 228
protected bool
TryLoadApp(string $app)
Loads the main include file for an app and constructs it
at line 247
Main
LoadApp(string $app)
Loads the main include file for an app and constructs it
at line 263
Run(Input $input)
Calls into an app to run the given Input command
Calls Run() on the requested app and then saves (but does not commit) any modified objects. These calls can be nested - apps can call Run for other apps but should always do so via the API, not directly to the app
at line 305
RunRemote(string $url, Input $input)
Calls into a remote API to run the given Input command
Note that this breaks transactions - the remote API will commit before we get the response to this remote call.
at line 315
static
LoggedTry(callable $func)
Runs the given $func in try/catch and logs if exception
at line 327
void
rollback(Throwable|null $e = null)
Rolls back the current transaction. Internal only, do not call via apps.
First rolls back each app, then the database, then saves mandatorySave objects if not a server error
at line 362
void
commit()
Commits the current transaction. Internal only, do not call via apps.
First commits each app, then the database. Does a rollback instead if the request was specified as a dry run.
at line 394
private void
innerCommit(bool $apps)
Commits the database or does a rollback if readOnly/dryrun
at line 407
private bool
isEnabled()
if false, requests are not allowed (always true for privileged interfaces)
at line 415
int
GetDebugLevel()
Returns the configured debug level, or the interface's default
at line 434
void
FinalizeOutput(Output $output, bool $isError = false)
Compiles performance metrics and adds them to the given output