Router
class Router
Class Routes A route is a pair key => value, where key is the short name of the controller and the value the FQCN
Traits
Properties
static protected bool | $singletonArray | Set to true if you want use more that one singleton using and index param in getInstance | from Singleton |
static protected string | $basePath | The base path where config files are placed. | from Singleton |
static private string | $className | Name of the class | from Singleton |
static private array | $instances | Hold the classes on instance. | from Singleton |
protected bool | $separateConfigFile | Set to true if you want to save configuration in a separate file | from Singleton |
private array | $routes | Contains all routes. |
Methods
Return this instance.
Save config to file.
Return default values
Initialization, equivalent to __construct and must be called from main class.
Routes constructor.
Return a list of routes.
Set a new list of routes.
Load routes from configuration file.
Saves routes to configuration file.
Add a new route if is not yet added.
Returns if route is setted.
Returns the FQCN if exists or null.
Details
at line 98
static
Router
getInstance()
Return this instance.
in
Singleton
at line 88
static private string
getClassName()
Returns the class name.
in
Singleton
at line 103
bool
setConfig(array $params, bool $merge = true, string $index = 'main')
Save config to file.
in
Singleton
at line 130
private array
getYamlContent()
Returns the content of the Yaml file.
in
Singleton
at line 152
string
getFilePath()
Return the full file config path.
in
Singleton
at line 162
string
getFileName()
Return the file name.
in
Singleton
at line 172
static string
yamlName()
Return the classname for yaml file.
in
Singleton
at line 184
protected bool
fileExists(string $filename)
Returns if file exists.
in
Singleton
at line 196
array
getConfig(string $index = 'main')
Returns the yaml config params.
at line 84
static array
getDefaultValues()
Return default values
in
Singleton
at line 215
string
getBasePath()
Return the base path.
in
Singleton
at line 223
protected
initSingleton()
Initialization, equivalent to __construct and must be called from main class.
at line 35
protected
__construct()
Routes constructor.
at line 50
array
getRoutes()
Return a list of routes.
at line 60
setRoutes(array $routes = [])
Set a new list of routes.
at line 70
array
loadRoutes()
Load routes from configuration file.
at line 110
bool
saveRoutes(bool $merge = false)
Saves routes to configuration file.
at line 125
bool
addRoute(string $key, string $value, bool $force = false)
Add a new route if is not yet added.
With forced can be added always.
at line 142
bool
hasRoute(string $key)
Returns if route is setted.
at line 154
string|null
getRoute(string $key)
Returns the FQCN if exists or null.