Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Provide a URL/ServerUrl extension, and extension loading #7

Merged

Conversation

weierophinney
Copy link
Member

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.

Because this patch provides extension loading, it supercedes the one in #6, and fixes #3.

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.
@weierophinney weierophinney added this to the 1.1.0 milestone Feb 2, 2016
@weierophinney
Copy link
Member Author

I have no idea why this isn't triggering a build. 😬

@weierophinney
Copy link
Member Author

I've tested this in a skeleton application, updating hard-coded URIs to use the url() function where possible, and it works like a charm!

@ricardofiorani
Copy link

Why is this not merged yet ?

@weierophinney
Copy link
Member Author

@ricardofiorani Was hoping for folks to test it and provide feedback.

// Create the engine instance:
$engine = new PlatesEngine();

$this->injectUrlExtension($container, $engine);

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
        ],
    ]

Copy link
Member Author

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.

Copy link
Member Author

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. 😄

@mwillbanks mwillbanks merged commit 5e2a8e3 into zendframework:develop Mar 29, 2016
mwillbanks added a commit that referenced this pull request Mar 29, 2016
Provide a URL/ServerUrl extension, and extension loading
mwillbanks added a commit that referenced this pull request Mar 29, 2016
@weierophinney weierophinney deleted the feature/url-extensions branch March 29, 2016 19:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants