@@ -49,19 +49,29 @@ class PackagesAuth
49
49
*/
50
50
private $ filesystem ;
51
51
52
+ /**
53
+ * @var \Magento\Framework\Serialize\Serializer\Json
54
+ */
55
+ private $ serializer ;
56
+
52
57
/**
53
58
* @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
54
59
* @param \Magento\Framework\HTTP\Client\Curl $curl
55
60
* @param \Magento\Framework\Filesystem $filesystem
61
+ * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
62
+ * @throws \RuntimeException
56
63
*/
57
64
public function __construct (
58
65
\Zend \ServiceManager \ServiceLocatorInterface $ serviceLocator ,
59
66
\Magento \Framework \HTTP \Client \Curl $ curl ,
60
- \Magento \Framework \Filesystem $ filesystem
67
+ \Magento \Framework \Filesystem $ filesystem ,
68
+ \Magento \Framework \Serialize \Serializer \Json $ serializer = null
61
69
) {
62
70
$ this ->serviceLocator = $ serviceLocator ;
63
71
$ this ->curlClient = $ curl ;
64
72
$ this ->filesystem = $ filesystem ;
73
+ $ this ->serializer = $ serializer ?: \Magento \Framework \App \ObjectManager::getInstance ()
74
+ ->get (\Magento \Framework \Serialize \Serializer \Json::class);
65
75
}
66
76
67
77
/**
@@ -85,6 +95,7 @@ public function getCredentialBaseUrl()
85
95
* @param string $token
86
96
* @param string $secretKey
87
97
* @return string
98
+ * @throws \InvalidArgumentException
88
99
*/
89
100
public function checkCredentials ($ token , $ secretKey )
90
101
{
@@ -96,12 +107,12 @@ public function checkCredentials($token, $secretKey)
96
107
$ packagesInfo = $ this ->curlClient ->getBody ();
97
108
$ directory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::COMPOSER_HOME );
98
109
$ directory ->writeFile (self ::PATH_TO_PACKAGES_FILE , $ packagesInfo );
99
- return \Zend_Json:: encode (['success ' => true ]);
110
+ return $ this -> serializer -> serialize (['success ' => true ]);
100
111
} else {
101
- return \Zend_Json:: encode (['success ' => false , 'message ' => 'Bad credentials ' ]);
112
+ return $ this -> serializer -> serialize (['success ' => false , 'message ' => 'Bad credentials ' ]);
102
113
}
103
114
} catch (\Exception $ e ) {
104
- return \Zend_Json:: encode (['success ' => false , 'message ' => $ e ->getMessage ()]);
115
+ return $ this -> serializer -> serialize (['success ' => false , 'message ' => $ e ->getMessage ()]);
105
116
}
106
117
}
107
118
0 commit comments