-
Notifications
You must be signed in to change notification settings - Fork 12
Provide a URL/ServerUrl extension, and extension loading #7
Provide a URL/ServerUrl extension, and extension loading #7
Conversation
This patch was prompted by a desire to have `url` and `serverurl` functions that proxy to the zend-expressive-helpers classes. In order to do that, however, I ended up needing the following as well: - The ability to register the `League\Plates\Engine` as a service, and consume it when present. - A factory for `League\Plates\Engine` that can load extensions into the engine (via instance, service name, or class name), as well as load the custom URL extension by default. - The UrlExtension itself, which composes UrlHelper and ServerUrlHelper instances. - A factory for the UrlExtension that raises exceptions if either helper is missing. I updated the PlatesRendererFactory to delegate to the new PlatesEngineFactory if no `League\Plates\Engine` service is present in order to create the Plates engine instance. This also then ensures that by default, we have the `UrlExtension` loaded.
I have no idea why this isn't triggering a build. 😬 |
I've tested this in a skeleton application, updating hard-coded URIs to use the |
Why is this not merged yet ? |
@ricardofiorani Was hoping for folks to test it and provide feedback. |
// Create the engine instance: | ||
$engine = new PlatesEngine(); | ||
|
||
$this->injectUrlExtension($container, $engine); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In here, instead of hardcoded inject the UrlExtesion, we could allow more extensions to be provided via config, like:
'templates' => [
'extension' => 'phtml',
'paths' => [
'app' => ['templates/app'],
'layout' => ['templates/layout'],
'error' => ['templates/error'],
],
'extensions' => [
Extension\UrlExtension::class => Zend\Expressive\Plates\Extension\UrlExtensionFactory::class
],
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ricardofiorani That can be done with delegator factories, or by providing your own factory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ricardofiorani Actually, I was wrong: functionality is already present in the PlatesEngineFactory
. 😄
Provide a URL/ServerUrl extension, and extension loading
This patch was prompted by a desire to have
url
andserverurl
functions that proxy to the zend-expressive-helpers classes. In order to do that, however, I ended up needing the following as well:League\Plates\Engine
as a service, and consume it when present.League\Plates\Engine
that can load extensions into the engine (via instance, service name, or class name), as well as load the custom URL extension by default.I updated the PlatesRendererFactory to delegate to the new PlatesEngineFactory if no
League\Plates\Engine
service is present in order to create the Plates engine instance. This also then ensures that by default, we have theUrlExtension
loaded.Because this patch provides extension loading, it supercedes the one in #6, and fixes #3.