ShopEnv
in package
uses
Loggable
Shop Environment Manager
Handles shop environment configuration, settings, paths, and access control. Manages environment-specific settings, logging, error handling, and maintenance mode.
Table of Contents
Properties
- $globalPaths : array<string|int, mixed>
- $settings : array<string|int, mixed>
- $shopEnvironment : string
- $isIpAllowed : bool
- $envFilePath : string|null
- $errorPage : string
- $isMinifyEnabled : bool
- $logger : object|null
- $logHelperEnabled : bool
- $maintenancePage : string
- $moduleName : string
- $shopName : string
Methods
- __construct() : mixed
- Constructor
- convertSettingsToArrays() : void
- Converts specified settings to arrays
- createFolders() : void
- Creates folders and checks write permissions
- getClientIpAdress() : string
- Gets client IP address
- getGlobalPath() : string
- Gets global path by key
- getModuleName() : string
- Gets current module name
- getSettings() : array<string|int, mixed>
- Gets current shop settings
- getShopName() : string
- Gets shop name
- initialize() : mixed
- Initializes shop environment
- isIpAllowed() : bool
- Checks if IP is allowed
- loadConfig() : array<string|int, mixed>
- Loads shop settings from a .env file.
- log() : void
- redirectToError() : void
- Redirects to error page
- redirectToMaintenance() : void
- Redirects to maintenance page
- setDisplayErrors() : void
- Sets display errors setting
- setEnvFile() : void
- Sets environment file path
- setGlobalPaths() : void
- Sets global path constants
- setLogger() : mixed
- Sets logger instance
- setLogHelper() : void
- Sets logging helper status
- setLogLevel() : void
- Sets logging level
- setMinifying() : void
- Sets minification status
- setModuleName() : void
- Sets current module name
- setSettings() : void
- Updates shop settings
- setShopEnvironment() : void
- Sets shop environment
- setShopName() : void
- Sets shop name
- validateUserAccess() : void
- Validates user access based on IP and maintenance mode
- convertStringsToArrays() : array<string|int, mixed>
- Converts string settings to arrays
- findConfig() : string|null
- Finds configuration file
Properties
$globalPaths
public
array<string|int, mixed>
$globalPaths
= []
Global path constants (ROOT_PATH, SHOP_PATH, LOG_PATH)
$settings
public
array<string|int, mixed>
$settings
= []
Shop settings loaded from environment file
$shopEnvironment
public
string
$shopEnvironment
= ''
Current shop environment (e.g. 'dev', 'test', 'live')
$isIpAllowed
protected
bool
$isIpAllowed
= true
Whether current IP is allowed access
$envFilePath
private
string|null
$envFilePath
= null
Path to the environment configuration file
$errorPage
private
string
$errorPage
= 'error.php'
Path to error page
$isMinifyEnabled
private
bool
$isMinifyEnabled
= false
Whether minification is enabled
$logger
private
object|null
$logger
= null
$logHelperEnabled
private
bool
$logHelperEnabled
= true
Whether logging helper is enabled
$maintenancePage
private
string
$maintenancePage
= 'error.php?maintenance=1'
Path to maintenance page
$moduleName
private
string
$moduleName
= 'undefined'
Current module name
$shopName
private
string
$shopName
= ''
Shop name identifier
Methods
__construct()
Constructor
public
__construct([string $shopEnvironment = '' ][, string $configFile = '' ]) : mixed
Parameters
- $shopEnvironment : string = ''
-
Shop environment identifier
- $configFile : string = ''
-
Path to configuration file
convertSettingsToArrays()
Converts specified settings to arrays
public
convertSettingsToArrays(array<string|int, mixed> $keysToConvert) : void
Parameters
- $keysToConvert : array<string|int, mixed>
-
Array of setting keys to convert
createFolders()
Creates folders and checks write permissions
public
createFolders(array<string|int, mixed> $folderPaths) : void
Parameters
- $folderPaths : array<string|int, mixed>
-
Array of folder paths to create
getClientIpAdress()
Gets client IP address
public
getClientIpAdress() : string
Return values
string —Client IP address
getGlobalPath()
Gets global path by key
public
getGlobalPath([string $path = 'SHOP_PATH' ]) : string
Parameters
- $path : string = 'SHOP_PATH'
-
Path key (e.g. 'SHOP_PATH')
Return values
string —Path value
getModuleName()
Gets current module name
public
getModuleName() : string
Return values
string —Current module name
getSettings()
Gets current shop settings
public
getSettings() : array<string|int, mixed>
Return values
array<string|int, mixed> —Current shop settings
getShopName()
Gets shop name
public
getShopName() : string
Return values
string —Shop name identifier
initialize()
Initializes shop environment
public
initialize([string $shopEnvironment = '' ]) : mixed
Loads configuration, sets properties, and defines legacy constants.
Parameters
- $shopEnvironment : string = ''
-
Shop environment identifier
isIpAllowed()
Checks if IP is allowed
public
isIpAllowed(array<string|int, mixed> $allowedIps, string $clientIp) : bool
Parameters
- $allowedIps : array<string|int, mixed>
-
Array of allowed IP addresses
- $clientIp : string
-
IP address to check
Return values
bool —Whether IP is allowed
loadConfig()
Loads shop settings from a .env file.
public
loadConfig(string $filePath) : array<string|int, mixed>
Parameters
- $filePath : string
-
The path to the file to be loaded.
Tags
Return values
array<string|int, mixed> —Array keys are the setting names and the values are the values. If a value contains commas, it's split into an array.
log()
public
log([mixed $message = '' ][, string $level = 'info' ][, mixed $backtrace = null ][, int $spacing = 0 ]) : void
Parameters
- $message : mixed = ''
- $level : string = 'info'
- $backtrace : mixed = null
- $spacing : int = 0
redirectToError()
Redirects to error page
public
redirectToError([int $errorCode = 0 ][, string $errorMessage = '' ][, string $get = '' ]) : void
Parameters
- $errorCode : int = 0
-
Error code
- $errorMessage : string = ''
-
Error message
- $get : string = ''
-
Additional GET parameters
redirectToMaintenance()
Redirects to maintenance page
public
redirectToMaintenance() : void
setDisplayErrors()
Sets display errors setting
public
setDisplayErrors(int $displayErrors) : void
Parameters
- $displayErrors : int
-
Whether to display errors (1 or 0)
setEnvFile()
Sets environment file path
public
setEnvFile([string $envFilePath = '' ]) : void
Parameters
- $envFilePath : string = ''
-
Path to environment configuration file
setGlobalPaths()
Sets global path constants
public
setGlobalPaths() : void
Looks for ROOT_PATH, SHOP_PATH, and LOG_PATH constants and stores them in the globalPaths array. Logs errors if constants are not defined.
setLogger()
Sets logger instance
public
setLogger(object $logger) : mixed
Parameters
- $logger : object
-
Logger instance to use
setLogHelper()
Sets logging helper status
public
setLogHelper(mixed $logHelperEnabled) : void
Parameters
- $logHelperEnabled : mixed
-
Whether logging helper is enabled
setLogLevel()
Sets logging level
public
setLogLevel(string $logLevel) : void
Parameters
- $logLevel : string
-
Log level ('notices', 'warnings', 'errors', 'none')
setMinifying()
Sets minification status
public
setMinifying(mixed $minify) : void
Parameters
- $minify : mixed
-
Whether minification is enabled
setModuleName()
Sets current module name
public
setModuleName([string $moduleName = '' ]) : void
Parameters
- $moduleName : string = ''
-
Name of the current module
setSettings()
Updates shop settings
public
setSettings(array<string|int, mixed> $settings) : void
Parameters
- $settings : array<string|int, mixed>
-
Array of settings to merge with current settings
setShopEnvironment()
Sets shop environment
public
setShopEnvironment([string $shopEnvironment = '' ]) : void
Parameters
- $shopEnvironment : string = ''
-
Environment identifier (e.g. 'dev', 'test', 'live')
setShopName()
Sets shop name
public
setShopName([string $shopName = '' ]) : void
Parameters
- $shopName : string = ''
-
Name identifier for the shop
validateUserAccess()
Validates user access based on IP and maintenance mode
public
validateUserAccess() : void
Checks if current IP is allowed and if maintenance mode is active. Redirects to error or maintenance page if access is denied.
convertStringsToArrays()
Converts string settings to arrays
private
convertStringsToArrays(array<string|int, mixed> $settings, array<string|int, mixed> $keysToConvert) : array<string|int, mixed>
Parameters
- $settings : array<string|int, mixed>
-
Settings array
- $keysToConvert : array<string|int, mixed>
-
Keys to convert
Return values
array<string|int, mixed> —Modified settings array
findConfig()
Finds configuration file
private
findConfig([string|null $startDir = null ]) : string|null
Searches for settings.env or environment-specific settings file
Parameters
- $startDir : string|null = null
-
Directory to start search from
Return values
string|null —Path to configuration file or null if not found