moduleManager = $moduleManager; } public function validate($account, Constraint $constraint) { if (!($constraint instanceof RetailCrmAccess)) { throw new UnexpectedTypeException($constraint, RetailCrmAccess::class); } $client = $this->moduleManager->getRetailCrmClient(); try { $response = $client->request->credentials(); if (!$response->isSuccessful()) { throw new RetailCrmApiException($response->offsetGet('errorMsg')); } $credentials = $response->offsetGet('credentials'); foreach ($constraint->requiredApiMethods as $method) { if (!in_array($method, $credentials)) { $this->context ->buildViolation('retailcrm_access.access_denied', ['%method%' => $method]) ->atPath('crmApiKey') ->addViolation() ; } } } catch (CurlException $e) { $this->context ->buildViolation('retailcrm_access.curl_exception') ->atPath('crmUrl') ->addViolation() ; } catch (LimitException $e) { $this->context ->buildViolation('retailcrm_access.service_unavailable') ->atPath('crmUrl') ->addViolation() ; } catch (InvalidJsonException $e) { $this->context ->buildViolation('retailcrm_access.invalid_json') ->atPath('crmUrl') ->addViolation() ; } catch (\InvalidArgumentException $e) { $this->context ->buildViolation('retailcrm_access.requires_https') ->atPath('crmUrl') ->addViolation() ; } catch (RetailCrmApiException $e) { $this->context ->buildViolation('retailcrm_access.wrong_api_key') ->atPath('crmUrl') ->addViolation() ; } } }