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_ROUTES = 'routes'
 
const CACHE_HASHED = 'hashed'
 
 $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
 
 $hashKey = 'hash'
 Default hash key. More...
 
 $hashAlgo = 'sha256'
 Default hash algo. 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 ()
 
 cache ($route, $key)
 Retrieve data from the route cache. More...
 
 save ($route, $key, $value)
 Save data to the route cache. More...
 
 mask ($route, &$mask, &$slots)
 Parse a route and generate a mask (regex). More...
 
 data ($route)
 Parsed data for route. More...
 
 hash ($hash, $params)
 Calculate the hash for 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 ()
 
 done ()
 
 getSession ()
 
- Protected Member Functions inherited from Thing
 publish ($property, $visibility=self::READABLE)
 Publish a property (or hide it again). 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...
 
 $_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...
 

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 75 of file Router.php.

◆ data()

data (   $route)
protected

Parsed data for route.

Parameters
string$route
Returns
array Data.

Definition at line 144 of file Router.php.

◆ done()

done ( )
protected

Definition at line 51 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 226 of file Router.php.

◆ format()

format (   $route)
protected

Format a (default) route.

Parameters
string$routeBase route.
Returns
string Formatted route.

Definition at line 254 of file Router.php.

◆ getControllerName()

getControllerName ( )
protected

Definition at line 301 of file Router.php.

◆ getPathInfo()

getPathInfo ( )
protected

Definition at line 306 of file Router.php.

◆ getViewType()

getViewType ( )
protected

Definition at line 310 of file Router.php.

◆ hash()

hash (   $hash,
  $params 
)
protected

Calculate the hash for a set of parameters.

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

Definition at line 160 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 174 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 110 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.

Definition at line 185 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 265 of file Router.php.

◆ save()

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

Save data to the route cache.

Parameters
string$route
string$key
mixed$valueData for this route + key.

Definition at line 100 of file Router.php.

Field Documentation

◆ $_cache

$_cache = null
protected

Definition at line 45 of file Router.php.

◆ $_controllerName

$_controllerName = null
protected

Definition at line 48 of file Router.php.

◆ $_hashed

$_hashed = false
protected

Definition at line 49 of file Router.php.

◆ $_save

$_save = false
protected

Definition at line 46 of file Router.php.

◆ $_sharedCacheFile

$_sharedCacheFile = null
protected

Shared cache file for compiled routes.

Definition at line 43 of file Router.php.

◆ $_viewType

$_viewType = null
protected

Definition at line 47 of file Router.php.

◆ $defaultParams

$defaultParams = []

Default params for routes.

Definition at line 35 of file Router.php.

◆ $hashAlgo

$hashAlgo = 'sha256'

Default hash algo.

Definition at line 41 of file Router.php.

◆ $hashKey

$hashKey = 'hash'

Default hash key.

Definition at line 40 of file Router.php.

◆ $prefix

$prefix = '/'

Prefix to add before each route.

Definition at line 11 of file Router.php.

◆ $regexShortcuts

$regexShortcuts
Initial value:
= [
'*' => '\\d+'

Definition at line 36 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 12 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 9 of file Router.php.

◆ CACHE_ROUTES

const CACHE_ROUTES = 'routes'

Definition at line 8 of file Router.php.


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