Comments (7)
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.
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.
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.
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.
@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.
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.
Please review my latest pull request. I believe it's handled all the comment of this bug.
from twig-view.
Related Issues (20)
- Question - Twig 3 Support HOT 10
- Slim\Views\Twig::create does not exist HOT 3
- Add support for Twig 3 in 3.x branch
- Slim 4 Compatibility In The Pipeline? HOT 1
- Rendering no space HOT 1
- Fix incorrect declaration HOT 3
- Version on Readme HOT 1
- Twig could not be found in the server request attributes using the key "view" HOT 5
- ,
- How to get args for is_current_url()? HOT 2
- Using view outside a request/response cycle does not load the Slim/Views/TwigExtension HOT 2
- Trying to use TwigExtension template functions returns an error HOT 1
- Uncaught Twig\Error\SyntaxError: Unknown "defined" test. HOT 3
- is_current_url() doesn't take basepath into consideration HOT 21
- Support PHP 8.0
- twig->fetch() outputs to browser rather than return string HOT 8
- 3.3.0 Release date HOT 3
- `composer require slim/twig-view:^3.0` handle PHP Version Problem HOT 1
- Rendering a template from a middleware HOT 4
- Error using Twig with Slim 4 & Container HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twig-view.