PHPackages                             oscarpalmer/shelf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. oscarpalmer/shelf

AbandonedArchivedLibrary[Framework](/categories/framework)

oscarpalmer/shelf
=================

A Rack-like interface.

v3.6.0(4y ago)234511MITPHPPHP &gt;=8.0

Since May 6Pushed 4y ago1 watchersCompare

[ Source](https://github.com/oscarpalmer/shelf)[ Packagist](https://packagist.org/packages/oscarpalmer/shelf)[ Docs](https://github.com/oscarpalmer/shelf)[ RSS](/packages/oscarpalmer-shelf/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (2)Versions (20)Used By (1)

Shelf
=====

[](#shelf)

[![Latest stable version](https://camo.githubusercontent.com/f694416c3ed62a67bcc6620b7580a7c0ddba6635ce7f624b0f08029e4af40f0f/68747470733a2f2f706f7365722e707567782e6f72672f6f7363617270616c6d65722f7368656c662f76)](//packagist.org/packages/oscarpalmer/shelf) [![Build status](https://camo.githubusercontent.com/5e79490475881d28dd2ff492c51a916451d474e5a5c3c0a2879dba766bab7c07/68747470733a2f2f6170692e7472617669732d63692e636f6d2f6f7363617270616c6d65722f7368656c662e7376673f6272616e63683d6d61696e)](https://travis-ci.com/oscarpalmer/shelf) [![Code coverage](https://camo.githubusercontent.com/1864f924929d7b73c17ce7c0678d6fb4faabc305019c0f2d471af883010e4fe4/68747470733a2f2f636f6465636f762e696f2f67682f6f7363617270616c6d65722f7368656c662f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d4845333242754a456d74)](https://codecov.io/gh/oscarpalmer/shelf) [![License](https://camo.githubusercontent.com/641dbe83326e05d74d725511e05f14f0124dbbb8d4665e8c83ccf1cf45753f75/68747470733a2f2f706f7365722e707567782e6f72672f6f7363617270616c6d65722f7368656c662f6c6963656e7365)](//packagist.org/packages/oscarpalmer/shelf)

Shelf is a [Rack](//rack.github.io)-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](https://github.com/topics/psr-7). 😄

Getting started
---------------

[](#getting-started)

### Installation

[](#installation)

Shelf is available via [Composer &amp; Packagist](//packagist.org/packages/oscarpalmer/shelf).

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

### Basic usage

[](#basic-usage)

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

#### Request

[](#request)

```
use oscarpalmer\Shelf\Request;

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

echo $request->path_info;
```

#### Response

[](#response)

```
use oscarpalmer\Shelf\Response;

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

$response->finish($request);
```

API
---

[](#api)

### Shelf

[](#shelf-1)

```
# Shelf version
Shelf::VERSION
```

### Request

[](#request-1)

```
# 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
$request->isDelete();
$request->isGet();
$request->isHead();
$request->isOptions();
$request->isPatch();
$request->isPost();
$request->isPut();

# Check if HTTP request was made via AJAX
$request->isAjax();

# 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 :)
Shelf\Request::fromGlobals($session);
```

### Response

[](#response-1)

```
# 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
$response->getBody();

# Retrieves the value for a header
$response->getHeader();

# Retrieves all headers
$response->getHeaders();

# Retrieves the status code
$response->getStatus();

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

# Set a scalar value as the response body
$response->setBody($body);

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

# Set multiple respons headers
$response->setHeaders($headers);

# Set response status
$response->setStatus($status);

# Append scalar value to the response body
$response->write($content);
```

### Files

[](#files)

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
```

### Blob

[](#blob)

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
$blob->all();

# Delete a value by key
$blob->delete($key);

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

# Check if Blob has key
$blob->has($key);

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

License
-------

[](#license)

MIT Licensed; see [the LICENSE file](LICENSE) for more info.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~152 days

Recently: every ~8 days

Total

18

Last Release

1790d ago

Major Versions

v1.4.0 → v2.0.02017-10-27

v2.3.1 → v3.0.02021-05-09

PHP version history (3 changes)v1.0.0PHP &gt;=5.3.0

v2.0.0PHP &gt;=7.0

v3.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e5647f0434aa5576876d278b8cffa863b69d5cc26acb5e7f08c8ef5816a689c?d=identicon)[oscarpalmer](/maintainers/oscarpalmer)

---

Top Contributors

[![oscarpalmer](https://avatars.githubusercontent.com/u/27967?v=4)](https://github.com/oscarpalmer "oscarpalmer (70 commits)")

---

Tags

httpphprackhttpframework

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/oscarpalmer-shelf/health.svg)

```
[![Health](https://phpackages.com/badges/oscarpalmer-shelf/health.svg)](https://phpackages.com/packages/oscarpalmer-shelf)
```

###  Alternatives

[hprose/hprose

It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.

2.1k215.3k37](/packages/hprose-hprose)[hprose/hprose-yii

Hprose Server for Yii 2

357.1k](/packages/hprose-hprose-yii)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
