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

Public Member Functions

 __construct ($pattern, $callable)
 Constructor.
 getPattern ()
 Get route pattern.
 setPattern ($pattern)
 Set route pattern.
 getCallable ()
 Get route callable.
 setCallable ($callable)
 Set route callable.
 getConditions ()
 Get route conditions.
 setConditions (array $conditions)
 Set route conditions.
 getName ()
 Get route name.
 setName ($name)
 Set route name.
 getParams ()
 Get route parameters.
 setHttpMethods ()
 Add supported HTTP method(s)
 getHttpMethods ()
 Get supported HTTP methods.
 appendHttpMethods ()
 Append supported HTTP methods.
 via ()
 Append supported HTTP methods (alias for Route::appendHttpMethods)
 supportsHttpMethod ($method)
 Detect support for an HTTP method.
 getRouter ()
 Get router.
 setRouter (Slim_Router $router)
 Set router.
 getMiddleware ()
 Get middleware.
 setMiddleware ($middleware)
 Set middleware.
 matches ($resourceUri)
 Matches URI?
 name ($name)
 Set route name.
 conditions (array $conditions)
 Merge route conditions.
 dispatch ()
 Dispatch route.

Static Public Member Functions

static setDefaultConditions (array $defaultConditions)
 Set default route conditions for all instances.
static getDefaultConditions ()
 Get default route conditions for all instances.

Protected Member Functions

 convertPatternToRegex ($matches)
 Convert a URL parameter (ie.

Protected Attributes

 $pattern
 $callable
 $conditions = array()
 $name
 $params = array()
 $methods = array()
 $router
 $middleware = array()

Static Protected Attributes

static $defaultConditions = array()

Detailed Description

Definition at line 40 of file Route.php.

Constructor & Destructor Documentation

Slim_Route::__construct (   $pattern,
  $callable 
)

Constructor.

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

Definition at line 92 of file Route.php.

References $callable, $pattern, setCallable(), setConditions(), and setPattern().

{
$this->setConditions(self::getDefaultConditions());
}

+ Here is the call graph for this function:

Member Function Documentation

Slim_Route::appendHttpMethods ( )

Append supported HTTP methods.

Returns
void

Definition at line 213 of file Route.php.

{
$args = func_get_args();
$this->methods = array_merge($this->methods, $args);
}
Slim_Route::conditions ( array  $conditions)

Merge route conditions.

Parameters
array$conditionsKey-value array of URL parameter conditions
Returns
Slim_Route

Definition at line 354 of file Route.php.

Referenced by convertPatternToRegex(), and setConditions().

{
$this->conditions = array_merge($this->conditions, $conditions);
return $this;
}

+ Here is the caller graph for this function:

Slim_Route::convertPatternToRegex (   $matches)
protected

Convert a URL parameter (ie.

":id") into a regular expression

Parameters
arrayURL parameters
Returns
string Regular expression for URL parameter

Definition at line 330 of file Route.php.

References conditions().

{
$key = str_replace(':', '', $matches[0]);
if ( array_key_exists($key, $this->conditions) ) {
return '(?P<' . $key . '>' . $this->conditions[$key] . ')';
} else {
return '(?P<' . $key . '>[a-zA-Z0-9_\-\.\!\~\*\\\'\(\)\:\@\&\=\$\+,%]+)';
}
}

+ Here is the call graph for this function:

Slim_Route::dispatch ( )

Dispatch route.

This method invokes this route's callable. If middleware is registered for this route, each callable middleware is invoked in the order specified.

This method is smart about trailing slashes on the route pattern. If this route's pattern is defined with a trailing slash, and if the current request URI does not have a trailing slash but otherwise matches this route's pattern, a Slim_Exception_RequestSlash will be thrown triggering an HTTP 301 Permanent Redirect to the same URI with a trailing slash. This Exception is caught in the Slim::run loop. If this route's pattern is defined without a trailing slash, and if the current request URI does have a trailing slash, this route will not be matched and a 404 Not Found response will be sent if no subsequent matching routes are found.

Returns
bool Was route callable invoked successfully?
Exceptions
Slim_Exception_RequestSlash

Definition at line 380 of file Route.php.

References getCallable().

{
if ( substr($this->pattern, -1) === '/' && substr($this->router->getRequest()->getResourceUri(), -1) !== '/' ) {
}
//Invoke middleware
foreach ( $this->middleware as $mw ) {
if ( is_callable($mw) ) {
call_user_func($mw);
}
}
//Invoke callable
if ( is_callable($this->getCallable()) ) {
call_user_func_array($this->callable, array_values($this->params));
return true;
}
return false;
}

+ Here is the call graph for this function:

Slim_Route::getCallable ( )

Get route callable.

Returns
mixed

Definition at line 136 of file Route.php.

References $callable.

Referenced by dispatch().

{
}

+ Here is the caller graph for this function:

Slim_Route::getConditions ( )

Get route conditions.

Returns
array

Definition at line 153 of file Route.php.

References $conditions.

{
}
static Slim_Route::getDefaultConditions ( )
static

Get default route conditions for all instances.

Returns
array

Definition at line 111 of file Route.php.

References $defaultConditions.

Slim_Route::getHttpMethods ( )

Get supported HTTP methods.

Returns
array

Definition at line 205 of file Route.php.

References $methods.

{
}
Slim_Route::getMiddleware ( )

Get middleware.

Returns
array[Callable]

Definition at line 257 of file Route.php.

References $middleware.

{
}
Slim_Route::getName ( )

Get route name.

Returns
string|null

Definition at line 170 of file Route.php.

References $name.

{
return $this->name;
}
Slim_Route::getParams ( )

Get route parameters.

Returns
array

Definition at line 188 of file Route.php.

References $params.

{
return $this->params;
}
Slim_Route::getPattern ( )

Get route pattern.

Returns
string

Definition at line 119 of file Route.php.

References $pattern.

{
}
Slim_Route::getRouter ( )

Get router.

Returns
Slim_Router

Definition at line 240 of file Route.php.

References $router.

{
return $this->router;
}
Slim_Route::matches (   $resourceUri)

Matches URI?

Parse this route's pattern, and then compare it to an HTTP resource URI This method was modeled after the techniques demonstrated by Dan Sosedoff at:

http://blog.sosedoff.com/2009/09/20/rails-like-php-url-router/

Parameters
string$resourceUriA Request URI
Returns
bool

Definition at line 298 of file Route.php.

{
//Extract URL params
preg_match_all('@:([\w]+)@', $this->pattern, $paramNames, PREG_PATTERN_ORDER);
$paramNames = $paramNames[0];
//Convert URL params into regex patterns, construct a regex for this route
$patternAsRegex = preg_replace_callback('@:[\w]+@', array($this, 'convertPatternToRegex'), $this->pattern);
if ( substr($this->pattern, -1) === '/' ) {
$patternAsRegex = $patternAsRegex . '?';
}
$patternAsRegex = '@^' . $patternAsRegex . '$@';
//Cache URL params' names and values if this route matches the current HTTP request
if ( preg_match($patternAsRegex, $resourceUri, $paramValues) ) {
array_shift($paramValues);
foreach ( $paramNames as $index => $value ) {
$val = substr($value, 1);
if ( isset($paramValues[$val]) ) {
$this->params[$val] = urldecode($paramValues[$val]);
}
}
return true;
} else {
return false;
}
}
Slim_Route::name (   $name)

Set route name.

Parameters
string$nameThe name of the route
Returns
Slim_Route

Definition at line 344 of file Route.php.

References $name, and setName().

Referenced by setName().

{
$this->setName($name);
return $this;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Route::setCallable (   $callable)

Set route callable.

Parameters
mixed$callable
Returns
void

Definition at line 145 of file Route.php.

References $callable.

Referenced by __construct().

{
$this->callable = $callable;
}

+ Here is the caller graph for this function:

Slim_Route::setConditions ( array  $conditions)

Set route conditions.

Parameters
array$conditions
Returns
void

Definition at line 162 of file Route.php.

References $conditions, and conditions().

Referenced by __construct().

{
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Slim_Route::setDefaultConditions ( array  $defaultConditions)
static

Set default route conditions for all instances.

Parameters
array$defaultConditions
Returns
void

Definition at line 103 of file Route.php.

References $defaultConditions.

{
self::$defaultConditions = $defaultConditions;
}
Slim_Route::setHttpMethods ( )

Add supported HTTP method(s)

Returns
void

Definition at line 196 of file Route.php.

{
$args = func_get_args();
$this->methods = $args;
}
Slim_Route::setMiddleware (   $middleware)

Set middleware.

This method allows middleware to be assigned to a specific Route. If the method argument is_callable (including callable arrays!), we directly append the argument to $this->middleware. Else, we assume the argument is an array of callables and merge the array with $this->middleware. Even if non-callables are included in the argument array, we still merge them; we lazily check each item against is_callable during Route::dispatch().

Parameters
Callable|array[Callable]
Returns
Slim_Route
Exceptions
InvalidArgumentExceptionIf argument is not callable or not an array

Definition at line 276 of file Route.php.

References $middleware.

{
if ( is_callable($middleware) ) {
$this->middleware[] = $middleware;
} else if ( is_array($middleware) ) {
$this->middleware = array_merge($this->middleware, $middleware);
} else {
throw new InvalidArgumentException('Route middleware must be callable or an array of callables');
}
return $this;
}
Slim_Route::setName (   $name)

Set route name.

Parameters
string$name
Returns
void

Definition at line 179 of file Route.php.

References $name, and name().

Referenced by name().

{
$this->name = (string)$name;
$this->router->cacheNamedRoute($this->name, $this);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Route::setPattern (   $pattern)

Set route pattern.

Parameters
string$pattern
Returns
void

Definition at line 128 of file Route.php.

References $pattern.

Referenced by __construct().

{
$this->pattern = str_replace(')', ')?', (string)$pattern);
}

+ Here is the caller graph for this function:

Slim_Route::setRouter ( Slim_Router  $router)

Set router.

Parameters
Slim_Router$router
Returns
void

Definition at line 249 of file Route.php.

References $router.

{
$this->router = $router;
}
Slim_Route::supportsHttpMethod (   $method)

Detect support for an HTTP method.

Returns
bool

Definition at line 232 of file Route.php.

{
return in_array($method, $this->methods);
}
Slim_Route::via ( )

Append supported HTTP methods (alias for Route::appendHttpMethods)

Returns
Slim_Route

Definition at line 222 of file Route.php.

{
$args = func_get_args();
$this->methods = array_merge($this->methods, $args);
return $this;
}

Field Documentation

Slim_Route::$callable
protected

Definition at line 50 of file Route.php.

Referenced by __construct(), getCallable(), and setCallable().

Slim_Route::$conditions = array()
protected

Definition at line 55 of file Route.php.

Referenced by getConditions(), and setConditions().

Slim_Route::$defaultConditions = array()
staticprotected

Definition at line 60 of file Route.php.

Referenced by getDefaultConditions(), and setDefaultConditions().

Slim_Route::$methods = array()
protected

Definition at line 75 of file Route.php.

Referenced by getHttpMethods().

Slim_Route::$middleware = array()
protected

Definition at line 85 of file Route.php.

Referenced by getMiddleware(), and setMiddleware().

Slim_Route::$name
protected

Definition at line 65 of file Route.php.

Referenced by getName(), name(), and setName().

Slim_Route::$params = array()
protected

Definition at line 70 of file Route.php.

Referenced by getParams().

Slim_Route::$pattern
protected

Definition at line 45 of file Route.php.

Referenced by __construct(), getPattern(), and setPattern().

Slim_Route::$router
protected

Definition at line 80 of file Route.php.

Referenced by getRouter(), and setRouter().


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