Magento2: Upgrade ZF components. Zend_Json

Created on 13 Apr 2017  路  11Comments  路  Source: magento/magento2

Description
Upgrade components from ZF1 to ZF2

As a long term goal, we would like to eliminate knowledge about 3rd party libraries from Magento code base. Magento code still can use 3rd party libraries, but they must be wrapped by Magento interfaces and classes (adapters) so that 3rd party libraries can be easily substituted by newest versions or alternative implementations.

Acceptance Criteria

  1. Magento interfaces are defined and can be used instead of ZF1 classes in Magento code
  2. Default implementations for new interfaces are defined and configured as the preferences for new interfaces
  3. Client code of the ZF1 components is refactored to use Magento interfaces
  4. Zend classes are used as private services in Magento adapters
  5. Backward compatibility is preserved
  6. ZF1 components are updated to ZF2

List of the components

# | Component Name
(total usages count) | Module Name | Usages Count
------------- | ------------- | ------------- | -------------
1|Zend_Json (total: 51)|FrameworkDataObject.php|1
 | |FrameworkController|1
 | |FrameworkJson|2
 | |FrameworkModule|3
 | |FrameworkWebapi|3
 | |MagentoWeee|6
 | |FrameworkData|4
 | |MagentoTheme|31

Fixed in 2.3.x Format is not valid Ready for Work up for grabs

Most helpful comment

Updated List of the components as of 28th of July

# | Component Name
(total usages count) | Module Name | Usages Count
------------- | ------------- | ------------- | -------------
1|Zend_Json (total: 2)|FrameworkJson|2

That makes me feel good!

All 11 comments

@dmanners if you would like to work on this, I can assign this to you.

Updated List of the components

# | Component Name
(total usages count) | Module Name | Usages Count
------------- | ------------- | ------------- | -------------
1|Zend_Json (total: 15)|FrameworkDataObject.php|1
 | |FrameworkController|1
 | |FrameworkJson|2
 | |FrameworkModule|3
 | |FrameworkWebapi|3
 | |FrameworkData|4
 | |MagentoWidget|1

Updated List of the components as of July

# | Component Name
(total usages count) | Module Name | Usages Count
------------- | ------------- | ------------- | -------------
1|Zend_Json (total: 13)|MagentoCustomer|1
 | |FrameworkDataObject.php|1
 | |FrameworkController|1
 | |FrameworkJson|2
 | |FrameworkModule|5
 | |FrameworkWebapi|3

Just noticed I forgot to include the setup module in the list of places to change that has 5 occurrences.

Current status

lib/internal/Magento/Framework/Controller/Result/Json.php:        $this->json = \Zend_Json::encode($data, $cycleCheck, $options);
lib/internal/Magento/Framework/Module/Setup/Migration.php:    protected function _jsonDecode($encodedValue, $objectDecodeType = \Zend_Json::TYPE_ARRAY)
lib/internal/Magento/Framework/Module/Setup/Migration.php:        return \Zend_Json::decode($encodedValue, $objectDecodeType);
lib/internal/Magento/Framework/Module/PackageInfo.php:     * @throws \Zend_Json_Exception
lib/internal/Magento/Framework/Module/PackageInfo.php:                        $packageData = \Zend_Json::decode($jsonData[$key]);
lib/internal/Magento/Framework/Module/PackageInfo.php:                    } catch (\Zend_Json_Exception $e) {
lib/internal/Magento/Framework/Module/PackageInfo.php:                        throw new \Zend_Json_Exception(
lib/internal/Magento/Framework/Json/Decoder.php:        return \Zend_Json::decode($data);
lib/internal/Magento/Framework/Json/Encoder.php:        return \Zend_Json::encode($data);
lib/internal/Magento/Framework/Webapi/Rest/Request/Deserializer/Json.php:        } catch (\Zend_Json_Exception $e) {
lib/internal/Magento/Framework/Webapi/Test/Unit/Rest/Request/Deserializer/JsonTest.php:            ->will($this->throwException(new \Zend_Json_Exception));
lib/internal/Magento/Framework/Webapi/Test/Unit/Rest/Request/Deserializer/JsonTest.php:                new \Zend_Json_Exception('Decoding error:' . PHP_EOL . 'Decoding failed: Syntax error')
setup/src/Magento/Setup/Test/Unit/Controller/MarketplaceTest.php:            ->will($this->returnValue(\Zend_Json::encode(['success' => true])));
setup/src/Magento/Setup/Test/Unit/Controller/MarketplaceTest.php:            ->will($this->returnValue(\Zend_Json::encode(['success' => true])));
setup/src/Magento/Setup/Model/PackagesAuth.php:                return \Zend_Json::encode(['success' => true]);
setup/src/Magento/Setup/Model/PackagesAuth.php:                return \Zend_Json::encode(['success' => false, 'message' => 'Bad credentials']);
setup/src/Magento/Setup/Model/PackagesAuth.php:            return \Zend_Json::encode(['success' => false, 'message' => $e->getMessage()]);

Updated List of the components as of 28th of July

# | Component Name
(total usages count) | Module Name | Usages Count
------------- | ------------- | ------------- | -------------
1|Zend_Json (total: 2)|FrameworkJson|2

That makes me feel good!

Internal ticket to track issue progress: MAGETWO-69369

Small step backwards but no problem 馃拑 we go again!

# | Component Name
(total usages count) | Module Name | Usages Count
------------- | ------------- | ------------- | -------------
1|Zend_Json (total: 3)|FrameworkJson|2
2| |FrameworkController|1

Hi @dmanners
Thank you for continuous contribution to this component. You almost resolved all issues in that area! 馃憤 馃憤 馃憤
We are closing the issue, but feel free to proceed with Zend_Json refactoring

Hi @okorshenko. Thank you for your report.
The issue has been fixed in magento/magento2#13137 by @dmanners in 2.3-develop branch
Related commit(s):

  • 41a4cf635fe8f64d911be07b876fcbe27e93c6fb
  • 9263b1d34f53efeddac072d00ab689da0652042d

The fix will be available with the upcoming patch release.

Hi @okorshenko. Thank you for your report.
The issue has been fixed in magento/magento2#14438 by @dmanners in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

Was this page helpful?
0 / 5 - 0 ratings