ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Slim_Router Class Reference
+ Inheritance diagram for Slim_Router:
+ Collaboration diagram for Slim_Router:

Public Member Functions

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

Protected Attributes

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

Detailed Description

Definition at line 45 of file Router.php.

Constructor & Destructor Documentation

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.

{
$this->request = $request;
$this->routes = array();
}

Member Function Documentation

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.

{
if ( isset($this->namedRoutes[(string)$name]) ) {
throw new RuntimeException('Named route already exists with name: ' . $name);
}
$this->namedRoutes[$name] = $route;
}
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.

{
if ( is_callable($callable) ) {
$this->error = $callable;
}
return $this->error;
}
Slim_Router::getIterator ( )

Get Iterator.

Returns
ArrayIterator

Definition at line 90 of file Router.php.

References getMatchedRoutes().

{
return new ArrayIterator($this->getMatchedRoutes());
}

+ Here is the call graph for this function:

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.

Referenced by getIterator().

{
if ( $reload || is_null($this->matchedRoutes) ) {
$this->matchedRoutes = array();
foreach ( $this->routes as $route ) {
if ( $route->matches($this->request->getResourceUri()) ) {
$this->matchedRoutes[] = $route;
}
}
}
}

+ Here is the caller graph for this function:

Slim_Router::getRequest ( )

Get Request.

Returns
Slim_Http_Request

Definition at line 98 of file Router.php.

References $request.

{
}
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.

{
$route = new Slim_Route($pattern, $callable);
$route->setRouter($this);
$this->routes[] = $route;
return $route;
}
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.

{
if ( is_callable($callable) ) {
$this->notFound = $callable;
}
}
Slim_Router::setRequest ( Slim_Http_Request  $req)

Set Request.

Parameters
Slim_Http_Request$req
Returns
void

Definition at line 107 of file Router.php.

{
$this->request = $req;
}
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.

{
if ( !isset($this->namedRoutes[(string)$name]) ) {
throw new RuntimeException('Named route not found for name: ' . $name);
}
$pattern = $this->namedRoutes[(string)$name]->getPattern();
$search = $replace = array();
foreach ( $params as $key => $value ) {
$search[] = ':' . $key;
$replace[] = $value;
}
$pattern = str_replace($search, $replace, $pattern);
//Remove remnants of unpopulated, trailing optional pattern segments
return preg_replace(array(
'@\(\/?:.+\/??\)\??@',
'@\?|\(|\)@'
), '', $this->request->getRootUri() . $pattern);
}

Field Documentation

Slim_Router::$error
protected

Definition at line 75 of file Router.php.

Referenced by error().

Slim_Router::$matchedRoutes
protected

Definition at line 65 of file Router.php.

Referenced by getMatchedRoutes().

Slim_Router::$namedRoutes
protected

Definition at line 60 of file Router.php.

Slim_Router::$notFound
protected

Definition at line 70 of file Router.php.

Referenced by notFound().

Slim_Router::$request
protected

Definition at line 50 of file Router.php.

Referenced by __construct(), and getRequest().

Slim_Router::$routes
protected

Definition at line 55 of file Router.php.


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