Download the PHP package tebe/http-factory without Composer

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

:factory: HTTP-Factory

Travis Scrutinizer Packagist GitHub (pre-)release License PHP from Packagist

HTTP-Factory is a PHP package that implements PSR-17 HTTP factories interface. It acts as a simple facade to provide easy access to concrete HTTP factory packets. As its main feature it offers support for auto-discovery of the supported factories.

All PSR-17 interfaces are implemented:

Additionally, it implements a createServerRequestFromGlobals method, which is not part of PSR-17.

Auto-discovering PSR-7 packages

The package features auto-discovery support for the following PSR-7 packages:

  1. laminas/laminas-diactoros
  2. guzzlehttp/psr7
  3. slim/slim
  4. nyholm/psr7

The auto-discovery mechanism assumes that you are using one (and only one) of the above PSR-7 packages in your project. The first detected PSR-17 package will then be used for all interface factory methods.

Installation

When starting a new project one of the following PSR-7 packages must be installed.

$ composer require laminas/laminas-diactoros
$ composer require guzzlehttp/psr7
$ composer require slim/slim
$ composer require nyholm/psr7

When using the "nyholm/psr7" package you have to require the "nyholm/psr7-server" package, too.

$ composer require nyholm/psr7-server

Then install the HTTP-Factory package.

$ composer require tebe/http-factory

You can now use HTTP-Factory in the codebase of your project like so:

use Tebe\HttpFactory\HttpFactory;

$factory = new HttpFactory();

# creates a ResponseInterface
$factory->createResponse(int $code = 200, string $reasonPhrase = '');

# creates a ServerRequestInterface
$factory->createServerRequest(string $method, $uri, array $serverParams = []);

# creates a ServerRequestInterface
$factory->createServerRequestFromGlobals();

# creates a StreamInterface
$factory->createStream(string $content = '');

# creates a StreamInterface
$factory->createStreamFromFile(string $filename, string $mode = 'r');

# creates a StreamInterface
$factory->createStreamFromResource($resource);

# creates an UriInterface
$factory->createUri(string $uri = '');

# creates an UploadedFileInterface
$factory->createUploadedFile(
    StreamInterface $stream, 
    int $size = null, 
    int $error = \UPLOAD_ERR_OK, 
    string $clientFilename = null, 
    string $clientMediaType = null
); 

Usage

Using constructor

use Tebe\HttpFactory\HttpFactory;

$factory = new HttpFactory();
$response = $factory->createResponse(200);
echo $response->getStatusCode();

Using static instance method

use Tebe\HttpFactory\HttpFactory;

$response = HttpFactory::instance()->createResponse(200);
echo $response->getStatusCode();

Using own strategies

use Tebe\HttpFactory\HttpFactory;

HttpFactory::setStrategies([
    DiactorosFactory::class,
    GuzzleFactory::class,
    SlimFactory::class
]);

$response = HttpFactory::instance()->createResponse(200);
echo $response->getStatusCode();

Using own factory

use Tebe\HttpFactory\HttpFactory;
use Tebe\HttpFactory\FactoryInterface;

class MyFactory implements FactoryInterface
{
    // implement interface methods
}

$factory = new HttpFactory();
$factory->setFactory(new MyFactory());
$response = $factory->createResponse(200);
echo $response->getStatusCode();

Tests

Run PHPUnit:

$ composer phpunit

Run PHP_CodeSniffer:

$ composer phpcs

Run PHP Code Beautifier and Fixer:

$ composer phpcbf

Run PHPUnit and PHP_CodeSniffer together:

$ composer test

Suggestions

Any suggestions? Open an issue.


All versions of http-factory with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
psr/http-message Version ^1.0
psr/http-factory Version ^1.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 tebe/http-factory contains the following files

Loading the files please wait ...