-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Added possibility to render view with short reference (added RelativeFallbackResolver). #6196
Conversation
It makes add rendering view the same as php include file which contains in the same folder.
You can also describe short names under the |
@Martin-P It is independent from template_map. Moreover getting view should be pointed inside 'template_map' or 'template_path_stack' as full view name 'very-long-view-top-name/very-long-view-top-name2/bar' (like full file path). We use short reference in the same view name space divided by '/' (like files in the same folder). And It's better then include file as after moving main view into another folder subview will work as before, |
@froschdesign I actually disagree on "no private methods" - instead of extending, people should implement the interface on their own. @vnagara this needs tests to verify what you are doing. |
@Ocramius I thank for reply. |
@vnagara no test no merge :) We can discuss the quality of the test on the PR |
I've finished and committed tests. |
@vnagara the tests make your code much clearer now. If I get this correctly, you basically want to use the current template as a name segment of the template that you want to render (for example in a partial)? I'm not sure if I agree with this approach... |
Yeah, you got it right. I've been using (testing) such behaviour for half a year. |
Please restart the build. See #6205 (comment). |
@Ocramius ping. |
@vnagara I don't agree with it from an usability pov - it is quite confusing, and this logic (imo) should be part of a separate resolver that wraps around the aggregate resolver. Thoughts? |
@Ocramius If not for usability for what else should we write classes? I like the idea to set it in the another class. |
Yeah, I agree with that, but I am questioning the usability here. Isn't it confusing that calling
I'm not yet sure how this would work, but it would likely be handled in the setter of the |
All test passed (pleas rerun travis).
There will be taken it if it exists, there is placed test for it (testReturnsResourceFromTopLevelIfExistsInsteadOfTheSameNameSpace). In my view it's is bad idea to create view name in top level without '/' (all them are created inside of module/vendor NS except layout and errors with his own NS). Any other absolute path will work.
I avoided circular dependency in code. It tests only once and if name exists return it. It didn't add any value in any array. |
Yes, but the current resolver doesn't assume that there are slashes in the name of a view, while the new logic does that. Instead, just move it to a new resolver.
Ah, yep, didn't notice that |
Yeah, It sounds good. |
@vnagara yes, the wrapped resolver should be a constructor parameter: class RelativeFallbackResolver implements ResolverInterface
{
public function __construct(ResolverInterface $resolver)
{
$this->resolver = $resolver;
}
public function resolve(...)
{
if ($match = $this->resolver->resolve(...)) {
return $match;
}
// your fallback logic goes here.
}
} |
@@ -27,8 +27,8 @@ class ViewResolverFactory implements FactoryInterface | |||
public function createService(ServiceLocatorInterface $serviceLocator) | |||
{ | |||
$resolver = new ViewResolver\AggregateResolver(); | |||
$resolver->attach($serviceLocator->get('ViewTemplateMapResolver')); | |||
$resolver->attach($serviceLocator->get('ViewTemplatePathStack')); | |||
$resolver->attach(new ViewResolver\RelativeFallbackResolver($serviceLocator->get('ViewTemplateMapResolver'))); |
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.
You can simply wrap once around the aggregate resolver.
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.
Actually, how about $resolver->attach(new ViewResolver\RelativeFallbackResolver($resolver))
here? That would make the fallback resolver just one resolver with lower priority
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.
Hardcoded instantiation of classes makes it impossible to overwrite them. I think a better way would be to retrieve the RelativeFallbackResolver
from the ServiceLocator and thus making it possible to overwrite it when needed.
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.
I attached It. For avoiding wasted checks I did the FallbackResolver more clear and usable only with AggragateResolver.
@Martin-P It will be done by someone with moving the 'ViewResolver\AggregateResolver' there too. This are not included into this issue.
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.
It will be done by someone with moving the 'ViewResolver\AggregateResolver' there too. This are not included into this issue.
Can you point to the issue where this is done? Just to make sure someone is actually doing the moving. I don't see that any reference to this issue has been made yet.
…c98907d This class does not need to be designed for extension. Replacing it is preferrable.
…lative fallback resolver class
…at don't provide the correct plugin type
… model is currently set
…callable that was instantiated Also moving success path to the end of the code block
…k/zendframework@c98907d This class does not need to be designed for extension. Replacing it is preferrable.
…pose of the relative fallback resolver class
…e unknown view renderer types
…e renderers that don't provide the correct plugin type
… `view_model` plugin type
…p when no view model is currently set
…ew model is currently set
…used assignment
…ually use the callable that was instantiated Also moving success path to the end of the code block
…ck-resolver' into develop Close zendframework/zendframework#6196
…ing non existing class
It makes add rendering view the same as php include file which contains
in the same folder.
Now possible use short form to look up in the same folder. If we are in view with template name
'very-long-view-top-name/very-long-view-top-name2/any-name'
we can use:should exist map resolver:
or the same path resolver.