Giter VIP home page Giter VIP logo

psr17's Introduction

Latest Stable Version GitHub stars Total Downloads GitHub Workflow Status Type Coverage License Donate!

PSR-17 http-factories implementation

The PSR-17 specification is about HTTP factories.

There are many PSR-17 interfaces and the purpose of this package is to regroup them all in one single interface: PSR17Interface.

This package also implements a PSR17 class which implements this interface and provide a basic implementation.

Requirements

  • PHP >= 7.4

Installation

composer require loophp/psr17

This package requires also a psr/http-factory-implementation. I advise to use nyholm/psr7 from Tobias Nyholm.

Usage

<?php

declare(strict_types=1);

namespace App;

use loophp\psr17\Psr17;
use Nyholm\Psr7\Factory\Psr17Factory;

include __DIR__ . '/vendor/autoload.php';

// In this example, I used nyholm/psr7
// But you could any another library of your choice.
$requestFactory = $responseFactory = $streamFactory = $uploadedFileFactory = $uriFactory = $serverRequestFactory = new Psr17Factory();

$psr17 = new Psr17($requestFactory, $responseFactory, $streamFactory, $uploadedFileFactory, $uriFactory, $serverRequestFactory);

$request = $psr17->createRequest('GET', 'https://github.com');
$response = $psr17->createResponse(200, 'hello');
$stream = $psr17->createStream('foobar');
$uploadedFile = $psr17->createUploadedFile($stream);
$uri = $psr17->createUri('https://github.com/loophp/psr17');
$serverRequest = $psr17->createServerRequest('GET', 'https://github.com/');

Integration with Symfony

Since the 29 of July, a Symfony recipe has been published for this package.

Therefore, if you're using Symfony Flex, then you don't have anything to do. When the package will be installed by Composer, Symfony Flex will install the configuration file in your application and automatically do the necessary services and interfaces wiring.

If you're not using Flex, add in services.yaml:

services:
  # Register loophp/psr17/Psr17 class and autowire/autoconfigure it.
  loophp\psr17\Psr17:
    autowire: true
    autoconfigure: true

  # Alias the service to the Psr17 interface.
  loophp\psr17\Psr17Interface: '@loophp\psr17\Psr17'

Once again, you will need to have proper wiring for the dependencies of the Psr17 class.

This is left up to the user but if you want a default implementation, you can use nyholm/psr7 which provides also a Symfony recipe with the required dependencies so the container will be able to autowire the Psr17 service.

Code quality, tests and benchmarks

Every time changes are introduced into the library, Github run the tests and the benchmarks.

The library has tests written with PHPSpec. Feel free to check them out in the spec directory. Run composer phpspec to trigger the tests.

Before each commit some inspections are executed with GrumPHP, run ./vendor/bin/grumphp run to check manually.

PHPInfection is used to ensure that your code is properly tested, run composer infection to test your code.

Contributing

Feel free to contribute by sending Github pull requests. I'm quite responsive :-)

Changelog

See CHANGELOG.md for a changelog based on git commits.

For more detailed changelogs, please check the release changelogs.

psr17's People

Contributors

dependabot[bot] avatar drupol avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

psr17's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.


Warning

Renovate failed to look up the following dependencies: Failed to look up packagist package psr/http-factory-implementation, Failed to look up packagist package psr/http-message-implementation.

Files affected: composer.json


Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

composer
composer.json
  • php >= 8.1
  • psr/http-factory ^1.0
  • psr/http-factory-implementation ^1.0
  • psr/http-message ^2.0
  • psr/http-message-implementation ^1.0
  • drupol/php-conventions ^5
  • friends-of-phpspec/phpspec-code-coverage ^6
  • infection/infection ^0.29
  • infection/phpspec-adapter ^0.2.0
  • nyholm/psr7 ^1.8
  • phpspec/phpspec ^7.4
github-actions
.github/workflows/benchmarks.yml
  • shivammathur/setup-php 2.30.0
  • actions/cache v3
  • actions/checkout v4
  • actions/checkout v4
.github/workflows/code-style.yml
  • actions/checkout v4
  • shivammathur/setup-php 2.30.0
  • ramsey/composer-install v3
.github/workflows/mutation-tests.yml
  • actions/checkout v4
  • shivammathur/setup-php 2.30.0
  • ramsey/composer-install v3
.github/workflows/prettier.yml
  • actions/checkout v4
  • cachix/install-nix-action v27
.github/workflows/prune.yaml
  • actions/stale v7
.github/workflows/release.yaml
  • actions/checkout v4
  • mindsers/changelog-reader-action v2
  • actions/create-release v1.1.4
.github/workflows/static-analysis.yml
  • actions/checkout v4
  • shivammathur/setup-php v2
  • ramsey/composer-install v3
.github/workflows/tests.yml
  • actions/checkout v4
  • WyriHaximus/github-action-composer-php-versions-in-range v1
  • actions/checkout v4
  • shivammathur/setup-php 2.30.0
  • ramsey/composer-install v3

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.