Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extended twig-related things instead of forcing them #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EmanueleMinotto
Copy link
Contributor

As reported by @stof in #1

$app['twig.loader'] = $app->share(function (Application $app) {
return new PuliTemplateLoader($app['puli.repository']);
$app->extend('twig.loader', function ($twigLoader, $app) {
$twigLoader->addLoader(new PuliTemplateLoader($app['puli.repository']));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This depends on the fact that we get a chain loader here, no? What if that's not the case? Should we handle that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, by default there's a Twig_Loader_Chain, but it could be overridden.

I see some possibilities here:

  1. an aggresive strategy, so overriding always the old loader
  2. wrap the current loader with a new Twig_Loader_Chain and than add the Puli loader (:+1:)
  3. don't consider other possibilities, so considering only the Silex default loader

What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof What's your advice?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do an instanceof check to see whether you receive an chain loader. If it is not a chain, just create a chain loader with both in it. If it is already a chain loader, just add your own loader (faster than nesting chain loaders into each other)

@EmanueleMinotto
Copy link
Contributor Author

ping @webmozart

@@ -55,11 +55,17 @@ public function register(Application $app)
public function boot(Application $app)
{
if (isset($app['twig']) && $app['puli.enable_twig']) {
$app['twig.loader'] = $app->share(function (Application $app) {
return new PuliTemplateLoader($app['puli.repository']);
$app->extend('twig.loader', function ($twigLoader, $app) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extending things should not be done on boot time though. Services may have been instantiated already (this was already an issue previously btw)

@EmanueleMinotto EmanueleMinotto force-pushed the extended-twig branch 5 times, most recently from 94b9bd1 to a83e83f Compare December 28, 2015 19:12
@EmanueleMinotto
Copy link
Contributor Author

@stof I've added a check for the chain loader, but this part below isn't still fully clear to me, can you give me an example of what you mean, please?

extending things should not be done on boot time though. Services may have been instantiated already (this was already an issue previously btw)

@webmozart
Copy link
Member

Just rediscovered this PR. I guess this is still relevant? Could you rebase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants