@@ -49,19 +49,29 @@ class PackagesAuth
4949 */
5050 private $ filesystem ;
5151
52+ /**
53+ * @var \Magento\Framework\Serialize\Serializer\Json
54+ */
55+ private $ serializer ;
56+
5257 /**
5358 * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
5459 * @param \Magento\Framework\HTTP\Client\Curl $curl
5560 * @param \Magento\Framework\Filesystem $filesystem
61+ * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
62+ * @throws \RuntimeException
5663 */
5764 public function __construct (
5865 \Zend \ServiceManager \ServiceLocatorInterface $ serviceLocator ,
5966 \Magento \Framework \HTTP \Client \Curl $ curl ,
60- \Magento \Framework \Filesystem $ filesystem
67+ \Magento \Framework \Filesystem $ filesystem ,
68+ \Magento \Framework \Serialize \Serializer \Json $ serializer = null
6169 ) {
6270 $ this ->serviceLocator = $ serviceLocator ;
6371 $ this ->curlClient = $ curl ;
6472 $ this ->filesystem = $ filesystem ;
73+ $ this ->serializer = $ serializer ?: \Magento \Framework \App \ObjectManager::getInstance ()
74+ ->get (\Magento \Framework \Serialize \Serializer \Json::class);
6575 }
6676
6777 /**
@@ -85,9 +95,11 @@ public function getCredentialBaseUrl()
8595 * @param string $token
8696 * @param string $secretKey
8797 * @return string
98+ * @throws \InvalidArgumentException
8899 */
89100 public function checkCredentials ($ token , $ secretKey )
90101 {
102+ $ response = ['success ' => true ];
91103 $ serviceUrl = $ this ->getPackagesJsonUrl ();
92104 $ this ->curlClient ->setCredentials ($ token , $ secretKey );
93105 try {
@@ -96,13 +108,13 @@ public function checkCredentials($token, $secretKey)
96108 $ packagesInfo = $ this ->curlClient ->getBody ();
97109 $ directory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::COMPOSER_HOME );
98110 $ directory ->writeFile (self ::PATH_TO_PACKAGES_FILE , $ packagesInfo );
99- return \Zend_Json::encode (['success ' => true ]);
100111 } else {
101- return \Zend_Json:: encode ( ['success ' => false , 'message ' => 'Bad credentials ' ]) ;
112+ $ response = ['success ' => false , 'message ' => 'Bad credentials ' ];
102113 }
103114 } catch (\Exception $ e ) {
104- return \Zend_Json:: encode ( ['success ' => false , 'message ' => $ e ->getMessage ()]) ;
115+ $ response = ['success ' => false , 'message ' => $ e ->getMessage ()];
105116 }
117+ return $ this ->serializer ->serialize ($ response );
106118 }
107119
108120 /**
0 commit comments