ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Slim\Route Class Reference

Route. More...

+ Inheritance diagram for Slim\Route:
+ Collaboration diagram for Slim\Route:

Public Member Functions

 __construct ($methods, $pattern, $callable, $groups=[], $identifier=0)
 Create new route. More...
 
 finalize ()
 Finalize the route in preparation for dispatching. More...
 
 getCallable ()
 Get route callable. More...
 
 setCallable ($callable)
 This method enables you to override the Route's callable. More...
 
 getMethods ()
 Get route methods. More...
 
 getGroups ()
 Get parent route groups. More...
 
 getName ()
 Get route name. More...
 
 getIdentifier ()
 Get route identifier. More...
 
 getOutputBuffering ()
 Get output buffering mode. More...
 
 setOutputBuffering ($mode)
 Set output buffering mode. More...
 
 setName ($name)
 Set route name. More...
 
 setArgument ($name, $value, $includeInSavedArguments=true)
 Set a route argument. More...
 
 setArguments (array $arguments, $includeInSavedArguments=true)
 Replace route arguments. More...
 
 getArguments ()
 Retrieve route arguments. More...
 
 getArgument ($name, $default=null)
 Retrieve a specific route argument. More...
 
 prepare (ServerRequestInterface $request, array $arguments)
 Prepare the route for use. More...
 
 run (ServerRequestInterface $request, ResponseInterface $response)
 Run route. More...
 
- Public Member Functions inherited from Slim\Routable
 getMiddleware ()
 Get the middleware registered for the group. More...
 
 getPattern ()
 Get the route pattern. More...
 
 setContainer (ContainerInterface $container)
 Set container for use with resolveCallable. More...
 
 add ($callable)
 Prepend middleware to the middleware collection. More...
 
 setPattern ($newPattern)
 Set the route pattern. More...
 
- Public Member Functions inherited from Slim\Interfaces\RouteInterface
 getPattern ()
 Get route pattern. More...
 
 setArgument ($name, $value)
 Set a route argument. More...
 
 setArguments (array $arguments)
 Replace route arguments. More...
 
 add ($callable)
 Add middleware. More...
 
 __invoke (ServerRequestInterface $request, ResponseInterface $response)
 Dispatch route callable against current Request and Response objects. More...
 

Protected Attributes

 $methods = []
 
 $identifier
 
 $name
 
 $groups
 
 $outputBuffering = 'append'
 
 $arguments = []
 
 $savedArguments = []
 
 $callable
 
- Protected Attributes inherited from Slim\Routable
 $callable
 
 $container
 
 $middleware = []
 
 $pattern
 

Private Attributes

 $finalized = false
 

Detailed Description

Route.

Definition at line 21 of file Route.php.

Constructor & Destructor Documentation

◆ __construct()

Slim\Route::__construct (   $methods,
  $pattern,
  $callable,
  $groups = [],
  $identifier = 0 
)

Create new route.

Parameters
string|string[]$methods The route HTTP methods
string$patternThe route pattern
callable$callableThe route callable
RouteGroup[]$groups The parent route groups
int$identifierThe route identifier

Definition at line 94 of file Route.php.

95  {
96  $this->methods = is_string($methods) ? [$methods] : $methods;
97  $this->pattern = $pattern;
98  $this->callable = $callable;
99  $this->groups = $groups;
100  $this->identifier = 'route' . $identifier;
101  }
$identifier
Definition: Route.php:37

Member Function Documentation

◆ finalize()

Slim\Route::finalize ( )

Finalize the route in preparation for dispatching.

Definition at line 106 of file Route.php.

References Slim\addMiddleware().

107  {
108  if ($this->finalized) {
109  return;
110  }
111 
112  $groupMiddleware = [];
113  foreach ($this->getGroups() as $group) {
114  $groupMiddleware = array_merge($group->getMiddleware(), $groupMiddleware);
115  }
116 
117  $this->middleware = array_merge($this->middleware, $groupMiddleware);
118 
119  foreach ($this->getMiddleware() as $middleware) {
120  $this->addMiddleware($middleware);
121  }
122 
123  $this->finalized = true;
124  }
addMiddleware(callable $callable)
Add middleware.
getMiddleware()
Get the middleware registered for the group.
Definition: Routable.php:56
getGroups()
Get parent route groups.
Definition: Route.php:161
+ Here is the call graph for this function:

◆ getArgument()

Slim\Route::getArgument (   $name,
  $default = null 
)

Retrieve a specific route argument.

Parameters
string$name
string | null$default
Returns
mixed

Implements Slim\Interfaces\RouteInterface.

Definition at line 287 of file Route.php.

References $default, and $name.

288  {
289  if (array_key_exists($name, $this->arguments)) {
290  return $this->arguments[$name];
291  }
292  return $default;
293  }
$default
Definition: build.php:20

◆ getArguments()

Slim\Route::getArguments ( )

Retrieve route arguments.

Returns
array

Implements Slim\Interfaces\RouteInterface.

Definition at line 274 of file Route.php.

275  {
276  return $this->arguments;
277  }
$arguments
Definition: Route.php:69

◆ getCallable()

Slim\Route::getCallable ( )

Get route callable.

Returns
callable

Definition at line 131 of file Route.php.

132  {
133  return $this->callable;
134  }

◆ getGroups()

Slim\Route::getGroups ( )

Get parent route groups.

Returns
RouteGroup[]

Definition at line 161 of file Route.php.

162  {
163  return $this->groups;
164  }

◆ getIdentifier()

Slim\Route::getIdentifier ( )

Get route identifier.

Returns
string

Definition at line 181 of file Route.php.

182  {
183  return $this->identifier;
184  }
$identifier
Definition: Route.php:37

◆ getMethods()

Slim\Route::getMethods ( )

Get route methods.

Returns
string[]

Definition at line 151 of file Route.php.

152  {
153  return $this->methods;
154  }

◆ getName()

Slim\Route::getName ( )

Get route name.

Returns
null|string

Implements Slim\Interfaces\RouteInterface.

Definition at line 171 of file Route.php.

References $name.

172  {
173  return $this->name;
174  }

◆ getOutputBuffering()

Slim\Route::getOutputBuffering ( )

Get output buffering mode.

Returns
boolean|string

Definition at line 191 of file Route.php.

192  {
193  return $this->outputBuffering;
194  }
$outputBuffering
Definition: Route.php:62

◆ prepare()

Slim\Route::prepare ( ServerRequestInterface  $request,
array  $arguments 
)

Prepare the route for use.

Parameters
ServerRequestInterface$request
array$arguments

Implements Slim\Interfaces\RouteInterface.

Definition at line 305 of file Route.php.

306  {
307  // Remove temp arguments
308  $this->setArguments($this->savedArguments);
309 
310  // Add the route arguments
311  foreach ($arguments as $k => $v) {
312  $this->setArgument($k, $v, false);
313  }
314  }
setArgument($name, $value, $includeInSavedArguments=true)
Set a route argument.
Definition: Route.php:243
setArguments(array $arguments, $includeInSavedArguments=true)
Replace route arguments.
Definition: Route.php:260
$arguments
Definition: Route.php:69

◆ run()

Slim\Route::run ( ServerRequestInterface  $request,
ResponseInterface  $response 
)

Run route.

This method traverses the middleware stack, including the route's callable and captures the resultant HTTP response object. It then sends the response back to the Application.

Parameters
ServerRequestInterface$request
ResponseInterface$response
Returns
ResponseInterface

Implements Slim\Interfaces\RouteInterface.

Definition at line 328 of file Route.php.

References $handler, $request, $response, and Psr\Http\Message\MessageInterface\getBody().

329  {
330  // Finalise route now that we are about to run it
331  $this->finalize();
332 
333  // Traverse middleware stack and fetch updated response
334  return $this->callMiddlewareStack($request, $response);
335  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
finalize()
Finalize the route in preparation for dispatching.
Definition: Route.php:106
$response
+ Here is the call graph for this function:

◆ setArgument()

Slim\Route::setArgument (   $name,
  $value,
  $includeInSavedArguments = true 
)

Set a route argument.

Parameters
string$name
string$value
bool$includeInSavedArguments
Returns
self

Definition at line 243 of file Route.php.

References $name.

244  {
245  if ($includeInSavedArguments) {
246  $this->savedArguments[$name] = $value;
247  }
248  $this->arguments[$name] = $value;
249  return $this;
250  }

◆ setArguments()

Slim\Route::setArguments ( array  $arguments,
  $includeInSavedArguments = true 
)

Replace route arguments.

Parameters
array$arguments
bool$includeInSavedArguments
Returns
self

Definition at line 260 of file Route.php.

261  {
262  if ($includeInSavedArguments) {
263  $this->savedArguments = $arguments;
264  }
265  $this->arguments = $arguments;
266  return $this;
267  }
$arguments
Definition: Route.php:69

◆ setCallable()

Slim\Route::setCallable (   $callable)

This method enables you to override the Route's callable.

Parameters
string | \Closure$callable

Definition at line 141 of file Route.php.

142  {
143  $this->callable = $callable;
144  }

◆ setName()

Slim\Route::setName (   $name)

Set route name.

Parameters
string$name
Returns
self
Exceptions
InvalidArgumentExceptionif the route name is not a string

Implements Slim\Interfaces\RouteInterface.

Definition at line 225 of file Route.php.

References $name.

226  {
227  if (!is_string($name)) {
228  throw new InvalidArgumentException('Route name must be a string');
229  }
230  $this->name = $name;
231  return $this;
232  }

◆ setOutputBuffering()

Slim\Route::setOutputBuffering (   $mode)

Set output buffering mode.

One of: false, 'prepend' or 'append'

Parameters
boolean | string$mode
Returns
self
Exceptions
InvalidArgumentExceptionIf an unknown buffering mode is specified

Implements Slim\Interfaces\RouteInterface.

Definition at line 207 of file Route.php.

208  {
209  if (!in_array($mode, [false, 'prepend', 'append'], true)) {
210  throw new InvalidArgumentException('Unknown output buffering mode');
211  }
212  $this->outputBuffering = $mode;
213  return $this;
214  }

Field Documentation

◆ $arguments

Slim\Route::$arguments = []
protected

Definition at line 69 of file Route.php.

◆ $callable

Slim\Route::$callable
protected

Definition at line 83 of file Route.php.

◆ $finalized

Slim\Route::$finalized = false
private

Definition at line 53 of file Route.php.

◆ $groups

Slim\Route::$groups
protected

Definition at line 51 of file Route.php.

◆ $identifier

Slim\Route::$identifier
protected

Definition at line 37 of file Route.php.

◆ $methods

Slim\Route::$methods = []
protected

Definition at line 30 of file Route.php.

◆ $name

Slim\Route::$name
protected

Definition at line 44 of file Route.php.

◆ $outputBuffering

Slim\Route::$outputBuffering = 'append'
protected

Definition at line 62 of file Route.php.

◆ $savedArguments

Slim\Route::$savedArguments = []
protected

Definition at line 76 of file Route.php.


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