Overview
  • Namespace
  • Class

Namespaces

  • Slim
    • Exception
    • Handlers
      • Strategies
    • Http
    • Interfaces
      • Http

Classes

  • App
  • CallableResolver
  • Collection
  • Container
  • DefaultServicesProvider
  • DeferredCallable
  • Routable
  • Route
  • RouteGroup
  • Router

Traits

  • CallableResolverAwareTrait
  • MiddlewareAwareTrait

Class App

App

This is the primary class with which you instantiate, configure, and run a Slim Framework application. The \Slim\App class also accepts Slim Framework middleware.

Slim\App uses Slim\MiddlewareAwareTrait
Namespace: Slim
Located at App.php

Methods summary

public
# __construct( Psr\Container\ContainerInterface|array $container = [] )

Create new application

Create new application

Parameters

$container
Either a ContainerInterface or an associative array of app settings

Throws

InvalidArgumentException
when no container is provided that implements ContainerInterface
public Psr\Container\ContainerInterface
# getContainer( )

Enable access to the DI container by consumers of $app

Enable access to the DI container by consumers of $app

Returns

Psr\Container\ContainerInterface
public static
# add( callable|string $callable )

Add middleware

Add middleware

This method prepends new middleware to the app's middleware stack.

Parameters

$callable
The callback routine

Returns

static
public mixed
# __call( string $method, array $args )

Calling a non-existant method on App checks to see if there's an item in the container that is callable and if so, calls it.

Calling a non-existant method on App checks to see if there's an item in the container that is callable and if so, calls it.

Parameters

$method
$args

Returns

mixed
public Slim\Interfaces\RouteInterface
# get( string $pattern, callable|string $callable )

Add GET route

Add GET route

Parameters

$pattern
The route URI pattern
$callable
The route callback routine

Returns

Slim\Interfaces\RouteInterface
public Slim\Interfaces\RouteInterface
# post( string $pattern, callable|string $callable )

Add POST route

Add POST route

Parameters

$pattern
The route URI pattern
$callable
The route callback routine

Returns

Slim\Interfaces\RouteInterface
public Slim\Interfaces\RouteInterface
# put( string $pattern, callable|string $callable )

Add PUT route

Add PUT route

Parameters

$pattern
The route URI pattern
$callable
The route callback routine

Returns

Slim\Interfaces\RouteInterface
public Slim\Interfaces\RouteInterface
# patch( string $pattern, callable|string $callable )

Add PATCH route

Add PATCH route

Parameters

$pattern
The route URI pattern
$callable
The route callback routine

Returns

Slim\Interfaces\RouteInterface
public Slim\Interfaces\RouteInterface
# delete( string $pattern, callable|string $callable )

Add DELETE route

Add DELETE route

Parameters

$pattern
The route URI pattern
$callable
The route callback routine

Returns

Slim\Interfaces\RouteInterface
public Slim\Interfaces\RouteInterface
# options( string $pattern, callable|string $callable )

Add OPTIONS route

Add OPTIONS route

Parameters

$pattern
The route URI pattern
$callable
The route callback routine

Returns

Slim\Interfaces\RouteInterface
public Slim\Interfaces\RouteInterface
# any( string $pattern, callable|string $callable )

Add route for any HTTP method

Add route for any HTTP method

Parameters

$pattern
The route URI pattern
$callable
The route callback routine

Returns

Slim\Interfaces\RouteInterface
public Slim\Interfaces\RouteInterface
# map( array $methods, string $pattern, callable|string $callable )

Add route with multiple methods

Add route with multiple methods

Parameters

$methods
Numeric array of HTTP method names
$pattern
The route URI pattern
$callable
The route callback routine

Returns

Slim\Interfaces\RouteInterface
public Slim\Interfaces\RouteGroupInterface
# group( string $pattern, callable $callable )

Route Groups

Route Groups

This method accepts a route pattern and a callback. All route declarations in the callback will be prepended by the group(s) that it is in.

Parameters

$pattern
$callable

Returns

Slim\Interfaces\RouteGroupInterface
public Psr\Http\Message\ResponseInterface
# run( boolean|false $silent = false )

Run application

Run application

This method traverses the application middleware stack and then sends the resultant Response object to the HTTP client.

Parameters

$silent

Returns

Psr\Http\Message\ResponseInterface

Throws

Exception
Slim\Exception\MethodNotAllowedException
Slim\Exception\NotFoundException
protected Psr\Http\Message\ResponseInterface
# processInvalidMethod( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response )

Pull route info for a request with a bad method to decide whether to return a not-found error (default) or a bad-method error, then run the handler for that error, returning the resulting response.

Pull route info for a request with a bad method to decide whether to return a not-found error (default) or a bad-method error, then run the handler for that error, returning the resulting response.

Used for cases where an incoming request has an unrecognized method, rather than throwing an exception and not catching it all the way up.

Parameters

$request
$response

Returns

Psr\Http\Message\ResponseInterface
public Psr\Http\Message\ResponseInterface
# process( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response )

Process a request

Process a request

This method traverses the application middleware stack and then returns the resultant Response object.

Parameters

$request
$response

Returns

Psr\Http\Message\ResponseInterface

Throws

Exception
Slim\Exception\MethodNotAllowedException
Slim\Exception\NotFoundException
public
# respond( Psr\Http\Message\ResponseInterface $response )

Send the response the client

Send the response the client

Parameters

$response
public Psr\Http\Message\ResponseInterface
# __invoke( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response )

Invoke application

Invoke application

This method implements the middleware interface. It receives Request and Response objects, and it returns a Response object after compiling the routes registered in the Router and dispatching the Request object to the appropriate Route callback routine.

Parameters

$request
The most recent Request object
$response
The most recent Response object

Returns

Psr\Http\Message\ResponseInterface

Throws

Slim\Exception\MethodNotAllowedException
Slim\Exception\NotFoundException
public Psr\Http\Message\ResponseInterface
# subRequest( string $method, string $path, string $query = '', array $headers = [], array $cookies = [], string $bodyContent = '', Psr\Http\Message\ResponseInterface $response = null )

Perform a sub-request from within an application route

Perform a sub-request from within an application route

This method allows you to prepare and initiate a sub-request, run within the context of the current request. This WILL NOT issue a remote HTTP request. Instead, it will route the provided URL, method, headers, cookies, body, and server variables against the set of registered application routes. The result response object is returned.

Parameters

$method
The request method (e.g., GET, POST, PUT, etc.)
$path
The request URI path
$query
The request URI query string
$headers
The request headers (key-value array)
$cookies
The request cookies (key-value array)
$bodyContent
The request body
$response
The response object (optional)

Returns

Psr\Http\Message\ResponseInterface
protected Psr\Http\Message\ServerRequestInterface
# dispatchRouterAndPrepareRoute( Psr\Http\Message\ServerRequestInterface $request, Slim\Interfaces\RouterInterface $router )

Dispatch the router to find the route. Prepare the route for use.

Dispatch the router to find the route. Prepare the route for use.

Parameters

$request
$router

Returns

Psr\Http\Message\ServerRequestInterface
protected Psr\Http\Message\ResponseInterface
# finalize( Psr\Http\Message\ResponseInterface $response )

Finalize response

Finalize response

Parameters

$response

Returns

Psr\Http\Message\ResponseInterface
protected boolean
# isEmptyResponse( Psr\Http\Message\ResponseInterface $response )

Helper method, which returns true if the provided response must not output a body and false if the response could have a body.

Helper method, which returns true if the provided response must not output a body and false if the response could have a body.

Parameters

$response

Returns

boolean

See

https://tools.ietf.org/html/rfc7231
protected Psr\Http\Message\ResponseInterface
# handleException( Exception $e, Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response )

Call relevant handler from the Container if needed. If it doesn't exist, then just re-throw.

Call relevant handler from the Container if needed. If it doesn't exist, then just re-throw.

Parameters

$e
$request
$response

Returns

Psr\Http\Message\ResponseInterface

Throws

Exception
if a handler is needed and not found
protected Psr\Http\Message\ResponseInterface
# handlePhpError( Throwable $e, Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response )

Call relevant handler from the Container if needed. If it doesn't exist, then just re-throw.

Call relevant handler from the Container if needed. If it doesn't exist, then just re-throw.

Parameters

$e
$request
$response

Returns

Psr\Http\Message\ResponseInterface

Throws

Throwable

Methods used from Slim\MiddlewareAwareTrait

addMiddleware(), callMiddlewareStack(), seedMiddlewareStack()

Constants summary

string VERSION

Current version

Current version

# '3.9.0-dev'

Properties summary

Properties used from Slim\MiddlewareAwareTrait

$middlewareLock, $stack

Magic properties

public read-only callable $errorHandler
public read-only callable $phpErrorHandler
public read-only callable $notFoundHandler

function($request, $response)

public read-only callable $notAllowedHandler

function($request, $response, $allowedHttpMethods)

API documentation generated by ApiGen