Download the PHP package webiny/http without Composer

On this page you can find all versions of the php package webiny/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

Http Component

The Http component consists of a Request, Response, Cookie and Session class.

Install the component

The best way to install the component is using Composer.

For additional versions of the package, visit the Packagist page.

Usage

The preferred way of accessing those classes is by using the HttpTrait.

To register the config with the component, just call Http::setConfig($pathToYamlConfig).

Request class

The Request class provides different helper methods like:

And a lot of other methods. NOTE: All of the functions check for forwarded response headers and validate them against the defined list of trusted proxies.

Other than just providing helper functions, the Request class gives you also objective wrappers for working with global variables like $_SERVER, $_GET, $_POST and $_FILES.

Server

The Server class is a wrapper for all of (documented) $_SERVER properties, based on the list on official php.net documentation. http://php.net/manual/en/reserved.variables.server.php

Here is an example usage:

NOTE: Server methods do not check forwarded response headers from reverse proxies. They are just an objective wrapper for $_SERVER properties. Use the methods from the Request class to get client ip, host name, and similar properties that validate against trusted proxies.

$_GET and $_POST

To access the $_GET properties use the query method, and to access the $_POST use the post method. Both methods take two params. First param is the key of the property, and the second is the default value that will be returned in case if the key does not exist.

Here is an example usage:

Payload

To access the Payload property, use the payload method. Payload automatically reads php://input and json_decodes the output.

To access payload values:

$_FILES

The $_FILES wrapper provides a much better way of handling uploaded files. The process consists of two steps. In the first step, you get the file using the files method on the Request class. After that you can move the file to desired destination.

Session class

Webiny framework provides you with two built-in session storage handlers, the native handler and the cache handler. Native handler uses the built-in PHP session handler, while cache handler uses the provided cache driver. Using the cache handler you can easily share your sessions across multiple servers and boost performance. Current supported cache drivers are all supported drivers by the Cache component.

Session cache handler configuration

The default defined storage handler is the native handler. If you want to use the cache handler you must first setup a cache driver (read the Cache component readme file) and then just link the cache driver to the session handler like this:

There are two most important properties you have to change, the Driver and Params.Cache. The Driver property must point to \Webiny\Component\Http\Session\Storage\CacheStorage and Params.Cache must have the name of a registered Cache service. No other changes are required in your code, you can work with sessions using the Session class.

Custom session storage handler

You can implement your own session storage handler by creating a class that implements \Webiny\Component\Http\Session\SessionStorageInterface. After you have created such a class, just point the Driver param to your class and, optionally, pass the requested constructor params using the Params config attribute.

Working with sessions

To work with sessions is rather easy, just access the current session handler which then provides you with the necessary session methods like get, save and getSessionId.

Here is an example:

Cookie class

Working with cookies is similar to working with sessions, you have a cookie storage handler that gives you the necessary methods for storing and accessing cookie values. By default there is only a native built-in storage handler.

Cookie configuration

The cookie configuration consists of defining the default storage driver and some optional parameters like Prefix, HttpOnly and ExpireTime.

Custom cookie storage handler

To implement a custom cookie storage handler, you first need to create a storage handler class which implements the \Webiny\Component\Http\Cookie\CookieStorageHandler interface. After you have successfully created your class, you now have to change the Storage.Driver parameter in your cookie configuration to point to your class.

Working with cookies

In order to read and store cookies you have to get the instance of current cookie storage driver which provides you with the necessary methods. The Cookie class provides you with that access:

Response class

The Response class provides methods for building an sending an output back to the browser. The class itself doesn't require any configuration.

To create a Response instance, you can use the HttpTrait, the class constructor or Response::create static method.

Methods

The Response class provides you with several helpful methods:

Cache control

A cache control class is provided to control the cache control headers on the response object. To access the cache control options, use the cacheControl method on the Response object.

CacheControl by default calls the setAsDontCache method which sets the cache control headers so that the response is not cached by the browser. To overwrite that, you can either provide an array with your own cache control header information or you can just call the setAsCache method which sets the response cache headers so the output can be cached by the browser.

JsonResponse

This class extends the Response class by setting the default content type to "application/json". The class can be accessed by a constructor or by a static short-hand method:

Resources

To run unit tests, you need to use the following command:

$ cd path/to/Webiny/Component/Http/
$ composer.phar install
$ phpunit

All versions of http with dependencies

PHP Build Version
Package Version
Requires php Version ^7
webiny/config Version ~1.6
webiny/std-lib Version ~1.6
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 webiny/http contains the following files

Loading the files please wait ....