@@ -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,9 +95,11 @@ 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
{
102
+ $ response = ['success ' => true ];
91
103
$ serviceUrl = $ this ->getPackagesJsonUrl ();
92
104
$ this ->curlClient ->setCredentials ($ token , $ secretKey );
93
105
try {
@@ -96,13 +108,13 @@ public function checkCredentials($token, $secretKey)
96
108
$ packagesInfo = $ this ->curlClient ->getBody ();
97
109
$ directory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::COMPOSER_HOME );
98
110
$ directory ->writeFile (self ::PATH_TO_PACKAGES_FILE , $ packagesInfo );
99
- return \Zend_Json::encode (['success ' => true ]);
100
111
} else {
101
- return \Zend_Json:: encode ( ['success ' => false , 'message ' => 'Bad credentials ' ]) ;
112
+ $ response = ['success ' => false , 'message ' => 'Bad credentials ' ];
102
113
}
103
114
} catch (\Exception $ e ) {
104
- return \Zend_Json:: encode ( ['success ' => false , 'message ' => $ e ->getMessage ()]) ;
115
+ $ response = ['success ' => false , 'message ' => $ e ->getMessage ()];
105
116
}
117
+ return $ this ->serializer ->serialize ($ response );
106
118
}
107
119
108
120
/**
0 commit comments