ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Slim_Router Class Reference
+ Inheritance diagram for Slim_Router:
+ Collaboration diagram for Slim_Router:

Public Member Functions

 __construct (Slim_Http_Request $request)
 Constructor. More...
 
 getIterator ()
 Get Iterator. More...
 
 getRequest ()
 Get Request. More...
 
 setRequest (Slim_Http_Request $req)
 Set Request. More...
 
 getMatchedRoutes ( $reload=false)
 Return routes that match the current request. More...
 
 map ( $pattern, $callable)
 Map a route to a callback function. More...
 
 cacheNamedRoute ( $name, Slim_Route $route)
 Cache named route. More...
 
 urlFor ( $name, $params=array())
 Get URL for named route. More...
 
 notFound ( $callable=null)
 Register a 404 Not Found callback. More...
 
 error ( $callable=null)
 Register a 500 Error callback. More...
 

Protected Attributes

 $request
 
 $routes
 
 $namedRoutes
 
 $matchedRoutes
 
 $notFound
 
 $error
 

Detailed Description

Definition at line 45 of file Router.php.

Constructor & Destructor Documentation

◆ __construct()

Slim_Router::__construct ( Slim_Http_Request  $request)

Constructor.

Parameters
Slim_Http_Request$requestThe HTTP request object

Definition at line 81 of file Router.php.

References $request, and array.

81  {
82  $this->request = $request;
83  $this->routes = array();
84  }
Create styles array
The data for the language used.

Member Function Documentation

◆ cacheNamedRoute()

Slim_Router::cacheNamedRoute (   $name,
Slim_Route  $route 
)

Cache named route.

Parameters
string$nameThe route name
Slim_Route$routeThe route object
Exceptions
RuntimeExceptionIf a named route already exists with the same name
Returns
void

Definition at line 147 of file Router.php.

147  {
148  if ( isset($this->namedRoutes[(string)$name]) ) {
149  throw new RuntimeException('Named route already exists with name: ' . $name);
150  }
151  $this->namedRoutes[$name] = $route;
152  }

◆ error()

mixed Callable to be invoked if application Slim_Router::error (   $callable = null)

Register a 500 Error callback.

Parameters
mixed$callableAnything that returns TRUE for is_callable()
Returns
mixed

Definition at line 196 of file Router.php.

References $error.

196  {
197  if ( is_callable($callable) ) {
198  $this->error = $callable;
199  }
200  return $this->error;
201  }
error( $callable=null)
Register a 500 Error callback.
Definition: Router.php:196

◆ getIterator()

Slim_Router::getIterator ( )

Get Iterator.

Returns
ArrayIterator

Definition at line 90 of file Router.php.

References getMatchedRoutes().

90  {
91  return new ArrayIterator($this->getMatchedRoutes());
92  }
getMatchedRoutes( $reload=false)
Return routes that match the current request.
Definition: Router.php:115
+ Here is the call graph for this function:

◆ getMatchedRoutes()

Slim_Router::getMatchedRoutes (   $reload = false)

Return routes that match the current request.

Returns
array[Slim_Route]

Definition at line 115 of file Router.php.

References $matchedRoutes, and array.

Referenced by getIterator().

115  {
116  if ( $reload || is_null($this->matchedRoutes) ) {
117  $this->matchedRoutes = array();
118  foreach ( $this->routes as $route ) {
119  if ( $route->matches($this->request->getResourceUri()) ) {
120  $this->matchedRoutes[] = $route;
121  }
122  }
123  }
124  return $this->matchedRoutes;
125  }
$matchedRoutes
Definition: Router.php:65
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getRequest()

Slim_Router::getRequest ( )

Get Request.

Returns
Slim_Http_Request

Definition at line 98 of file Router.php.

References $request.

98  {
99  return $this->request;
100  }

◆ map()

Slim_Router::map (   $pattern,
  $callable 
)

Map a route to a callback function.

Parameters
string$patternThe URL pattern (ie. "/books/:id")
mixed$callableAnything that returns TRUE for is_callable()
Returns
Slim_Route

Definition at line 133 of file Router.php.

133  {
134  $route = new Slim_Route($pattern, $callable);
135  $route->setRouter($this);
136  $this->routes[] = $route;
137  return $route;
138  }

◆ notFound()

Slim_Router::notFound (   $callable = null)

Register a 404 Not Found callback.

Parameters
mixed$callableAnything that returns TRUE for is_callable()
Returns
mixed

Definition at line 184 of file Router.php.

References $notFound.

184  {
185  if ( is_callable($callable) ) {
186  $this->notFound = $callable;
187  }
188  return $this->notFound;
189  }
notFound( $callable=null)
Register a 404 Not Found callback.
Definition: Router.php:184

◆ setRequest()

Slim_Router::setRequest ( Slim_Http_Request  $req)

Set Request.

Parameters
Slim_Http_Request$req
Returns
void

Definition at line 107 of file Router.php.

107  {
108  $this->request = $req;
109  }

◆ urlFor()

Slim_Router::urlFor (   $name,
  $params = array() 
)

Get URL for named route.

Parameters
string$nameThe name of the route
arrayAssociative array of URL parameter names and values
Exceptions
RuntimeExceptionIf named route not found
Returns
string The URL for the given route populated with the given parameters

Definition at line 161 of file Router.php.

References $params, array, and string.

161  {
162  if ( !isset($this->namedRoutes[(string)$name]) ) {
163  throw new RuntimeException('Named route not found for name: ' . $name);
164  }
165  $pattern = $this->namedRoutes[(string)$name]->getPattern();
166  $search = $replace = array();
167  foreach ( $params as $key => $value ) {
168  $search[] = ':' . $key;
169  $replace[] = $value;
170  }
171  $pattern = str_replace($search, $replace, $pattern);
172  //Remove remnants of unpopulated, trailing optional pattern segments
173  return preg_replace(array(
174  '@\(\/?:.+\/??\)\??@',
175  '@\?|\(|\)@'
176  ), '', $this->request->getRootUri() . $pattern);
177  }
Add rich text string
The name of the decorator.
Create styles array
The data for the language used.
$params
Definition: example_049.php:96

Field Documentation

◆ $error

Slim_Router::$error
protected

Definition at line 75 of file Router.php.

Referenced by error().

◆ $matchedRoutes

Slim_Router::$matchedRoutes
protected

Definition at line 65 of file Router.php.

Referenced by getMatchedRoutes().

◆ $namedRoutes

Slim_Router::$namedRoutes
protected

Definition at line 60 of file Router.php.

◆ $notFound

Slim_Router::$notFound
protected

Definition at line 70 of file Router.php.

Referenced by notFound().

◆ $request

Slim_Router::$request
protected

Definition at line 50 of file Router.php.

Referenced by __construct(), and getRequest().

◆ $routes

Slim_Router::$routes
protected

Definition at line 55 of file Router.php.


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