2017 © Pedro Peláez
 

library shelf

A Rack-like interface.

image

oscarpalmer/shelf

A Rack-like interface.

  • Thursday, March 8, 2018
  • by oscarpalmer
  • Repository
  • 1 Watchers
  • 2 Stars
  • 287 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Shelf

Latest stable version Build status Code coverage License, (*1)

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

If you need to work with requests and responses in PHP, please consider using a PSR-7 compliant library. :smile:, (*3)

Getting started

Installation

Shelf is available via Composer & Packagist., (*4)

{
  "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., (*5)

Request

use oscarpalmer\Shelf\Request;

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

echo $request->path_info;

Response

use oscarpalmer\Shelf\Response;

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

$response->finish($request);

API

Shelf

# Shelf version
Shelf::VERSION

Request

# 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

# 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

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

# 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

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., (*7)

# 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

MIT Licensed; see the LICENSE file for more info., (*8)

The Versions

08/03 2018

dev-master

9999999-dev https://github.com/oscarpalmer/shelf

A Rack-like interface.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

framework http

08/03 2018

v2.3.1

2.3.1.0 https://github.com/oscarpalmer/shelf

A Rack-like interface.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

framework http

07/03 2018

v2.3.0

2.3.0.0 https://github.com/oscarpalmer/shelf

A Rack-like interface.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

framework http

17/02 2018

v2.2.0

2.2.0.0 https://github.com/oscarpalmer/shelf

A Rack-like interface.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

framework http

14/02 2018

v2.1.1

2.1.1.0 https://github.com/oscarpalmer/shelf

A Rack-like interface.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

framework http

13/02 2018

v2.1.0

2.1.0.0 https://github.com/oscarpalmer/shelf

A Rack-like interface.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

framework http

27/10 2017

v2.0.0

2.0.0.0 https://github.com/oscarpalmer/shelf

A Rack-like interface.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

framework http

01/02 2015

v1.4.0

1.4.0.0 http://git.io/shelf

A Rack-like interface.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

framework http

31/01 2015

v1.3.0

1.3.0.0 http://git.io/shelf

A Rack-like interface.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

framework http

10/01 2015

v1.2.0

1.2.0.0 http://git.io/shelf

A Rack-like interface.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

framework http

20/12 2014

v1.1.0

1.1.0.0 http://git.io/shelf

A Rack-like interface.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

framework http

06/05 2014

v1.0.0

1.0.0.0 http://git.io/shelf

A Rack-like interface.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

framework http