Overview

Namespaces

  • api
  • config
  • database
  • PHP
  • Slim
    • Exception
    • Http
    • Middleware
  • utiliy

Classes

  • Environment
  • Log
  • LogWriter
  • Middleware
  • Route
  • Router
  • Slim
  • View
  • Overview
  • Namespace
  • Class
  • Tree

Class Slim

Slim

Direct known subclasses

api\Api

Indirect known subclasses

api\PisApi, api\PssApi, api\SpsApi
Namespace: Slim
Package: Slim
Author: Josh Lockhart
Since: 1.0.0
Located at thirdparty/Slim/Slim.php
Methods summary
public static
# autoload( mixed $className )

Slim PSR-0 autoloader

Slim PSR-0 autoloader

public static
# registerAutoloader( )

Register Slim's PSR-0 autoloader

Register Slim's PSR-0 autoloader

public
# __construct( array $userSettings = array() )

Constructor

Constructor

Parameters

$userSettings
array
$userSettings Associative array of application settings
public static Slim|null
# getInstance( string $name = 'default' )

Get application instance by name

Get application instance by name

Parameters

$name
string
$name The name of the Slim application

Returns

Slim|null
public
# setName( string $name )

Set Slim application name

Set Slim application name

Parameters

$name
string
$name The name of this Slim application
public string|null
# getName( )

Get Slim application name

Get Slim application name

Returns

string|null
public static array
# getDefaultSettings( )

Get default application settings

Get default application settings

Returns

array
public mixed
# config( string|array $name, mixed $value = null )

Configure Slim Settings

Configure Slim Settings

This method defines application settings and acts as a setter and a getter.

If only one argument is specified and that argument is a string, the value of the setting identified by the first argument will be returned, or NULL if that setting does not exist.

If only one argument is specified and that argument is an associative array, the array will be merged into the existing application settings.

If two arguments are provided, the first argument is the name of the setting to be created or updated, and the second argument is the setting value.

Parameters

$name
string|array
$name If a string, the name of the setting to set or retrieve. Else an associated array of setting names and values
$value
mixed
$value If name is a string, the value of the setting identified by $name

Returns

mixed
The value of a setting if only one argument is a string
public string
# getMode( )

Get application mode

Get application mode

This method determines the application mode. It first inspects the $_ENV superglobal for key SLIM_MODE. If that is not found, it queries the getenv function. Else, it uses the application mode setting.

Returns

string
public
# configureMode( string $mode, mixed $callable )

Configure Slim for a given mode

Configure Slim for a given mode

This method will immediately invoke the callable if the specified mode matches the current application mode. Otherwise, the callable is ignored. This should be called only _after_ you initialize your Slim app.

Parameters

$mode
string
$mode
$callable
mixed
$callable
public Slim\Log
# getLog( )

Get application log

Get application log

Returns

Slim\Log
protected Slim\Route
# mapRoute( array $args )

Add GET|POST|PUT|DELETE route

Add GET|POST|PUT|DELETE route

Adds a new route to the router with associated callable. This route will only be invoked when the HTTP request's method matches this route's method.

ARGUMENTS:

First: string The URL pattern (REQUIRED) In-Between: mixed Anything that returns TRUE for is_callable (OPTIONAL) Last: mixed Anything that returns TRUE for is_callable (REQUIRED)

The first argument is required and must always be the route pattern (ie. '/books/:id').

The last argument is required and must always be the callable object to be invoked when the route matches an HTTP request.

You may also provide an unlimited number of in-between arguments; each interior argument must be callable and will be invoked in the order specified before the route's callable is invoked.

USAGE:

Slim::get('/foo'[, middleware, middleware, ...], callable);

Parameters

$args
array
(See notes above)

Returns

Slim\Route
public Slim\Route
# map( )

Add generic route without associated HTTP method

Add generic route without associated HTTP method

Returns

Slim\Route

See

Slim\Slim::mapRoute()
public Slim\Route
# get( )

Add GET route

Add GET route

Returns

Slim\Route

See

Slim\Slim::mapRoute()
public Slim\Route
# post( )

Add POST route

Add POST route

Returns

Slim\Route

See

Slim\Slim::mapRoute()
public Slim\Route
# put( )

Add PUT route

Add PUT route

Returns

Slim\Route

See

Slim\Slim::mapRoute()
public Slim\Route
# delete( )

Add DELETE route

Add DELETE route

Returns

Slim\Route

See

Slim\Slim::mapRoute()
public Slim\Route
# options( )

Add OPTIONS route

Add OPTIONS route

Returns

Slim\Route

See

Slim\Slim::mapRoute()
public
# notFound( mixed $callable = null )

Not Found Handler

Not Found Handler

This method defines or invokes the application-wide Not Found handler. There are two contexts in which this method may be invoked:

1. When declaring the handler:

If the $callable parameter is not null and is callable, this method will register the callable to be invoked when no routes match the current HTTP request. It WILL NOT invoke the callable.

2. When invoking the handler:

If the $callable parameter is null, Slim assumes you want to invoke an already-registered handler. If the handler has been registered and is callable, it is invoked and sends a 404 HTTP Response whose body is the output of the Not Found handler.

Parameters

$callable
mixed
$callable Anything that returns true for is_callable()
public
# error( mixed $argument = null )

Error Handler

Error Handler

This method defines or invokes the application-wide Error handler. There are two contexts in which this method may be invoked:

1. When declaring the handler:

If the $argument parameter is callable, this method will register the callable to be invoked when an uncaught Exception is detected, or when otherwise explicitly invoked. The handler WILL NOT be invoked in this context.

2. When invoking the handler:

If the $argument parameter is not callable, Slim assumes you want to invoke an already-registered handler. If the handler has been registered and is callable, it is invoked and passed the caught Exception as its one and only argument. The error handler's output is captured into an output buffer and sent as the body of a 500 HTTP Response.

Parameters

$argument
mixed
$argument Callable|\Exception
protected string
# callErrorHandler( Exception|null $argument = null )

Call error handler

Call error handler

This will invoke the custom or default error handler and RETURN its output.

Parameters

$argument
Exception|null
$argument

Returns

string
public Slim\Environment
# environment( )

Get a reference to the Environment object

Get a reference to the Environment object

Returns

Slim\Environment
public Slim\Http\Request
# request( )

Get the Request object

Get the Request object

Returns

Slim\Http\Request
public Slim\Http\Response
# response( )

Get the Response object

Get the Response object

Returns

Slim\Http\Response
public Slim\Router
# router( )

Get the Router object

Get the Router object

Returns

Slim\Router
public Slim\View
# view( string|Slim\View $viewClass = null )

Get and/or set the View

Get and/or set the View

This method declares the View to be used by the Slim application. If the argument is a string, Slim will instantiate a new object of the same class. If the argument is an instance of View or a subclass of View, Slim will use the argument as the View.

If a View already exists and this method is called to create a new View, data already set in the existing View will be transferred to the new View.

Parameters

$viewClass
string|Slim\View
$viewClass The name or instance of a \Slim\View subclass

Returns

Slim\View
public
# render( string $template, array $data = array(), integer $status = null )

Render a template

Render a template

Call this method within a GET, POST, PUT, DELETE, NOT FOUND, or ERROR callable to render a template whose output is appended to the current HTTP response body. How the template is rendered is delegated to the current View.

Parameters

$template
string
$template The name of the template passed into the view's render() method
$data
array
$data Associative array of data made available to the view
$status
integer
$status The HTTP response status code to use (optional)
public
# lastModified( integer $time )

Set Last-Modified HTTP Response Header

Set Last-Modified HTTP Response Header

Set the HTTP 'Last-Modified' header and stop if a conditional GET request's If-Modified-Since header matches the last modified time of the resource. The time argument is a UNIX timestamp integer value. When the current request includes an 'If-Modified-Since' header that matches the specified last modified time, the application will stop and send a '304 Not Modified' response to the client.

Parameters

$time
integer
$time The last modified UNIX timestamp

Throws

InvalidArgumentException
If provided timestamp is not an integer
public
# etag( string $value, string $type = 'strong' )

Set ETag HTTP Response Header

Set ETag HTTP Response Header

Set the etag header and stop if the conditional GET request matches. The value argument is a unique identifier for the current resource. The type argument indicates whether the etag should be used as a strong or weak cache validator.

When the current request includes an 'If-None-Match' header with a matching etag, execution is immediately stopped. If the request method is GET or HEAD, a '304 Not Modified' response is sent.

Parameters

$value
string
$value The etag value
$type
string
$type The type of etag to create; either "strong" or "weak"

Throws

InvalidArgumentException
If provided type is invalid
public
# expires( string|integer $time )

Set Expires HTTP response header

Set Expires HTTP response header

The Expires header tells the HTTP client the time at which the current resource should be considered stale. At that time the HTTP client will send a conditional GET request to the server; the server may return a 200 OK if the resource has changed, else a 304 Not Modified if the resource has not changed. The Expires header should be used in conjunction with the etag() or lastModified() methods above.

Parameters

$time
string|integer
$time If string, a time to be parsed by strtotime(); If int, a UNIX timestamp;
public
# setCookie( string $name, string $value, integer|string $time = null, string $path = null, string $domain = null, boolean $secure = null, boolean $httponly = null )

Set unencrypted HTTP cookie

Set unencrypted HTTP cookie

Parameters

$name
string
$name The cookie name
$value
string
$value The cookie value
$time
integer|string
$time The duration of the cookie; If integer, should be UNIX timestamp; If string, converted to UNIX timestamp with strtotime;
$path
string
$path The path on the server in which the cookie will be available on
$domain
string
$domain The domain that the cookie is available to
$secure
boolean
$secure Indicates that the cookie should only be transmitted over a secure HTTPS connection to/from the client
$httponly
boolean
$httponly When TRUE the cookie will be made accessible only through the HTTP protocol
public string|null
# getCookie( string $name )

Get value of unencrypted HTTP cookie

Get value of unencrypted HTTP cookie

Return the value of a cookie from the current HTTP request, or return NULL if cookie does not exist. Cookies created during the current request will not be available until the next request.

Parameters

$name
string
$name

Returns

string|null
public
# setEncryptedCookie( string $name, mixed $value, mixed $expires = null, string $path = null, string $domain = null, boolean $secure = null, boolean $httponly = null )

Set encrypted HTTP cookie

Set encrypted HTTP cookie

Parameters

$name
string
$name The cookie name
$value
mixed
$value The cookie value
$expires
mixed
$expires The duration of the cookie; If integer, should be UNIX timestamp; If string, converted to UNIX timestamp with strtotime;
$path
string
$path The path on the server in which the cookie will be available on
$domain
string
$domain The domain that the cookie is available to
$secure
boolean
$secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client
$httponly
boolean
$httponly When TRUE the cookie will be made accessible only through the HTTP protocol
public string|false
# getEncryptedCookie( string $name, mixed $deleteIfInvalid = true )

Get value of encrypted HTTP cookie

Get value of encrypted HTTP cookie

Return the value of an encrypted cookie from the current HTTP request, or return NULL if cookie does not exist. Encrypted cookies created during the current request will not be available until the next request.

Parameters

$name
string
$name
$deleteIfInvalid

Returns

string|false
public
# deleteCookie( string $name, string $path = null, string $domain = null, boolean $secure = null, boolean $httponly = null )

Delete HTTP cookie (encrypted or unencrypted)

Delete HTTP cookie (encrypted or unencrypted)

Remove a Cookie from the client. This method will overwrite an existing Cookie with a new, empty, auto-expiring Cookie. This method's arguments must match the original Cookie's respective arguments for the original Cookie to be removed. If any of this method's arguments are omitted or set to NULL, the default Cookie setting values (set during Slim::init) will be used instead.

Parameters

$name
string
$name The cookie name
$path
string
$path The path on the server in which the cookie will be available on
$domain
string
$domain The domain that the cookie is available to
$secure
boolean
$secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client
$httponly
boolean
$httponly When TRUE the cookie will be made accessible only through the HTTP protocol
public string
# root( )

Get the absolute path to this Slim application's root directory

Get the absolute path to this Slim application's root directory

This method returns the absolute path to the Slim application's directory. If the Slim application is installed in a public-accessible sub-directory, the sub-directory path will be included. This method will always return an absolute path WITH a trailing slash.

Returns

string
protected
# cleanBuffer( )

Clean current output buffer

Clean current output buffer

public
# stop( )

Stop

Stop

The thrown exception will be caught in application's call() method and the response will be sent as is to the HTTP client.

Throws

Slim\Exception\Stop
public
# halt( integer $status, string $message = '' )

Halt

Halt

Stop the application and immediately send the response with a specific status and body to the HTTP client. This may send any type of response: info, success, redirect, client error, or server error. If you need to render a template AND customize the response status, use the application's render() method instead.

Parameters

$status
integer
$status The HTTP response status
$message
string
$message The HTTP response body
public
# pass( )

Pass

Pass

The thrown exception is caught in the application's call() method causing the router's current iteration to stop and continue to the subsequent route if available. If no subsequent matching routes are found, a 404 response will be sent to the client.

Throws

Slim\Exception\Pass
public
# contentType( string $type )

Set the HTTP response Content-Type

Set the HTTP response Content-Type

Parameters

$type
string
$type The Content-Type for the Response (ie. text/html)
public
# status( integer $code )

Set the HTTP response status code

Set the HTTP response status code

Parameters

$code
integer
$status The HTTP response status code
public string
# urlFor( string $name, array $params = array() )

Get the URL for a named route

Get the URL for a named route

Parameters

$name
string
$name The route name
$params
array
$params Associative array of URL parameters and replacement values

Returns

string

Throws

RuntimeException
If named route does not exist
public
# redirect( string $url, integer $status = 302 )

Redirect

Redirect

This method immediately redirects to a new URL. By default, this issues a 302 Found response; this is considered the default generic redirect response. You may also specify another valid 3xx status code if you want. This method will automatically set the HTTP Location header for you using the URL parameter.

Parameters

$url
string
$url The destination URL
$status
integer
$status The HTTP redirect status code (optional)
public
# flash( string $key, mixed $value )

Set flash message for subsequent request

Set flash message for subsequent request

Parameters

$key
string
$key
$value
mixed
$value
public
# flashNow( string $key, mixed $value )

Set flash message for current request

Set flash message for current request

Parameters

$key
string
$key
$value
mixed
$value
public
# flashKeep( )

Keep flash messages from previous request for subsequent request

Keep flash messages from previous request for subsequent request

public
# hook( string $name, mixed $callable, integer $priority = 10 )

Assign hook

Assign hook

Parameters

$name
string
$name The hook name
$callable
mixed
$callable A callable object
$priority
integer
$priority The hook priority; 0 = high, 10 = low
public
# applyHook( string $name, mixed $hookArg = null )

Invoke hook

Invoke hook

Parameters

$name
string
$name The hook name
$hookArg
mixed
$hookArgs (Optional) Argument for hooked functions
public array|null
# getHooks( string $name = null )

Get hook listeners

Get hook listeners

Return an array of registered hooks. If $name is a valid hook name, only the listeners attached to that hook are returned. Else, all listeners are returned as an associative array whose keys are hook names and whose values are arrays of listeners.

Parameters

$name
string
$name A hook name (Optional)

Returns

array|null
public
# clearHooks( string $name = null )

Clear hook listeners

Clear hook listeners

Clear all listeners for all hooks. If $name is a valid hook name, only the listeners attached to that hook will be cleared.

Parameters

$name
string
$name A hook name (Optional)
public
# add( Slim\Middleware $newMiddleware )

Add middleware

Add middleware

This method prepends new middleware to the application middleware stack. The argument must be an instance that subclasses Slim_Middleware.

Parameters

$newMiddleware
Slim\Middleware
public
# run( )

Run

Run

This method invokes the middleware stack, including the core Slim application; the result is an array of HTTP status, header, and body. These three items are returned to the HTTP client.

public
# call( )

Call

Call

This method finds and iterates all route objects that match the current request URI.

public static true
# handleErrors( integer $errno, string $errstr = '', string $errfile = '', integer $errline = '' )

Convert errors into ErrorException objects

Convert errors into ErrorException objects

This method catches PHP errors and converts them into \ErrorException objects; these \ErrorException objects are then thrown and caught by Slim's built-in or custom error handlers.

Parameters

$errno
integer
$errno The numeric type of the Error
$errstr
string
$errstr The error message
$errfile
string
$errfile The absolute path to the affected file
$errline
integer
$errline The line number of the error in the affected file

Returns

true

Throws

ErrorException
protected static string
# generateTemplateMarkup( string $title, string $body )

Generate diagnostic template markup

Generate diagnostic template markup

This method accepts a title and body content to generate an HTML document layout.

Parameters

$title
string
$title The title of the HTML template
$body
string
$body The body content of the HTML template

Returns

string
protected
# defaultNotFound( )

Default Not Found handler

Default Not Found handler

protected
# defaultError( mixed $e )

Default Error handler

Default Error handler

Constants summary
string VERSION '2.2.0'
#

Const

string
Properties summary
protected static array[\Slim] $apps array()
#
protected string $name
#
protected array $environment
#
protected Slim\Http\Request $request
#
protected Slim\Http\Response $response
#
protected Slim\Router $router
#
protected Slim\View $view
#
protected array $settings
#
protected string $mode
#
protected array $middleware
#
protected mixed $error
#

Callable to be invoked if application error

Callable to be invoked if application error

protected mixed $notFound
#

Callable to be invoked if no matching routes are found

Callable to be invoked if no matching routes are found

protected array $hooks array( 'slim.before' => array(array()), 'slim.before.router' => array(array()), 'slim.before.dispatch' => array(array()), 'slim.after.dispatch' => array(array()), 'slim.after.router' => array(array()), 'slim.after' => array(array()) )
#
GeoApi API documentation generated by ApiGen 2.8.0