30 protected $methods = [];
53 private $finalized =
false;
62 protected $outputBuffering =
'append';
69 protected $arguments = [];
76 protected $savedArguments = [];
94 public function __construct($methods, $pattern, $callable, $groups = [], $identifier = 0)
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;
108 if ($this->finalized) {
112 $groupMiddleware = [];
113 foreach ($this->getGroups() as $group) {
114 $groupMiddleware = array_merge($group->getMiddleware(), $groupMiddleware);
117 $this->middleware = array_merge($this->middleware, $groupMiddleware);
119 foreach ($this->getMiddleware() as $middleware) {
123 $this->finalized =
true;
133 return $this->callable;
143 $this->callable = $callable;
153 return $this->methods;
163 return $this->groups;
183 return $this->identifier;
193 return $this->outputBuffering;
209 if (!in_array($mode, [
false,
'prepend',
'append'],
true)) {
212 $this->outputBuffering = $mode;
227 if (!is_string(
$name)) {
245 if ($includeInSavedArguments) {
246 $this->savedArguments[
$name] = $value;
248 $this->arguments[
$name] = $value;
262 if ($includeInSavedArguments) {
263 $this->savedArguments = $arguments;
265 $this->arguments = $arguments;
276 return $this->arguments;
289 if (array_key_exists(
$name, $this->arguments)) {
290 return $this->arguments[
$name];
308 $this->setArguments($this->savedArguments);
311 foreach ($arguments as $k => $v) {
312 $this->setArgument($k, $v,
false);
334 return $this->callMiddlewareStack($request, $response);
351 $this->callable = $this->resolveCallable($this->callable);
356 $newResponse =
$handler($this->callable, $request, $response, $this->arguments);
360 $response = $newResponse;
361 } elseif (is_string($newResponse)) {
363 if ($response->
getBody()->isWritable()) {
364 $response->
getBody()->write($newResponse);
prepare(ServerRequestInterface $request, array $arguments)
Prepare the route for use.
setName($name)
Set route name.
setOutputBuffering($mode)
Set output buffering mode.
getCallable()
Get route callable.
Representation of an incoming, server-side HTTP request.
trait MiddlewareAwareTrait
Middleware.
setArgument($name, $value, $includeInSavedArguments=true)
Set a route argument.
__construct($methods, $pattern, $callable, $groups=[], $identifier=0)
Create new route.
getArgument($name, $default=null)
Retrieve a specific route argument.
getMethods()
Get route methods.
getOutputBuffering()
Get output buffering mode.
run(ServerRequestInterface $request, ResponseInterface $response)
Run route.
setArguments(array $arguments, $includeInSavedArguments=true)
Replace route arguments.
getArguments()
Retrieve route arguments.
getIdentifier()
Get route identifier.
addMiddleware(callable $callable)
Add middleware.
getBody()
Gets the body of the message.
finalize()
Finalize the route in preparation for dispatching.
Representation of an outgoing, server-side response.
Create styles array
The data for the language used.
Default route callback strategy with route parameters as an array of arguments.
Slim Framework (https://slimframework.com)
setCallable($callable)
This method enables you to override the Route's callable.
getGroups()
Get parent route groups.