FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Router Class Reference
Inheritance diagram for Router:
Component Thing

Public Member Functions

 execute ($path=null)
 Determine controller name and type. More...
 
 reverse ($controller_name=null, $type=null, $params=null, $strict=true)
 Determine a route from a controller name and type. More...
 
- Public Member Functions inherited from Component
 __construct ($fred, $config=null)
 
 __destruct ()
 
 clientConfig ()
 Public configuration. More...
 
 config ($key, $default=null)
 Retrieve a config value. More...
 
 ping ()
 Ping function. More...
 
 filemtime ($filename)
 Filemtime with session cache. More...
 
 component ($name)
 Get a component (local or default). More...
 
 components (... $names)
 Get multiple components in an array. More...
 
- Public Member Functions inherited from Thing
 propertyExists ($property)
 Check if a property exists (public or published). More...
 
 constants ($prefix=null)
 Return all constants. More...
 
 get ($key)
 Get one or more properties. More...
 
 set ($key, $value=null)
 Set one or more properties. More...
 
 __get ($key)
 
 __set ($key, $value)
 

Data Fields

const CACHE_HASH = 'hash'
 
const CACHE_TIME = 'time'
 
const CACHE_ROUTES = 'routes'
 
const CACHE_HASHED = 'hashed'
 
const ENUM_TRANS = '@'
 
const ENUM_DYNAMIC = '#'
 
 $prefix = '/'
 Prefix to add before each route. More...
 
 $routes = []
 Available routes (key = route, value = controller data). Parameters can be present in a route (e.g. More...
 
 $defaultParams = []
 Default params for routes. More...
 
 $regexShortcuts
 
 $enumTransTtl = 3600
 Time-to-live for translated enum options. More...
 
 $hashKey = 'hash'
 Default hash key. More...
 
 $hashAlgo = 'sha256'
 Default hash algo. More...
 
 $encryptKey = 'data'
 Default encrypted data key. More...
 
- Data Fields inherited from Component
 $filemtimeTtl = 0
 
- Data Fields inherited from Thing
const HIDDEN = 0
 Property is hidden. More...
 
const READABLE = 1
 Property is readable. More...
 
const WRITEABLE = 2
 Property is writeable. More...
 
const READWRITE = 3
 Property is readable and writeable. More...
 

Protected Member Functions

 done ()
 
 stripClosures ($value)
 
 cache ($route, $key)
 Retrieve data from the route cache. More...
 
 save ($route, $key, $value)
 Save data to the route cache. More...
 
 enumLang ($params)
 
 mask ($route, &$mask, &$slots)
 Parse a route and generate a mask (regex). More...
 
 data ($route)
 Parsed data for route. More...
 
 enum ($enum, $params, $data)
 Parse an (dynamic) enum. More...
 
 hash ($hash, $params)
 Calculate the hash for a set of parameters. More...
 
 encrypt ($encrypt, $params, &$keys)
 Encrypt a set of parameters. More...
 
 hashed (&$key=null)
 Check if the current controller (+ action) has a hashed version. More...
 
 match ($path, $route)
 Check if a path matches a route and extract the parameters. More...
 
 format ($route)
 Format a (default) route. More...
 
 getControllerName ()
 
 getPathInfo ()
 
 getViewType ()
 
- Protected Member Functions inherited from Component
 init ()
 
 getSession ()
 
- Protected Member Functions inherited from Thing
 publish ($property, $visibility=self::READABLE)
 Publish a property (or hide it again). More...
 
 alias ($alias, $property, $object=null)
 Define an alias for a property (of another object). More...
 
 configure ($config)
 Configure the object. More...
 
 _get ($key)
 Default getter if no specific setter is defined, and the property is also not published (readable). More...
 
 _set ($key, $value)
 Default setter if no specific setter is defined, and the property is also not published (writeable). More...
 

Protected Attributes

 $_sharedCacheFile = null
 Shared cache file for compiled routes. More...
 
 $_sharedCacheTtlSpread = 10
 Random spread for TTL. More...
 
 $_cache = null
 
 $_save = false
 
 $_viewType = null
 
 $_controllerName = null
 
 $_hashed = false
 
- Protected Attributes inherited from Component
 $_fred = null
 
 $_config = null
 
 $_name = null
 
 $_components = []
 Local components (key = component name, value = component). More...
 
 $_session = null
 
- Protected Attributes inherited from Thing
 $_published = []
 Published properties (key = name of property, value = visibility). More...
 
 $_aliases = []
 Alias properties (key = alias, value = [object,property]). More...
 

Detailed Description

Definition at line 5 of file Router.php.

Member Function Documentation

◆ cache()

cache (   $route,
  $key 
)
protected

Retrieve data from the route cache.

Parameters
string$route
string$key
Returns
mixed Data for this route + key.

Definition at line 97 of file Router.php.

◆ data()

data (   $route)
protected

Parsed data for route.

Parameters
string$route
Returns
array Data.

Definition at line 186 of file Router.php.

◆ done()

done ( )
protected

Reimplemented from Component.

Definition at line 69 of file Router.php.

◆ encrypt()

encrypt (   $encrypt,
  $params,
$keys 
)
protected

Encrypt a set of parameters.

Parameters
array$encryptEncryption parameters.
array$paramsRoute parameters (values).
array$keysKeys encrypted (return).
Returns
string Encrypted data (binary).

Definition at line 228 of file Router.php.

◆ enum()

enum (   $enum,
  $params,
  $data 
)
protected

Parse an (dynamic) enum.

Parameters
mixed$enumRaw enum.
array$paramsCurrent set of parameters.
array$dataRoute data.
Returns
array

Definition at line 203 of file Router.php.

◆ enumLang()

enumLang (   $params)
protected

Definition at line 134 of file Router.php.

◆ execute()

execute (   $path = null)

Determine controller name and type.

If the controller name matches a route, the name will be translated to this route, and parameters present will be added to the $_GET.

Parameters
string$pathIf the path is not given, then the path after the script itself ('foo/bar' in '/index.php/foo/bar') will be used.

Definition at line 303 of file Router.php.

◆ format()

format (   $route)
protected

Format a (default) route.

Parameters
string$routeBase route.
Returns
string Formatted route.

Definition at line 331 of file Router.php.

◆ getControllerName()

getControllerName ( )
protected

Definition at line 389 of file Router.php.

◆ getPathInfo()

getPathInfo ( )
protected

Definition at line 394 of file Router.php.

◆ getViewType()

getViewType ( )
protected

Definition at line 398 of file Router.php.

◆ hash()

hash (   $hash,
  $params 
)
protected

Calculate the hash for a set of parameters.

Parameters
array$hashHash configuration.
array$paramsRoute parameters (values).
Returns
string Hash.

Definition at line 212 of file Router.php.

◆ hashed()

hashed ( $key = null)
protected

Check if the current controller (+ action) has a hashed version.

Parameters
string$keyCache key.
Returns
array Keys for the parametes in the hash (or false if not found).

Definition at line 239 of file Router.php.

◆ mask()

mask (   $route,
$mask,
$slots 
)
protected

Parse a route and generate a mask (regex).

Parameters
string$route
string$maskResulting regex.
array$slotsSlots for every paramter in the route.

Definition at line 143 of file Router.php.

◆ match()

match (   $path,
  $route 
)
protected

Check if a path matches a route and extract the parameters.

Parameters
string$pathPath to check.
string$routeRoute to check against.
Returns
string Controller name on match (null = no match, false = unsatisfied enum).

Definition at line 251 of file Router.php.

◆ reverse()

reverse (   $controller_name = null,
  $type = null,
  $params = null,
  $strict = true 
)

Determine a route from a controller name and type.

Parameters
string$controller_name(empty = current)
string$type
array$paramsParameters to use with the route.
bool$strictWhether too check the format of the parameters.
Returns
string Found route. Parameters that were not used in the route are added in the query.

Definition at line 342 of file Router.php.

◆ save()

save (   $route,
  $key,
  $value 
)
protected

Save data to the route cache.

Parameters
string$routeRoute (set tot false for hash).
string$key
mixed$valueData for this route + key.

Definition at line 128 of file Router.php.

◆ stripClosures()

stripClosures (   $value)
protected

Definition at line 85 of file Router.php.

Field Documentation

◆ $_cache

$_cache = null
protected

Definition at line 63 of file Router.php.

◆ $_controllerName

$_controllerName = null
protected

Definition at line 66 of file Router.php.

◆ $_hashed

$_hashed = false
protected

Definition at line 67 of file Router.php.

◆ $_save

$_save = false
protected

Definition at line 64 of file Router.php.

◆ $_sharedCacheFile

$_sharedCacheFile = null
protected

Shared cache file for compiled routes.

Definition at line 60 of file Router.php.

◆ $_sharedCacheTtlSpread

$_sharedCacheTtlSpread = 10
protected

Random spread for TTL.

Definition at line 61 of file Router.php.

◆ $_viewType

$_viewType = null
protected

Definition at line 65 of file Router.php.

◆ $defaultParams

$defaultParams = []

Default params for routes.

Definition at line 50 of file Router.php.

◆ $encryptKey

$encryptKey = 'data'

Default encrypted data key.

Definition at line 58 of file Router.php.

◆ $enumTransTtl

$enumTransTtl = 3600

Time-to-live for translated enum options.

Definition at line 55 of file Router.php.

◆ $hashAlgo

$hashAlgo = 'sha256'

Default hash algo.

Definition at line 57 of file Router.php.

◆ $hashKey

$hashKey = 'hash'

Default hash key.

Definition at line 56 of file Router.php.

◆ $prefix

$prefix = '/'

Prefix to add before each route.

Definition at line 15 of file Router.php.

◆ $regexShortcuts

$regexShortcuts
Initial value:
= [
'*' => '\\d+',
'+' => '[1-9]\\d*'
]

Definition at line 51 of file Router.php.

◆ $routes

$routes = []

Available routes (key = route, value = controller data). Parameters can be present in a route (e.g.

Definition at line 16 of file Router.php.

◆ CACHE_HASH

const CACHE_HASH = 'hash'

Definition at line 7 of file Router.php.

◆ CACHE_HASHED

const CACHE_HASHED = 'hashed'

Definition at line 10 of file Router.php.

◆ CACHE_ROUTES

const CACHE_ROUTES = 'routes'

Definition at line 9 of file Router.php.

◆ CACHE_TIME

const CACHE_TIME = 'time'

Definition at line 8 of file Router.php.

◆ ENUM_DYNAMIC

const ENUM_DYNAMIC = '#'

Definition at line 13 of file Router.php.

◆ ENUM_TRANS

const ENUM_TRANS = '@'

Definition at line 12 of file Router.php.


The documentation for this class was generated from the following file: