Skip to content

Environment

Overview

The Skinny Framework implements a derivation of the Rack protocol. When you instantiate a Skinny application, it immediately inspects the $_SERVER superglobal and derives a set of environment variables that dictate application behavior.

What is the Environment?

A Skinny application’s “environment” is an associative array of settings that are parsed once and made accessible to the Skinny application and its middleware. You are free to modify the environment variables during runtime; changes will propagate immediately throughout the application.

When you instantiate a Skinny application, the environment variables are derived from the $_SERVER superglobal; you do not need to set these yourself. However, you are free to modify or supplement these variables in Skinny middleware.

These variables are fundamental to determining how your Skinny application runs: the resource URI, the HTTP method, the HTTP request body, the URL query parameters, error output, and more. Middleware, described later, gives you the power to — among other things — manipulate environment variables before and/or after the Skinny application is run.

Environment Variables

The environment array must include these variables:

REQUEST_METHOD
The HTTP request method. This is required and may never be an empty string.
SCRIPT_NAME
The initial portion of the request URI’s “path” that corresponds to the physical directory in which the Skinny application is installed — so that the application knows its virtual “location”. This may be an empty string if the application is installed in the top-level of the public document root directory. This will never have a trailing slash.
PATH_INFO
The remaining portion of the request URI’s “path” that determines the “virtual” location of the HTTP request’s target resource within the Skinny application context. This will always have a leading slash; it may or may not have a trailing slash.
QUERY_STRING
The part of the HTTP request’s URI after, but not including, the “?”. This is required but may be an empty string.
SERVER_NAME
When combined with SCRIPT_NAME and PATH_INFO, this can be used to create a fully qualified URL to an application resource. However, if HTTP_HOST is present, that should be used instead of this. This is required and may never be an empty string.
SERVER_PORT
When combined with SCRIPT_NAME and PATH_INFO, this can be used to create a fully qualified URL to any application resource. This is required and may never be an empty string.
HTTP_*
Variables matching the HTTP request headers sent by the client. The existence of these variables correspond with those sent in the current HTTP request.
skinny.url_scheme
Will be “http” or “https” depending on the HTTP request URL.
skinny.input
Will be a string representing the raw HTTP request body. If the HTTP request body is empty (e.g. with a GET request), this will be an empty string.
skinny.errors
Must always be a writable resource; by default, this is a write-only resource handle to php://stderr.
inputstream.limit
Maximum number of bytes allowed from php://input.
inputstream.auth
(bool)inputstream.auth must evaluate to true in order to capture php://input as a stream resource.
inputstream.expected
Number of input bytes expected from php://input.
inputstream.received
Number of bytes captured from php://input.
inputstream.handle
A valid resource handle to temporary file into which php://input was captured.
inputstream.errcode
An integer corresponding to one of the `\Skinny\Environment::INPUTSTREAM_*` constants.

The Skinny application can store its own data in the environment, too. The environment array’s keys must contain at least one dot, and should be prefixed uniquely (e.g. “prefix.foo”). The prefix skinny. is reserved for use by Skinny itself and must not be used otherwise. The prefix inputstream. is also reserved for Skiiny's internal use. The environment must not contain the keys HTTP_CONTENT_TYPE or HTTP_CONTENT_LENGTH (use the versions without HTTP_). The CGI keys (named without a period) must have String values. There are the following restrictions:

  • skinny.url_scheme must either be “http” or “https”.

  • skinny.input must be a string.

  • There must be a valid, writable resource in skinny.errors.

  • The REQUEST_METHOD must be a valid token.

  • The SCRIPT_NAME, if non-empty, must start with “/”

  • The PATH_INFO, if non-empty, must start with “/”

  • The CONTENT_LENGTH, if given, must consist of digits only.

  • One of SCRIPT_NAME or PATH_INFO must be set. PATH_INFO should be “/” if SCRIPT_NAME is empty. SCRIPT_NAME never should be “/”, but instead be an empty string.