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

Remove Zend1 Json from Magento Captcha module #8331

Merged
merged 9 commits into from
Feb 9, 2017

Conversation

dmanners
Copy link
Contributor

@dmanners dmanners commented Jan 30, 2017

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.

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Jan 30, 2017

Magento has own lib for json encode/decode. I think it should be used instead in all places:
https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/Json/EncoderInterface.php
Also classes of Magento\Framework\Json should be fixed to use new version of zend json

@dmanners
Copy link
Contributor Author

@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.

@dmanners
Copy link
Contributor Author

I see that there are 2 ways to approach this either.

  1. Migrate all usage of Zend_Json to use the Magento lib version. Then once this is done migrate the lib version to Zend2.
  2. Just migrate one module at a time directly to Zend2,

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 Zend_Json calls either migrating to the lib call or direct calls to Zend2.

Copy link
Contributor

@buskamuza buskamuza left a comment

Choose a reason for hiding this comment

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

@dmanners
Copy link
Contributor Author

@buskamuza I have updated the module to now use Magento/Framework/Serialize/Serializer/Json.php when dealing with Json.

@dmanners
Copy link
Contributor Author

dmanners commented Feb 2, 2017

All other pull requests in the "Remove Zend1 from Magento Captcha" series can be found:

  1. Remove the usage of Zend_Db_Expr from the captcha module #8389
  2. Remove Zend1 captcha from Magento2 Captcha module #8356

public function __construct(
Context $context,
\Magento\Captcha\Helper\Data $captchaHelper,
\Magento\Framework\Serialize\SerializerInterface $serializer
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor

@ishakhsuvarov ishakhsuvarov left a 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.

@dmanners
Copy link
Contributor Author

dmanners commented Feb 3, 2017

@ishakhsuvarov should all be covered now

@ishakhsuvarov
Copy link
Contributor

Hi @dmanners
We still have some discussion regarding json encoding internally. I am going to proceed with your PR as soon as it is possible.
Sorry for the delay.

@dmanners
Copy link
Contributor Author

dmanners commented Feb 6, 2017

Hi @ishakhsuvarov no rush. I want to get the "best" option here.

@ishakhsuvarov
Copy link
Contributor

Hey @dmanners
Looks like every serialization in the change set requires the data to be explicitly encoded in JSON. Sadly, SerializeInterface can not guarantee, that preference for it would always be Magento\Framework\Serialize\Serializer\Json in future, so, the best solution for now would be to use not interface but Json Serializer class.

\Magento\Framework\Serialize\SerializerInterface $serializer = null
) {
parent::__construct($context);
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
Copy link
Contributor

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.
  • Since you are not modifying the existing constructor but adding a new one – you can inject the dependency in a normal way.

Copy link
Contributor Author

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()
Copy link
Contributor

@ishakhsuvarov ishakhsuvarov Feb 7, 2017

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.

) {
$this->helper = $helper;
$this->sessionManager = $sessionManager;
$this->resultJsonFactory = $resultJsonFactory;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
Copy link
Contributor

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,
Copy link
Contributor

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,
Copy link
Contributor

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.

@mmansoor-magento mmansoor-magento merged commit c5bb856 into magento:develop Feb 9, 2017
@okorshenko
Copy link
Contributor

@dmanners that you for this PR. you made module captcha better again!

@okorshenko okorshenko added this to the February 2017 milestone Feb 11, 2017
@dmanners dmanners deleted the zend1-json-removed branch July 26, 2017 12:00
@korostii korostii mentioned this pull request Jul 27, 2017
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants