Giter Site home page Giter Site logo

Comments (10)

sasezaki avatar sasezaki commented on June 19, 2024

But sorry, at first, I don't prefer __toString for Render for PSR-7. 😠
(reason is wrote at http://sasezaki.hatenablog.com/entry/2015/03/07/195908 )

from bear.middleware.

koriym avatar koriym commented on June 19, 2024

Agreed. Handler should be handle stream not body string.

Your code seems works fine. Would you send PR ?
https://gist.github.com/sasezaki/68670975fbb5ca5114ed
Then we can leave your contribution on repository.

Or I can fixed it later. Thank you for making the issue.

from bear.middleware.

sasezaki avatar sasezaki commented on June 19, 2024

ok. I would try at this weekend.

from bear.middleware.

koriym avatar koriym commented on June 19, 2024

Awesome !

from bear.middleware.

sasezaki avatar sasezaki commented on June 19, 2024

sorry for late. I couldn't take a time to catch up lack of BEAR.Sunday knowledge.
so I want someone working on this.

from bear.middleware.

koriym avatar koriym commented on June 19, 2024

no problem, I will do it later with your code.

from bear.middleware.

koriym avatar koriym commented on June 19, 2024

quick fix for header now.

from bear.middleware.

koriym avatar koriym commented on June 19, 2024

@sasezaki

ResourceObject should be render (__toString) before looking up headers

Fixed !

But sorry, at first, I don't prefer __toString for Render for PSR-7. 😠

Now RequestHandler returns 100% genuine stream response.

$response = $response->withBody(new Stream($stream));

But things are not easy as first glance. The current implementation has limitation. This version can't handle with your blog post example. (view template produce huge text).

Instead, we can assign stream resource at ResourceObject

    public function onGet()
    {
        $this['msg'] = 'hello world';
        $this['stream'] = fopen(__DIR__ . '/message.txt', 'r');
        return $this;
    }

hello world text and /message.txt stream are placed at their place folder in layout file, then text parts(hello world and layout template) is converted to stream to merge native stream (message.txt). You can assign multiple stream in any place. All stream will be merged and streamed.

https://github.com/bearsunday/BEAR.Middleware/blob/1.x/src/Module/StreamRenderer.php#L117

If you want single stream without any fixed text, you simple assign stream to entire resource body.

    public function onGet()
    {
        $this->body = fopen(__DIR__ . '/message.txt', 'r');
        return $this;
    }

from bear.middleware.

koriym avatar koriym commented on June 19, 2024

@sasezaki I tested with huge text stream, It succeeded but need to change output procedure as you mentioned.

mwop-q

from bear.middleware.

koriym avatar koriym commented on June 19, 2024

@sasezaki your blog post are SUPER helpful. (I knew very little about it)
Huge thanks !!

from bear.middleware.

Related Issues (2)

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.