AppFactory
in package
Table of Contents
- $app : App
- $appDirPath : string
- $environment : string|null
- $httpFactory : HostManager
- $ipResolver : ClientIpResolver
- $request : ServerRequestInterface
- $tenantResolver : Tenant
- __construct() : mixed
- AppFactory constructor.
- create() : App
- Static factory method for backward compatibility and convenience.
- init() : App
- Creates and configures the application instance.
- run() : void
- Runs the created application.
- copyConfigSampleFile() : void
- Copies <configs>/<file>.php ➜ <configs>/<file>.sample.php – Does nothing if the user‑specific file already exists.
- createPrivateDir() : void
- Create private directory if it doesn't exist.
- createRequest() : ServerRequestInterface
- Create server request instance.
- defineInitialConstants() : void
- Define initial constants required by the application.
- defineMandatoryConstants() : null|ConstantBuilder
- Define mandatory application constants.
- getEnvironmentFiles() : array<string|int, mixed>
- Get environment files for the application.
- getTenant() : mixed
- Get tenant information from the request.
- loadDotEnv() : void
- Load dot environment files.
- loadZeroConfig() : void
- Load zero configuration file if it exists.
- setAppDirectoryPath() : string
- Sets the application directory path by locating the Composer autoloader.
- setEnvironment() : void
- Set the environment type for the application.
- setErrorHandler() : void
- Set up error handler for the application.
- setupContainer() : Bindings
- Set up the dependency injection container.
- setupEnvironment() : void
- Set up the application environment.
Properties
$app
private
App
$app
$appDirPath
private
string
$appDirPath
$environment
private
string|null
$environment
$httpFactory
private
HostManager
$httpFactory
$ipResolver
private
ClientIpResolver
$ipResolver
$request
private
ServerRequestInterface
$request
$tenantResolver
private
Tenant
$tenantResolver
Methods
__construct()
AppFactory constructor.
public
__construct(string $appDirPath[, null|string $environment = null ][, null|ServerRequestInterface $request = null ][, null|ClientIpResolver $ipResolver = null ][, null|Tenant $tenantResolver = null ][, null|HostManager $httpFactory = null ]) : mixed
Parameters
- $appDirPath : string
-
The directory path for the application
- $environment : null|string = null
-
The environment setting
- $request : null|ServerRequestInterface = null
-
Optional server request
- $ipResolver : null|ClientIpResolver = null
-
Optional IP resolver
- $tenantResolver : null|Tenant = null
-
Optional tenant resolver
- $httpFactory : null|HostManager = null
-
Optional HTTP factory
Return values
mixed —create()
Static factory method for backward compatibility and convenience.
public
static create(string $appDirPath[, null|string $environment = null ][, null|ServerRequestInterface $request = null ]) : App
Parameters
- $appDirPath : string
-
The directory path for the application.
- $environment : null|string = null
-
The environment setting, e.g., 'development', 'production'.
- $request : null|ServerRequestInterface = null
-
Optional server request
Return values
App —An initialized App instance.
init()
Creates and configures the application instance.
public
init() : App
Return values
App —An initialized App instance.
run()
Runs the created application.
public
run() : void
Tags
Return values
void —copyConfigSampleFile()
Copies <configs>/<file>.php ➜ <configs>/<file>.sample.php – Does nothing if the user‑specific file already exists.
private
copyConfigSampleFile(string $file, Container $c) : void
Parameters
- $file : string
-
Basename without extension (e.g. 'constants', 'app')
- $c : Container
-
PSR‑11 container with
filesystem
+configs
Return values
void —createPrivateDir()
Create private directory if it doesn't exist.
private
createPrivateDir(Container $psrContainer) : void
Parameters
- $psrContainer : Container
-
PSR-11 container
Return values
void —createRequest()
Create server request instance.
private
createRequest([null|ServerRequestInterface $request = null ]) : ServerRequestInterface
Parameters
- $request : null|ServerRequestInterface = null
-
Optional server request
Return values
ServerRequestInterface —Server request instance
defineInitialConstants()
Define initial constants required by the application.
private
defineInitialConstants(null|TenantInfo $tenantInfo) : void
Parameters
- $tenantInfo : null|TenantInfo
-
Tenant information
Return values
void —defineMandatoryConstants()
Define mandatory application constants.
private
defineMandatoryConstants(string $httpHost, string $peerIp, ServerRequestInterface $request) : null|ConstantBuilder
Parameters
- $httpHost : string
-
HTTP host
- $peerIp : string
-
Peer IP address
- $request : ServerRequestInterface
-
Server request
Return values
null|ConstantBuilder —Constant builder instance or null if in test mode
getEnvironmentFiles()
Get environment files for the application.
private
getEnvironmentFiles(EnvType $envType) : array<string|int, mixed>
Parameters
- $envType : EnvType
-
Environment type instance
Return values
array<string|int, mixed> —List of environment files
getTenant()
Get tenant information from the request.
private
getTenant(ServerRequestInterface $request) : mixed
Parameters
- $request : ServerRequestInterface
-
Server request
Return values
mixed —Tenant information
loadDotEnv()
Load dot environment files.
private
loadDotEnv(array<string|int, mixed> $envFiles, EnvType $envType) : void
Parameters
- $envFiles : array<string|int, mixed>
-
Environment files
- $envType : EnvType
-
Environment type instance
Return values
void —loadZeroConfig()
Load zero configuration file if it exists.
private
loadZeroConfig() : void
Return values
void —setAppDirectoryPath()
Sets the application directory path by locating the Composer autoloader.
private
static setAppDirectoryPath(string $appDirPath) : string
Parameters
- $appDirPath : string
-
The initial application directory path
Tags
Return values
string —The resolved application directory path
setEnvironment()
Set the environment type for the application.
private
setEnvironment() : void
This function sets the environment type by defining the RAYDIUM_ENVIRONMENT_TYPE
constant.
If the environment type is not provided, it defaults to null
and can fallback to .env
file setup.
Usage:
- If
$environment
is provided, it will define theRAYDIUM_ENVIRONMENT_TYPE
. - If
$environment
isnull
, the function will allow the.env
file to define the environment type.
Return values
void —setErrorHandler()
Set up error handler for the application.
private
setErrorHandler() : void
Return values
void —setupContainer()
Set up the dependency injection container.
private
setupContainer() : Bindings
Return values
Bindings —Container bindings instance
setupEnvironment()
Set up the application environment.
private
setupEnvironment(array<string|int, mixed> $envFiles, EnvType $envType, Container $psrContainer) : void
Parameters
- $envFiles : array<string|int, mixed>
-
Environment files
- $envType : EnvType
-
Environment type instance
- $psrContainer : Container
-
PSR-11 container