Singleton
trait Singleton
Trait Singleton, This class ensures that all class that use this have only one instance of itself if called as: Class::getInstance()
If any specific class need more than one instance (for example database connection), can add a reference name to the function to have a separate configuration using this reference name.
Properties
static protected bool | $singletonArray | Set to true if you want use more that one singleton using and index param in getInstance | |
static protected string | $basePath | The base path where config files are placed. | |
static private string | $className | Name of the class | |
static private array | $instances | Hold the classes on instance. | |
protected bool | $separateConfigFile | Set to true if you want to save configuration in a separate file |
Methods
The object is created from within the class itself only if the class has no instance.
Returns the class name.
Save config to file.
Returns the content of the Yaml file.
Return the full file config path.
Return the file name.
Return the classname for yaml file.
Returns if file exists.
Returns the yaml config params.
Return default values
Return the base path.
Initialization, equivalent to __construct and must be called from main class.
Details
at line 72
static mixed
getInstance(string $index = 'main')
The object is created from within the class itself only if the class has no instance.
We opted to use an array to make several singletons according to the index passed to getInstance
at line 88
static private string
getClassName()
Returns the class name.
at line 103
bool
setConfig(array $params, bool $merge = true, string $index = 'main')
Save config to file.
at line 130
private array
getYamlContent()
Returns the content of the Yaml file.
at line 152
string
getFilePath()
Return the full file config path.
at line 162
string
getFileName()
Return the file name.
at line 172
static string
yamlName()
Return the classname for yaml file.
at line 184
protected bool
fileExists(string $filename)
Returns if file exists.
at line 196
array
getConfig(string $index = 'main')
Returns the yaml config params.
at line 208
abstract static array
getDefaultValues()
Return default values
at line 215
string
getBasePath()
Return the base path.
at line 223
protected
initSingleton()
Initialization, equivalent to __construct and must be called from main class.