Strict PSR-7 implementation used by the Slim Framework

Related tags

Frameworks Slim-Psr7
Overview

Slim PSR-7

Strict PSR-7 implementation used by the Slim Framework, but you may use it separately with any framework compatible with the PSR-7 standard.

Build Status Coverage Status Total Downloads License

Installation

It's recommended that you use Composer to install this library.

$ composer require slim/psr7

This will install the slim/psr7 component and all required dependencies.

PHP 7.4 or newer is required.

Tests

To execute the test suite, you'll need to clone the repository and install the dependencies.

$ git clone https://github.com/slimphp/Slim-Psr7
$ composer install
$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

This component is licensed under the MIT license. See License File for more information.

Comments
  • Some minor improvements

    Some minor improvements

    About 966d0fffd845a4e63a69fb157ed4e77b0ab1041b it is similar to https://github.com/phpmyadmin/sql-parser/commit/a20131487496892d4111c1cbe0025fee35180cce In Debian we need the tests folder to run auto-package tests on packages. Example: https://salsa.debian.org/php-team/pear/php-zumba-json-serializer/-/jobs/3521669#L312 or https://ci.debian.net/data/autopkgtest/unstable/amd64/p/phpmyadmin-sql-parser/27794800/log.gz

    opened by williamdes 1
  • Remove dependency on ralouphie/getallheaders

    Remove dependency on ralouphie/getallheaders

    This was added in https://github.com/slimphp/Slim-Psr7/pull/76 Then moved as a normal dependency in https://github.com/slimphp/Slim-Psr7/pull/111 for https://github.com/slimphp/Slim-Psr7/issues/101

    And got upgraded in https://github.com/slimphp/Slim-Psr7/pull/112

    I see no reason this function would be now missing in PHP 7.4+

    opened by williamdes 1
  • Fix moving uploaded file crashed when source was stream

    Fix moving uploaded file crashed when source was stream

    Description

    When UploadedFile is created from stream then calling movingTo will throw an exception.

    Script to reproduce the bug

    require_once __DIR__ . '/vendor/autoload.php';
    
    $file = new \Slim\Psr7\UploadedFile(
        (new \Slim\Psr7\Factory\StreamFactory())->createStream('Hello, World!')
    );
    
    $targetPath = tempnam(sys_get_temp_dir(), 'sample');
    $file->moveTo($targetPath);
    
    echo file_get_contents($targetPath);
    
    

    Expected output:

    Hello, World!

    Actual output:

    PHP Warning:  rename(): PHP wrapper does not support renaming in /home/rait/dev/github/Slim-Psr7/src/UploadedFile.php on line 172
    PHP Stack trace:
    PHP   1. {main}() /home/rait/dev/github/Slim-Psr7/demo.php:0
    PHP   2. Slim\Psr7\UploadedFile->moveTo() /home/rait/dev/github/Slim-Psr7/demo.php:10
    PHP   3. rename() /home/rait/dev/github/Slim-Psr7/src/UploadedFile.php:172
    PHP Fatal error:  Uncaught RuntimeException: Error moving uploaded file  to /tmp/samplezHN38z in /home/rait/dev/github/Slim-Psr7/src/UploadedFile.php:173
    Stack trace:
    #0 /home/rait/dev/github/Slim-Psr7/demo.php(10): Slim\Psr7\UploadedFile->moveTo('/tmp/samplezHN3...')
    #1 {main}
      thrown in /home/rait/dev/github/Slim-Psr7/src/UploadedFile.php on line 173
    

    Motivation

    I discovered this bug when I was creating a stub for a test.

    Notes on implementation

    I used stream_copy_to_stream for copying. I speculate that built-in stream function should be more efficient because it is implemented in C.

    My fix also handles php://temp case where huge files might be the case.

    opened by raigu 5
  • Request body is seekable but size is null when a file is sent

    Request body is seekable but size is null when a file is sent

    Hello there, I'm using Slim 4.5.0. I'm PUTting a binary file to one of my routes but the Slim\Psr7\Stream instance I get from the Slim\Http\ServerRequest object won't tell me the content size. I'm NOT sending a multipart/form-data request. I'm just PUTting a file with curl -T "filename" "http://my-host/my-route"

    Here's my PHP code. $request->getBody()->getSize() is null even though the stream is reported seekable and the Content-Length header was provided.

    public function putMediaContent(ServerRequestInterface $request, ResponseInterface $response, array $args) : ResponseInterface {
        //body is a Slim\Psr7\Stream instance
        $body = $request->getBody();
        //size is null
        $size = $body->getSize();
        //isSeekable is true
        $isSeekable = $body->isSeekable();
        //contentLength has the correct uploaded file size
        $contentLength = $request->getHeaders()['Content-Length'][0];
    
        //...
    }
    

    This is a problem since I then have to pass this stream to an S3Client for cloud upload and it complains about the fact the size is unknown. Is this intended?

    Thanks.

    opened by BrightSoul 4
  • BasePath processing is missing

    BasePath processing is missing

    According to the documentation

    The PSR-7 Request object’s URI is itself an object that provides the following methods to inspect the HTTP request’s URL parts:
    
    getScheme()
    getAuthority()
    getUserInfo()
    getHost()
    getPort()
    getPath()
    getBasePath()
    getQuery() (returns the full query string, e.g. a=1&b=2)
    getFragment()
    getBaseUrl()
    You can get the query parameters as an associative array on the Request object using getQueryParams().
    
    Base Path
    If your Slim application's front-controller lives in a physical subdirectory beneath your document root directory, you can fetch the HTTP request's physical base path (relative to the document root) with the Uri object's getBasePath() method. This will be an empty string if the Slim application is installed in the document root's top-most directory.
    

    Slim v3 implemented the basePath processing as per https://github.com/slimphp/Slim/blob/3.x/Slim/Http/Uri.php#L204

    enhancement 
    opened by esetnik 1
  • Add body parsing functionality in Request object

    Add body parsing functionality in Request object

    Currently we do not parse any incoming data in the Request object. All that functionality has been moved to the Slim-Http decorators repository.

    We should by default at least support the incoming form data in the $_POST object and JSON.

    enhancement 
    opened by l0gicgate 8
Releases(1.6.0)
Owner
Slim Framework
Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
Slim Framework
Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components

Spiral HTTP Application Skeleton Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components.

Spiral Scout 152 Dec 18, 2022
Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.

Slim Framework Slim is a PHP micro-framework that helps you quickly write simple yet powerful web applications and APIs. Installation It's recommended

Slim Framework 11.5k Jan 4, 2023
Slim Framework - Prerequisite Checker

Slim Framework - Server Configuration Checker Upload the file check.php to your webserver Browse to the file: https://example.com/check.php Check the

Daniel Opitz 6 Aug 30, 2022
REST APIs using Slim framework. Implemented all CRUD operations on the MySql database

PHP REST API using slim framework and CRUD operations ?? Hi there, this is a simple REST API built using the Slim framework. And this is for the folks

Hanoak 2 Jun 1, 2022
A Slim PHP MVC framework built just for fun!

Aura Framework A Slim PHP MVC framework built just for fun! en: Note: This repository only contains the core code of the Aura framework. If you want t

Murilo Magalhães Barreto 2 Dec 16, 2021
Slim Framework skeleton application with MVC Schema

Slim Framework skeleton application with MVC Schema

JingwenTian 9 Apr 29, 2021
This repository contains a library of optional middleware for your Slim Framework application

Slim Framework Middleware This repository contains a library of optional middleware for your Slim Framework application. How to Install Update your co

Slim Framework 47 Nov 7, 2022
A curated list of awesome tutorials and other resources for the Slim micro framework

Awesome Slim A curated list of awesome tutorials and other resources for the Slim micro framework Table of Contents Essentials Tutorials Packages and

Sawyer Charles 466 Dec 8, 2022
Slim Framework 3 Skeleton Application + PagSeguro Lib

Slim Framework 3 Skeleton Application + PagSeguro Lib Aplicação simples para geração do Token para pagamentos no PagSeguro (método transparente) e env

Raí Siqueira 1 Feb 26, 2018
My personal blog developed on the Slim Framework

nesbot.com I am making the source code of my personal site available publicly in case it helps anybody. It's developed using the Slim Framework. I am

Brian Nesbitt 56 Sep 14, 2022
Plates Template Integration for Slim micro framework 3

Plates Template Integration for Slim micro framework 3 Render your Slim 3 application views using Plates template engine. Install Via Composer $ compo

Projek XYZ 26 Feb 5, 2022
Juliangut Slim Framework Doctrine handler middleware

Juliangut Slim Framework Doctrine handler middleware Doctrine handler middleware for Slim Framework. Slim3 version Doctrine integration service for Sl

Julián Gutiérrez 6 Mar 23, 2021
This Slim Framework middleware will compile LESS CSS files on-the-fly using the Assetic library

This Slim Framework middleware will compile LESS CSS files on-the-fly using the Assetic library. It supports minification and caching, also via Asseti

Gerard Sychay 22 Mar 31, 2020
Slim Framework custom views

Slim Views This repository contains custom View classes for the template frameworks listed below. You can use any of these custom View classes by eith

Slim Framework 302 Feb 21, 2022
Access control middleware for Slim framework

Slim Access Access control middleware for Slim framework. Supported formats IPv4 and IPv6 addresses CIDR notation all keyword Installation composer re

Alexandre Bouvier 7 Oct 22, 2019
Redis cache middleware for Slim framework

RedisCache Redis cache middleware for Slim framework. Installation composer require abouvier/slim-redis-cache Usage Cache every successful HTTP respo

Alexandre Bouvier 16 Sep 20, 2021
Slim Framework using Jade for templates

Welcome to Slim-Jade What? This is a boilerplate. It's the Slim Framework with jade.php to render views Why? I like the Sinatra style MVC and love Jad

Joe Fleming 23 Oct 16, 2019
The Slim PHP micro framework paired with Laravel's Illuminate Database toolkit.

Slim & Eloquent The Slim PHP micro framework paired with Laravel's Illuminate Database toolkit. Getting started # Download composer curl -s https://ge

Kyle Ladd 111 Jul 23, 2022
A set of shady Slim Framework middlewares that can solve some annoyances...

Shady A set of shady Slim Framework middlewares that can solve some annoyances... What does it contain? Available middlewares: ApacheVirtualHostFix Ur

Jan-Age Laroo 7 Jun 22, 2021