-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
Add parameters injections to ViewRenderer + minor refactoring #122
Conversation
That looks overcomplicated for the problem it solves. |
…ections, withLayoutInjections to ViewRenderer.
Made it a little simpler (merge contentInjections and layoutInjections), and create ApplicationInjection — this is convenient for add parameters, meta and link tags to App views. |
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 like that layout parameters are separated from content parameters. Still, I think that overall it can be simpler.
public function getLayoutParams(): array | ||
{ | ||
return [ | ||
'user' => $this->user->getIdentity(), |
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.
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 defaultParameters set to both: content and layout.
If need only for layout defaultParameters not suitable.
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've meant that such configuration is way more exposed to end user and simpler than modifying ApplicationViewInjection itself. It could be generalized and made configurable.
{ | ||
return [ | ||
[ | ||
'__key' => 'favicon', |
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.
That's static. It's better to have it in HTML directly.
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 didn't understand... Return HTML, for example <link rel="icon" type="image/png" href="/myicon.png">
?
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 mean there's no reason to inject it. It could be just a line of HTML in layout like https://github.com/yiisoft/yii-demo/blob/master/views/layout/main.php#L32
{ | ||
return [ | ||
[ | ||
'__key' => 'generator', |
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.
That's static. It's better to have it in HTML directly.
src/ViewRenderer/ViewRenderer.php
Outdated
use Yiisoft\Strings\Inflector; | ||
use Yiisoft\View\ViewContextInterface; | ||
use Yiisoft\View\WebView; | ||
use Yiisoft\DataResponse\DataResponseFactoryInterface; | ||
use Yiisoft\Yii\Web\Middleware\Csrf; | ||
use Yiisoft\Yii\Web\User\User; | ||
|
||
final class ViewRenderer implements ViewContextInterface |
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.
Can part of these changes such as having defaults for parameters / layout be applied to yiisoft/view package directly?
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.
Also do you plan to move this class somewhere out of the application?
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.
Also do you plan to move this class somewhere out of the application?
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.
Can part of these changes such as having defaults for parameters / layout be applied to yiisoft/view package directly?
This can be partially done. For link and meta tags.
For content/layout params this it's impossible: in yiisoft/view there is no division into content and layout.
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.
Let's add default link and meta-tags to yiisoft/view.
Moved Where to move
? |
|
But Advantages separately package:
CsrfViewInjectionInterface::class => CsrfViewInjection::class, Maybe create package, for example, |
How about having it in yii-view? |
This added dependences for yii-view from router and yii-web. It's ok? |
Yes since it's yii- packages are framework specific. |
Ok, I make it. |
Should be adjusted since https://github.com/yiisoft/csrf is there now. |
See yiisoft/csrf#2 |
…erer # Conflicts: # config/common.php # src/Blog/Post/PostController.php # src/ViewRenderer/ViewRenderer.php
Done... |
please merge these functions to one,thanks /** public function withAddedInjections(array $injections): self
|
This is different functions.
|
Move adding of "csrf" parameters to external class
CsrfViewInjection
. This change will allow without changing ViewRenderer class add any parameters to view or layout.Add class
ApplicationViewInjection
to add params, meta- and link-tags to views.Method
getName()
make static and added cache by object class name.Idea of next steps:
ViewRenderer
to package (separately or yiisoft/view or yiisoft/web)CsrfViewInjection
to package (separately or yiisoft/view or yiisoft/web)ApplicationViewInjection
use in App for add parameters, meta and link tags to views.Example of config:
Example of ApplicationViewInjection: