-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Remove zend json from customer data #10259
Remove zend json from customer data #10259
Conversation
- remove zend call and use the Magento Framework, - move work from template into app/code/Magento/Customer/Block/CustomerScopeData.php
…terface in the CustomerScopeData block, - Use \Magento\Framework\Serialize\Serializer\Json instead when dealing with serilization - Update test to mirror the change in the main class
Not 100% sure if this is the "best way" ™️ for replacing the deprecated class that is being injected in. Happy for feedback and change requests. |
@dmanners I see that app/code/Magento/Customer/Block/CustomerScopeData.php file didn't exists in 2.1 releases, so I think it's ok that we can change file before release. |
Ah @ihor-sviziev thanks for the information. I had not noticed it before. |
Hi @dmanners |
Hi @okorshenko, thanks for the feedback. I have a few follow up questions then.
Happy to here any options for making this change. |
*/ | ||
public function getSerializedInvalidationRules() | ||
{ | ||
return $this->serializer->serialize( |
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 don't think serialization in block is a good idea. It is better to just return raw data and JSON (or whatever else) encode in template.
Due to such get...Json
methods in Magento 1 some extensions had to decode string and then re-encode just to modify array.
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.
Thanks for the feedback, generally I agree with you here. I considered putting in one function to cover the serialization of the data. And one to cover the getting of the data. This would then allow 3rd party extensions to manipulate the data. Currently with the data stuck in the template it could not be changed easily anyway. I will have a look around for other examples of code like this.
Hm, this is something new I was not aware of... @okorshenko as all blocks became
http://devdocs.magento.com/guides/v2.1/contributor-guide/backward-compatible-development/index.html more or less describes approach, if some cases are not covered yet we can extend it with time. |
…C rules - keep the $jsonEncoder injection but remove the type, - mark the constructor as PHPMD.UnusedFormalParameter, - split out the config and the serilization to happen in two methods,
*/ | ||
public function getSerializedInvalidationRules() | ||
{ | ||
return $this->serializer->serialize($this->getInvalidationRules()); |
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.
Still... What are the advantages compared to echo json_encode($block->getInvalidationRules();
in template? As to me encoding is purely responsibility of template.
Another thing which just came to my mind: do we have a recommendation to leave JS component declaration in templates? Thus they may be overridden more easily, without touching PHP classes. At least I was not able to find similar occurrence of /js/
or '*'
in *.php
.
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.
Not sure about the leaving of the js declaration in the templates. Though to me this feels like config and to have to change a full template to change the config feels odd.
With regards to the json_encode
in the template I dont agree here. I feel that we should either be using json_encode everywhere or wrap it's usage across the system, which would include templates. This way if a mass change is needed it is easier to manage and roll out.
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.
Have no idea which kind of mass change could it be :D
Ok, I see your point, you want to encapsulate serializer logic in block class and don't make template aware of it (while it does escapeHtml
and other similar things). There is nothing to discuss here, let's wait for the feedback from Oleksii and then maybe put a common recommendation for such situation somewhere to keep the code consistent.
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.
Yeah something like escapeHtml
would be a nice option here also thought about that. It's above this PR but I think some "common" way to do this through templates would be amazing.
Hi @dmanners and @orlangur
So the issue was with the constructor. |
*/ | ||
public function __construct( | ||
\Magento\Framework\View\Element\Template\Context $context, | ||
\Magento\Framework\Json\EncoderInterface $jsonEncoder, | ||
array $data = [] | ||
$jsonEncoder, |
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.
Looks like you removed interface by mistake.
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.
yup, will add that back in.
- moved component configuration to the template file
- rework fix for 2.2.1 without minor change
@magento-team What version of 2.2 will have this included? As of 2.2.7 it doesn't appear to be in there. |
@Ctucker9233 you can check corresponding 2.2 commits: http://prntscr.com/mz7vk2 |
Description
As both Zend_Json and \Magento\Framework\Json\EncoderInterface are now deprecated I have migrated the usage across the the accepted \Magento\Framework\Serialize\Serializer\Json class.
Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist