Git Product home page Git Product logo

psr7-asset's People

Contributors

basz avatar harikt avatar koriym avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

koriym basz

psr7-asset's Issues

Replace CallbackStream with Stream

using mezzio-swoole in front of the this package is problematic because this package uses a CallbackStream. mezzio-swoole isn't capable of using that currently (there is a PR for that mezzio/mezzio-swoole#31). However, even when that PR get's merged, the CallbackStream Psr7Assets echo's the contents which doesn't work with mezzio-swoole. The contents ends up in the log not in the browser :-).

https://github.com/harikt/psr7-asset/blob/master/src/AssetResponder.php#L110

A simple but somewhat naive fix would be change the echo into a return;

        $callable = function () use ($path) {
            $file = new SplFileObject($path);
            $content = '';
            while (! $file->eof()) {
                $content .= $file->fgets();
            }

            return $content;
        };

This would -however- defeat the purpose of being capable of streaming large files. So in my project I have overwritten the AssetResponder and am using a Diactoros Stream as a response. That works great!

<?php

namespace MyApp;

use Laminas\Diactoros\Stream;
use Psr\Http\Message\ResponseInterface;

class AssetResponder extends \Hkt\Psr7Asset\AssetResponder
{
    /**
     * Sets a 200 OK response with the asset contents.
     *
     * @return ResponseInterface
     */
    protected function ok()
    {
        $response = $this->responseFactory->createResponse(200);
        return $response
            ->withBody(new Stream($this->data->asset->path))
            ->withHeader('Content-Length', (string) filesize($this->data->asset->path))
            ->withHeader('Content-Type', $this->data->asset->type);
    }
}

Before I create PR, this would introduce a dependency on laminas-diactoros or... I could write a minimal Stream implementation s was done with the CallbackStream class...

http-factory-diactoros won't install, required?

Hi I'm trying the package... but am stuck at installing http-interop/http-factory-diactoros

bas$ composer require http-interop/http-factory-diactoros --ignore-platform-reqs
Using version ^0.3.0 for http-interop/http-factory-diactoros
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Can only install one of: http-interop/http-factory[0.3.0, 0.2.0].
    - Can only install one of: http-interop/http-factory[0.3.0, 0.2.0].
    - Can only install one of: http-interop/http-factory[0.3.0, 0.2.0].
    - http-interop/http-factory-diactoros 0.3.0 requires http-interop/http-factory ^0.3 -> satisfiable by http-interop/http-factory[0.3.0].
    - Installation request for http-interop/http-factory-diactoros ^0.3.0 -> satisfiable by http-interop/http-factory-diactoros[0.3.0].
    - Installation request for http-interop/http-factory (locked at 0.2.0) -> satisfiable by http-interop/http-factory[0.2.0].


Installation failed, reverting ./composer.json to its original content.
bas$ composer why http-interop/http-factory
hkt/psr7-asset  0.2.0  requires  http-interop/http-factory (^0.2) 

I'm am aware this is probably not related to psr7-asset (sorry) but I just don't see what conflicting? All other dependencies have been updated....

thank you

bas$ composer show
bushbaby/php-cs-fixer-config                   1.0.5              PHP CS Fixer config
composer/semver                                1.4.2              Semver library that offers utilities, version constraint parsing and validation.
container-interop/container-interop            1.2.0              Promoting the interoperability of container objects (DIC, SL, etc.)
doctrine/annotations                           v1.5.0             Docblock Annotations Parser
doctrine/instantiator                          1.1.0              A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                                 v1.0.1             Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
evenement/evenement                            v2.1.0             Événement is a very simple event dispatching library for PHP
fig/http-message-util                          1.1.2              Utility classes and constants for use with PSR-7 (psr/http-message)
friendsofphp/php-cs-fixer                      v2.7.1             A tool to automatically fix PHP code style
gecko-packages/gecko-php-unit                  v2.2               Additional PHPUnit asserts and constraints.
guzzlehttp/psr7                                1.4.2              PSR-7 message implementation that also provides common utility methods
hkt/psr7-asset                                 0.2.0              Managing assets via PSR-7
http-interop/http-factory                      0.2.0              Common interface for HTTP message factories
http-interop/http-middleware                   0.4.1              Common interface for HTTP server-side middleware
los/loslog                                     2.1.1              LosLog provides some log utility
mkraemer/react-inotify                         v1.1.0             Inotify bindings for ReactPHP
mkraemer/react-pcntl                           v3.0.0             PCNTL bindings for ReactPHP
monolog/monolog                                1.23.0             Sends your logs to files, sockets, inboxes, databases and various web services
myclabs/deep-copy                              1.7.0              Create deep copies (clones) of your objects
nikic/fast-route                               v1.2.0             Fast request router for PHP
oscarotero/psr7-middlewares                    v3.21.1            Collection of HTTP middlewares compatible with PSR-7
paragonie/random_compat                        v2.0.11            PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phar-io/manifest                               1.0.1              Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                                1.0.1              Library for handling version information and constraints
php-cs-fixer/diff                              v1.2.0             sebastian/diff v2 backport support for PHP5.6
php-ds/php-ds                                  v1.2.0            
phpdocumentor/reflection-common                1.0.1              Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock              4.1.1              With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver                    0.4.0             
phpspec/prophecy                               v1.7.2             Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage                      5.2.2              Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator                      1.4.2              FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template                      1.2.1              Simple template engine.
phpunit/php-timer                              1.0.9              Utility class for timing
phpunit/php-token-stream                       2.0.1              Wrapper around PHP's tokenizer extension.
phpunit/phpunit                                6.4.3              The PHP Unit Testing framework.
phpunit/phpunit-mock-objects                   4.0.4              Mock Object library for PHPUnit
pimple/pimple                                  v3.2.2             Pimple, a simple Dependency Injection Container
psr/container                                  1.0.0              Common Container Interface (PHP FIG PSR-11)
psr/http-message                               1.0.1              Common interface for HTTP messages
psr/log                                        1.0.2              Common interface for logging libraries
rauwebieten/psr7-partial-download              dev-master 26d1d32
react/event-loop                               v0.4.3             Event loop abstraction layer that libraries can use for evented I/O.
roave/security-advisories                      dev-master df81ca9 Prevents installation of composer packages with known security vulnerabilities: no API, simply require it
sebastian/code-unit-reverse-lookup             1.0.1              Looks up which function or method a line of code belongs to
sebastian/comparator                           2.0.2              Provides the functionality to compare PHP values for equality
sebastian/diff                                 2.0.1              Diff implementation
sebastian/environment                          3.1.0              Provides functionality to handle HHVM/PHP environments
sebastian/exporter                             3.1.0              Provides the functionality to export PHP variables for visualization
sebastian/global-state                         2.0.0              Snapshotting of global state
sebastian/object-enumerator                    3.0.3              Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector                     1.1.1              Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context                    3.0.0              Provides functionality to recursively process PHP variables
sebastian/resource-operations                  1.0.0              Provides a list of PHP built-in functions that operate on resources
sebastian/version                              2.0.1              Library that helps with managing the version number of Git-hosted PHP projects
sendgrid/php-http-client                       3.8.0              HTTP REST client, simplified for PHP
sendgrid/sendgrid                              6.0.0              This library allows you to quickly and easily send emails through SendGrid using PHP.
slim/http-cache                                0.3.0              Slim Framework HTTP cache middleware and service provider
symfony/console                                v3.3.10            Symfony Console Component
symfony/debug                                  v3.3.10            Symfony Debug Component
symfony/event-dispatcher                       v3.3.10            Symfony EventDispatcher Component
symfony/filesystem                             v3.3.10            Symfony Filesystem Component
symfony/finder                                 v3.3.10            Symfony Finder Component
symfony/options-resolver                       v3.3.10            Symfony OptionsResolver Component
symfony/polyfill-mbstring                      v1.6.0             Symfony polyfill for the Mbstring extension
symfony/polyfill-php70                         v1.6.0             Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-php72                         v1.6.0             Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/process                                v3.3.10            Symfony Process Component
symfony/stopwatch                              v3.3.10            Symfony Stopwatch Component
theseer/tokenizer                              1.1.0              A small library for converting tokenized PHP source code into XML and potentially other formats
tuupola/slim-basic-auth                        2.3.0              PSR-7 HTTP Basic Authentication Middleware
webimpress/composer-extra-dependency           0.2.2              Composer plugin to require extra dependencies
webimpress/http-middleware-compatibility       0.1.4              Compatibility library for Draft PSR-15 HTTP Middleware
webmozart/assert                               1.2.0              Assertions to validate method input/output with nice error messages.
zendframework/zend-cache                       2.7.2              provides a generic way to cache any data
zendframework/zend-code                        3.3.0              provides facilities to generate arbitrary code using an object oriented interface
zendframework/zend-component-installer         1.0.0              Composer plugin for automating component registration in zend-mvc and Expressive applications
zendframework/zend-config-aggregator           1.0.0              Lightweight library for merging and caching application config
zendframework/zend-diactoros                   1.6.1              PSR HTTP Message implementations
zendframework/zend-escaper                     2.5.2             
zendframework/zend-eventmanager                3.2.0              Trigger and listen to events within a PHP application
zendframework/zend-expressive                  2.0.5              PSR-7 Middleware Microframework based on Stratigility
zendframework/zend-expressive-fastroute        2.1.0              FastRoute integration for Expressive
zendframework/zend-expressive-helpers          4.2.0              Helper/Utility classes for Expressive
zendframework/zend-expressive-router           2.2.0              Router subcomponent for Expressive
zendframework/zend-expressive-template         1.0.4              Template subcomponent for Expressive
zendframework/zend-expressive-tooling          0.4.4              Migration and development tooling for Expressive
zendframework/zend-expressive-zendviewrenderer 1.4.0              zend-view PhpRenderer integration for Expressive
zendframework/zend-json                        3.0.0              provides convenience methods for serializing native PHP to JSON and decoding JSON to native PHP
zendframework/zend-loader                      2.5.1             
zendframework/zend-log                         2.9.2              component for general purpose logging
zendframework/zend-mail                        2.8.0              provides generalized functionality to compose and send both text and MIME-compliant multipart e-mail messages
zendframework/zend-mime                        2.6.1             
zendframework/zend-serializer                  2.8.0              provides an adapter based interface to simply generate storable representation of PHP types by different facilities, and recover
zendframework/zend-servicemanager              3.3.0             
zendframework/zend-stdlib                      3.1.0             
zendframework/zend-stratigility                2.1.2              Middleware for PHP
zendframework/zend-validator                   2.10.1             provides a set of commonly needed validators
zendframework/zend-view                        2.9.0              provides a system of helpers, output filters, and variable escaping
zfcampus/zf-composer-autoloading               2.0.0              Sets up Composer-based autoloading for your Zend Framework modules
zfcampus/zf-development-mode                   3.1.0              Zend Framework development mode script

HeaderSecurity Exception when mime type isn't registered

When a file is requested that is available in an assets directory but there is no mime type registered for the extension in the AssetService an HeaderSecurity Exception is thrown. Shouldn't a 404 be more appropriate/save?

Invalid header value type; must be a string or numeric; received NULL
.../vendor/zendframework/zend-diactoros/src/HeaderSecurity.php:131

Great package by the way!

Cache assets

  1. use symbolic links
  2. or copy files to public folder

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.