Download the PHP package fracture/http without Composer

On this page you can find all versions of the php package fracture/http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package http

Fracture\Http

Build Status Code Coverage Scrutinizer Packagist

Introduction

A simple abstraction for handling the HTTP requests and responses. Library is made for interacting with fracture\routing and provides simple object-oriented interface.

Installation

You can add the library to your project using composer with following command:

Usage

All of the following code will assume that the Composer's autoloader has already been included.

Basic request initialization

While initializing a new Request instance manually is possible, for said instance to be fully prepared, it require several additional steps. To simplify this process, you should use RequestBuider, which will perform all of those steps:

Use of this code fragment is sufficient for any basic website and will produces a ready-to-use Request instance.

Requests and REST

When creating a site, that provides REST API, a common practice is to implement API versioning via HTTP Accept and Content-Type headers. But, if you send a POST query with custom Content-Type header, PHP will not populate $_POST with the information, that you sent to the server. And there are no $_PUT and $_DETETE superglobals in PHP.

To retrieve data information in a usable form, you have define a content parser, which, if the media type matches, is executed to supplement the Request instance with additional parameters.

It is possible for RequestBuilder instance to have multiple content parsers added.

Content parsers

A content parser is defined as an anonymous function, which will be executed with Fracture\Http\Headers\ContentType and Fracture\Http\Request instances as parameters and is expected to return an array of name => value pairs for parameters.

You can also use content parsers to override Request attributes. For example, if you want to alter the request method, when submitting for with "magic" parameter like <input type="hidden" name="_my_method" value="PUT" /> (which is a common approach for making more RESTful and bypass the limitations of standard webpage):

Accessing data in the request

When the instance of Request has been fully initialized (preferably, using RequestBuilder), you gain ability to extract several types of information from this abstraction.

Parameters

To retrieve a parameter from an initialized Request instance you have to use getParameter() method:

When instance has been produced using RequestBuilder, it will contain parameter values from $_GET, $_POST and the data from content parsers.

Important!
If your code contains two parameters in $_GET and $_POST with same name, it will trigger a warning. Same warning will also be triggered, if one of the content parsers returned parameter, which already existed in $_GET or $_POST. The library is designed with an assumption, that having such overlap is an unintentional mistake.

The getParameter() method has the following signature:

If parameter with the provided name does not exist, the method will return null.

Cookies

Retrieval of cookies is done using getCookies() method.

The getCookie() method has the following signature:

If parameter with the provided name does not exist, the method will return null.

File uploads

The method for retrieving uploaded files from Request instance is getUpload():

This method is called with the input's name as parameter. Depending on the structure of your upload form, it will return either an instance of UploadedFile, if your HTML had name="attachment", or FileBag instance, if form element had name="attachment[]".

If no file has been uploaded with the given field name, then the method will return null.

The method signature is:

Request method

To retrieve the HTTP request method, you have to use getMethod() method.

It has the following signature:

Headers

Currently the Request instance lets you access abstractions for Accept and Content-Type HTTP headers. It can be done using getAcceptHeader() and getContentTypeHeader() methods. These methods have the following signatures:

and


All versions of http with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package fracture/http contains the following files

Loading the files please wait ....