Пример #1
0
 /**
  * Handler for all SOAP operations.
  *
  * @param string $operation
  * @param array $arguments
  * @return \stdClass|null
  * @throws WebapiException
  * @throws \LogicException
  * @throws AuthorizationException
  */
 public function __call($operation, $arguments)
 {
     $requestedServices = $this->_request->getRequestedServices();
     $serviceMethodInfo = $this->_apiConfig->getServiceMethodInfo($operation, $requestedServices);
     $serviceClass = $serviceMethodInfo[SoapConfig::KEY_CLASS];
     $serviceMethod = $serviceMethodInfo[SoapConfig::KEY_METHOD];
     // check if the operation is a secure operation & whether the request was made in HTTPS
     if ($serviceMethodInfo[SoapConfig::KEY_IS_SECURE] && !$this->_request->isSecure()) {
         throw new WebapiException(__("Operation allowed only in HTTPS"));
     }
     $isAllowed = false;
     foreach ($serviceMethodInfo[SoapConfig::KEY_ACL_RESOURCES] as $resource) {
         if ($this->_authorization->isAllowed($resource)) {
             $isAllowed = true;
             break;
         }
     }
     if (!$isAllowed) {
         throw new AuthorizationException(__(AuthorizationException::NOT_AUTHORIZED, ['resources' => implode(', ', $serviceMethodInfo[SoapConfig::KEY_ACL_RESOURCES])]));
     }
     $service = $this->_objectManager->get($serviceClass);
     $inputData = $this->_prepareRequestData($serviceClass, $serviceMethod, $arguments);
     $outputData = call_user_func_array([$service, $serviceMethod], $inputData);
     return $this->_prepareResponseData($outputData, $serviceClass, $serviceMethod);
 }