slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.98k stars 1.95k forks source link

Implement `$_FILES` support into Http\Request class. #1099

Closed codeguy closed 9 years ago

codeguy commented 9 years ago

The Http\Request class needs to support the PSR-7 interface methods for dealing with the $_FILES request data. The \Slim\Http\Request::getFileParams() method should return the current $_FILES data. This data should be injected into the Request object at instantiation.

r3wt commented 9 years ago

I'm down

codeguy commented 9 years ago

Awesome! Go for it. Feel free to ask any questions here as you're working on it.

r3wt commented 9 years ago

Well, looks like i will have to back out of this after all. I checked out the develop branch and i'm not happy with the direction the project is going. I love the current version of Slim php so i'll just stick with that. if you stop supporting it ( The 2.x branch ), i will gladly fork and continue it.

r3wt commented 9 years ago

I went ahead and pulled my changes.

r3wt commented 9 years ago

@codeguy It's not immediately clear in the PSR if getFileParams() is expected to take an optional key as argument. thoughts?

codeguy commented 9 years ago

It does not. It should return a data structure that mimics $_FILES. Re: your current PR, we cannot rely on direct access to the $_FILES superglobal. Instead, we should inject an array that mimics this structure via the constructor. We can also leverage the Environment object to contain a key (e.g., slim.files) that contains this data. This makes it much easier to test and craft sub-requests.

geggleto commented 9 years ago

A little updating is in order with the adoption of PSR-7. PSR-7 defines an UploadedFileInterface, which for the most part is pretty straight forward. However it does also support returning the File as a stream. As such we need a more encapsulated Object that implements the StreamInterface (current supported in \Slim\Http\Body).

I would think that the implementation of the StreamInterface should be extracted from Body into a new class that both the "UploadedFile" Object and the Body Object can Utilize.

The Linkage is in the ServerRequestInterface where getUploadedFiles() is defined.

opengeek commented 9 years ago

I'll take a stab at this shortly.

akrabat commented 9 years ago

Fixed by https://github.com/slimphp/Slim/pull/1263

geggleto commented 9 years ago

Hurray! :+1: