Giter Club home page Giter Club logo

Comments (7)

adriansuter avatar adriansuter commented on May 26, 2024

To me, the view (template engine) is a component that belongs into the container. After all, the container is exactly for this kind of scenario and should serve as dependency injection.

from twig-view.

bangzek avatar bangzek commented on May 26, 2024

Well normally the template engine doesn't have business messing around with container.

If there's a good excuse they can use the container engine as service locator anti pattern, but that just using the ->get() method. See my LazyTwigMiddleware for a good excuse to use container.

One good reason for a library not setting the Container cause the user knows more about their current setup than library author. For example PHP-DI has special compiled mode that must be run before any library code. If the view setting the container after it, it just make the compiled code useless.

from twig-view.

l0gicgate avatar l0gicgate commented on May 26, 2024

We could do something similar to RouteContext @adriansuter.

The one thing that worries me is that we're going to break the synthax that users were used to before. We could leave both in place perhaps?

TwigContext::fromRequest($request) and pass in view as well within the $request object.

from twig-view.

adriansuter avatar adriansuter commented on May 26, 2024

But I still don't understand, why the template engine should be added to the request object. To me, that belongs to the container (dependency injection - it is a service after all).

The only reason I can see is, if someone wants to use Slim and Twig without DI container.

I agree, that actually we should not set the instance to the container in the middleware, but rather we should let the user set it beforehand (because of php-di container compilation). The middleware should get twig from the container.

from twig-view.

l0gicgate avatar l0gicgate commented on May 26, 2024

@adriansuter itโ€™s really just a hackish way to transport data honestly. It pains me that we have to do it in Slim as well.

And yes, that is the only reason why someone would want to transport it in another way. Not use a container or having container constraints due to pre-compilation or other.

Ultimately we canโ€™t please everyone though.

from twig-view.

bangzek avatar bangzek commented on May 26, 2024

There's probably a misunderstanding here. Let me clarify:

First are we in agreement that the current way of TwigMiddleware set container in ->process() is wrong?

My suggestion that we set it in Request attribute probably not good either, that's why I made it optional.

Let's get back to the v2 way, let user handle the responsibility to set container's view service with the Twig object. The middleware just add runtime loader and extension to the passed Twig object. So the user must get the Twig object from container and pass it to TwigMiddleware::create() or the constructor if he want to build it from scratch. Most DI container will get the same object so it's not a problem.

from twig-view.

bangzek avatar bangzek commented on May 26, 2024

Please review my latest pull request. I believe it's handled all the comment of this bug.

from twig-view.

Related Issues (20)

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.