timostamm / web-resource
PHP Web Resources
v1.2.1
2023-10-08 14:09 UTC
Requires
- php: ^7.2 || ^8.0
- symfony/http-foundation: >=4.4 < 6
- symfony/mime: >=4.4 < 6
Requires (Dev)
- ext-zip: *
- mikey179/vfsstream: ^1.6.11
- phpunit/phpunit: ^8.5.23 || ^9
- symfony/process: >=4.4 < 6
README
A collection of classes that represent resources, suited for delivery to a HTTP client.
The benefit of these classes is a common interface that bundles the data stream with a bunch of metadata like mimetype, modification date, etc.
This abstraction makes caching, lazy processing, media type conversion and other pipelined operations much more convenient than handling files.
Example
// In a Symfony Controller: $res = Resource::fromFile('dir/my-file.txt'); $res->getMimetype(); // guessed mimetype return new ResourceResponse($res); // Fetch a resource from an URL: $res = Resource::fromUrl('http://foo.bar/my-file.txt'); $res->getMimetype(); // mimetype from server $res->getLastModified(); // modification date from server // Overriding a mimetype and the file name: $res = Resource::fromFile('dir/my-file.txt', [ 'mimetype' => 'applicatio/octet-stream', 'filename' => 'text.txt' ]); return new ResourceResponse($res); // will also set the appropriate content-disposition header