-
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 Zend1 Json from Magento Captcha module #8331
Conversation
Magento has own lib for json encode/decode. I think it should be used instead in all places: |
@ihor-sviziev In an ideal world that is the approach that I wanted to take and update the lib to use Zend2 rather than Zend1. The honest reason that I did not do this is because updating the main lib and then all the 100s of places that are using it would be far to big a change set. I also could not get the test suit to run to cover these changes. |
I see that there are 2 ways to approach this either.
I can see benefits to both approaches and do not really mind which way to do. I would be happy to work through some of the |
62ddff2
to
b2bc36f
Compare
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.
https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/Json/EncoderInterface.php may be deprecated and removed in future as it has unnecessary responsibilities.
b2bc36f
to
92c317a
Compare
@buskamuza I have updated the module to now use Magento/Framework/Serialize/Serializer/Json.php when dealing with Json. |
8dae3db
to
311a7be
Compare
All other pull requests in the "Remove Zend1 from Magento Captcha" series can be found: |
8f09908
to
65de9c6
Compare
public function __construct( | ||
Context $context, | ||
\Magento\Captcha\Helper\Data $captchaHelper, | ||
\Magento\Framework\Serialize\SerializerInterface $serializer |
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.
Please inject this dependency using optional parameter.
* @param array $formIds | ||
*/ | ||
public function __construct( | ||
CaptchaHelper $helper, | ||
SessionManagerInterface $sessionManager, | ||
JsonFactory $resultJsonFactory, | ||
\Magento\Framework\Serialize\SerializerInterface $serializer, |
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.
Please inject this dependency using optional parameter.
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.
Please improve constructor injections, so that new dependencies are optional parameters.
@ishakhsuvarov should all be covered now |
Hi @dmanners |
Hi @ishakhsuvarov no rush. I want to get the "best" option here. |
Hey @dmanners |
\Magento\Framework\Serialize\SerializerInterface $serializer = null | ||
) { | ||
parent::__construct($context); | ||
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() |
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.
- Please use
Magento\Framework\Serialize\Serializer\Json
instead ofSerializerInterface
, since we can not guarantee that preference will remain Json in the future. - Since you are not modifying the existing constructor but adding a new one – you can inject the dependency in a normal way.
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.
@ishakhsuvarov for the second point do you mean I do not need to default to null?
$this->captchaHelper = $captchaHelper; | ||
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() |
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.
- Please use
Magento\Framework\Serialize\Serializer\Json
instead ofSerializerInterface
, since we can not guarantee that preference will remain Json in the future.
) { | ||
$this->helper = $helper; | ||
$this->sessionManager = $sessionManager; | ||
$this->resultJsonFactory = $resultJsonFactory; | ||
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() |
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.
Please use Magento\Framework\Serialize\Serializer\Json
instead of SerializerInterface
, since we can not guarantee that preference will remain Json in the future.
@@ -62,24 +67,37 @@ protected function setUp() | |||
$this->viewMock = $this->getMock(\Magento\Framework\App\ViewInterface::class); | |||
$this->layoutMock = $this->getMock(\Magento\Framework\View\LayoutInterface::class); | |||
$this->flagMock = $this->getMock(\Magento\Framework\App\ActionFlag::class, [], [], '', false); | |||
$this->serializerMock = $this->getMock( | |||
\Magento\Framework\Serialize\SerializerInterface::class, |
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.
Please use Magento\Framework\Serialize\Serializer\Json
instead of SerializerInterface
.
@@ -79,31 +84,41 @@ protected function setUp() | |||
$this->captchaHelperMock->expects($this->once())->method('getCaptcha') | |||
->with('user_login')->will($this->returnValue($this->captchaMock)); | |||
$this->formIds = ['user_login']; | |||
$this->serializerMock = $this->getMock( | |||
\Magento\Framework\Serialize\SerializerInterface::class, |
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.
Please use Magento\Framework\Serialize\Serializer\Json
instead of SerializerInterface
.
…work\Serialize\SerializerInterface
…er/Refresh/Index.php to use the lib json serializer object
…to/Captcha/Controller/Adminhtml/Refresh/Refresh.php
…on the interface that could change
e916d93
to
c5bb856
Compare
@dmanners that you for this PR. you made module captcha better again! |
Zend Framework 1 has been at end of life since middle of 2016. Zend Framework 2 comes with a json module that works in the same way as the Zend Framework 1 version.
In this pull request I have updated the captcha module to use the zend framework 2 versions of Zend_Json. I have also updated the code to use json decode via object since that is the new default in Zend Framework 2.