This package is abandoned and no longer maintained. No replacement package was suggested.

A Rack-like interface.

v3.6.0 2021-06-18 17:01 UTC


Latest stable version Build status Code coverage License

Shelf is a Rack-like interface for PHP >=8, but is not actively maintained.

If you need to work with requests and responses in PHP, please consider using a PSR-7 compliant library. 😄

Getting started


Shelf is available via Composer & Packagist.

  "require": {
    "oscarpalmer/shelf": "3.6.*"

Basic usage

Here are two small examples to get you up and running in ~ten seconds. Please consult the API reference if you get stuck or want to learn more.


use oscarpalmer\Shelf\Request;

$request = new Request($server); # Or new Request::fromGlobals();

echo $request->path_info;


use oscarpalmer\Shelf\Response;

$response = new Response(
    'Hello, world!',
    ['Content-Type' => 'text/plain']




# Shelf version


# Constructor
# Takes an array of server variables and a session variable;
# the session variable can be either boolean (to enable/disable sessions),
# or a string (to enable a session with a unique name)
$request = new Shelf\Request($server, $session);

# Check if HTTP request matches an expected type

# Check if HTTP request was made via AJAX

# Getters for Blobs (described below) for accessing HTTP request information
$request->getCookies(); # $_COOKIES
$request->getData();    # $_POST
$request->getQuery();   # $_GET
$request->getServer();  # $_SERVER or custom server variables
$request->getSession(); # $_SESSION

# Getter for uploaded files; a more detailed description can be found below
$request->getFiles(); # $_FILES

# Alternative to using the constructor; automatically uses the $_SERVER-variables
# The session variable still works the same :)


# Constructor
# Takes a scalar body, an HTTP status code, and an array of HTTP headers
$response = new Shelf\Response($body, $status, $headers);

# Retrieves the response body as a string

# Retrieves the value for a header

# Retrieves all headers

# Retrieves the status code 

# Retrieves a status message for the current response, e.g. '200 OK'
$response->getStatusMessage($code); # Or retrieve a specific status message

# Set a scalar value as the response body

# Set a response header
$response->setHeader($key, $value);

# Set multiple respons headers

# Set response status

# Append scalar value to the response body


Uploaded files can be accessed with $request->getFiles() which returns a Files-object containing a File-object for each file.

# Files

$files->name;              # Returns a File, or array of Files
$files->get('name');       # A less magical version of the above

# File

$file->getError();         # Error code for uploaded file
$file->getName();          # Original file name for uploaded file
$file->getSize();          # File size for uploaded file
$file->getTemporaryName(); # Temporary file name for uploaded file
$file->getType();          # File type for uploaded file


Blobs are containers used to store any kind of iterable data. In the Request-class, Blobs are used to manage $_COOKIES, $_FILES, $_GET, $_POST, $_SERVER (or custom server variables), and $_SESSION-information. In the Response-class, a Blob is used to manage HTTP-headers.

# Retrieve all Blob values as an array

# Delete a value by key

# Retrieve a value by key with an optional default value
$blob->get($key, $default);

# Check if Blob has key

# Set value by key
$blob->set($key, $value);


MIT Licensed; see the LICENSE file for more info.