Append responses onto an operation, checking first if they are already configured.

@param Operation $operation
@param array     $newResponses
501524
private function appendResponses(Operation $operation, array $newResponses)
    {
        foreach ($newResponses as $newResponse) {
            if (!$operation->responses) {
                $operation->responses = [];
            }

            $hasResponse = false;

            /** @var Response $response */
            foreach ($operation->responses as $response) {
                // check if one has already been set. If so, skip it.
                if ($response->response == $newResponse->response) {
                    $hasResponse = true;
                }
            }

            if (!$hasResponse) {
                $operation->responses[] = $newResponse;
            }
        }
    }
578294
public function queue(Operations $operations)
    {
        foreach ($operations->getOperations() as $operation) {
            if ($operation instanceof AddDocumentOperation) {
                $identity = $operation->getDocument()->getIdentity();
                $job = new Job('indexer:add', array((string) $identity));
            } elseif ($operation instanceof AddIdentityOperation) {
                $identity = $operation->getIdentity();
                $job = new Job('indexer:add', array((string) $identity));
            } elseif ($operation instanceof UpdateDocumentOperation) {
                $identity = $operation->getDocument()->getIdentity();
                $job = new Job('indexer:add', array('--update', (string) $identity));
            } elseif ($operation instanceof UpdateIdentityOperation) {
                $identity = $operation->getIdentity();
                $job = new Job('indexer:add', array('--update', (string) $identity));
            } elseif ($operation instanceof DeleteDocumentOperation) {
                $identity = $operation->getDocument()->getIdentity();
                $job = new Job('indexer:delete', array('--identifier', (string) $identity));
            } elseif ($operation instanceof DeleteIdentityOperation) {
                $identity = $operation->getIdentity();
                $job = new Job('indexer:delete', array('--identifier', (string) $identity));
            } elseif ($operation instanceof DeleteTypeOperation) {
                $job = new Job('indexer:delete', array('--type', $operation->getType()));
            } elseif ($operation instanceof DeleteAllOperation) {
                $job = new Job('indexer:delete', array('--all'));
            } elseif ($operation instanceof FlushOperation) {
                $job = new Job('indexer:index', array('--flush'));
            } elseif ($operation instanceof OptimizeOperation) {
                $job = new Job('indexer:index', array('--optimize'));
            } elseif ($operation instanceof CommitOperation) {
                $job = new Job('indexer:index', array('--commit'));
            } elseif ($operation instanceof RollbackOperation) {
                $job = new Job('indexer:index', array('--rollback'));
            } else {
                continue;
            }

            $this->jobManager->addJob($job);
        }

        return true;
    }
1166963
public function saveOperations(array $operations)
    {

        $this->logger->info('Save operations', array('miraklId' => null, "action" => "Operations creation"));
        $this->operationManager->saveAll($operations);
        $this->logOperationsManager->saveAll($this->operationsLogs);
        $this->saveAdjustedOperations($this->adjustedOperations);
        $this->logger->info('[OK] Operations saved', array('miraklId' => null, "action" => "Operations creation"));
    }
977074
private function operationEmail($operation)
    {
        if ($this->test) {
            $to = !empty($operation->test) ? $operation->test : (!empty($operation->to) ? $operation->to : '');
        } else {
            $to = !empty($operation->to) ? $operation->to : '';
        }
        if (!$to) {
            $this->setLogs('Email to address is invalid. No email will be sent.', 'error');

            return false;
        }
        $from  = (isset($operation->from) && !empty(trim($operation->from)))
            ? $operation->from : $this->getIntegrationSetting('email_from');
        $email = new Email();
        $email->setSessionId('new_'.hash('sha1', uniqid(mt_rand())));
        $email->setReplyToAddress($from);
        $email->setFromAddress($from);
        $subject = (isset($operation->subject) && !empty(trim($operation->subject)))
            ? $operation->subject : $this->file->getName();
        $email->setSubject($subject);
        if ($this->file->getCount()) {
            $body = (isset($operation->successMessage) && !empty(trim($operation->successMessage)))
                ? $operation->successMessage : $this->getIntegrationSetting('success_message');
        } else {
            $body = (isset($operation->emptyMessage) && !empty(trim($operation->emptyMessage)))
                ? $operation->emptyMessage : $this->getIntegrationSetting('empty_message');
        }
        $body .= PHP_EOL.PHP_EOL.((isset($operation->footer) && !empty(trim($operation->footer)))
                ? $operation->footer : $this->getIntegrationSetting('footer'));
        $email->setContent($body);
        $email->setCustomHtml(htmlentities($body));

        /** @var MailHelper $mailer */
        $mailer = $this->mailHelper->getMailer();
        $mailer->setLead(null, true);
        $mailer->setTokens([]);
        $to = (!empty($to)) ? array_fill_keys(array_map('trim', explode(',', $to)), null) : [];
        $mailer->setTo($to);
        $mailer->setFrom($from);
        $mailer->setEmail($email);
        $mailer->attachFile($this->file->getLocation(), $this->file->getName());

        $this->setLogs($to, 'emailTo');
        $this->setLogs($from, 'emailFrom');
        $this->setLogs($subject, 'emailSubject');
        $this->setLogs($body, 'emailbody');

        // $mailer->setBody($email);
        // $mailer->setEmail($to, false, $emailSettings[$emailId]['slots'], $assetAttachments, (!$saveStat));
        // $mailer->setCc($cc);
        // $mailer->setBcc($bcc);

        // [ENG-683] start/stop transport as suggested by http://www.prowebdev.us/2013/06/swiftmailersymfony2-expected-response.html and
        // https://github.com/php-pm/php-pm-httpkernel/issues/62#issuecomment-410667217

        $repeatSend = true;
        $sendTry    = 1;
        while ($repeatSend || $sendTry < 4) {
            if (!$mailer->getTransport()->isStarted()) {
                $mailer->getTransport()->start();
            }
            $mailResult = $mailer->send(false, false);
            if ($errors = $mailer->getErrors()) {
                $this->setLogs($errors, 'sendError');
            } else {
                $repeatSend = false;
            }
            ++$sendTry;
            $mailer->getTransport()->stop();
        }

        return $mailResult;
    }
259904
public function ExecuteRequest($operation, $params = array())
	{
		if (!isset($this->soap_client)) {
			$this->soap_client = new SoapClient($this->WSDL, array(
				'soap_version' 	=> $this->soap_version,
				'location' 		=> $this->URL,
				'trace' 		=> 1,
				'exceptions' 	=> 0
			)); 
		}

		$results = $this->soap_client->{$operation}($params);

		$this->_CheckErrors($operation, $results);

		return $results;
	}
329982
private function appendChildren(array &$children, string $name, array $new): void
    {
        foreach ($new as $key => $value) {
            $children[$name.'/'.$key] = $value;
        }
    }
967843
protected function triggerAfterCreationEvent(AddOperation $operation)
    {
        $event = new LdapObjectCreationEvent(Event::LDAP_OBJECT_AFTER_CREATE, $this->schema ? $this->schema->getObjectType() : null);
        $event->setData((new ParameterResolver($this->attributes, $this->hydrator->getParameters()))->resolve());
        $event->setContainer($operation->getLocation());
        $event->setDn($operation->getDn());

        $this->dispatcher->dispatch($event);
    }
116536
public function execute(string $type, string $operation, array $parameters = [])
    {
        return $this->{$type}->{$operation}(...$parameters);
    }
1311277
public function after(
        CommandInterface $command,
        RequestInterface $request,
        Operation $operation
    ) {
        $additional = $operation->getAdditionalParameters();
        if ($additional && $additional->getLocation() == $this->locationName) {
            foreach ($command->toArray() as $key => $value) {
                if (!$operation->hasParam($key)) {
                    $uri = $request->getUri();
                    $query = Psr7\parse_query($uri->getQuery());

                    $query[$key] = $this->prepareValue(
                        $value,
                        $additional
                    );

                    $uri = $uri->withQuery($this->querySerializer->aggregate($query));
                    $request = $request->withUri($uri);
                }
            }
        }

        return $request;
    }
375583
public function respond($response = array(), $replaceResponse = false)
    {
        // Set any final data
        $this->set($response, $replaceResponse);

        // Make sure it only responds once
        if ($this->hasResponded()) {
            return;
        }

        // Clear anything that may have snuck in
        $this->cleanBuffer();

        if (self::$code == 204) {
            // No-body response
            $this->responseSent = true;
            return;
        }

        if (!empty($this->apiResponseCallback) && is_callable($this->apiResponseCallback)) {
            $callback = &$this->apiResponseCallback;
            $callback($this->response);
        }

        // Format for specific output type
        if ($this->responseFormat == 'JSON') {
            if ($this->jsonCallbackWrap) {
                echo $this->jsonCallbackWrap . '(';
            }

            echo json_encode($this->response);

            if ($this->jsonCallbackWrap) {
                echo ');';
            }
        } else {
            throw new \Exception('Invalid response format: '. $this->responseFormat);
        }

        // Indicate the response as already sent
        $this->responseSent = true;
    }
555704
public function execute(OperationInterface $op)
  {
    try {
      if ($op instanceof DeleteOperationInterface) {
        $response = $this->httpClient->delete($op->getEndpoint(), [
          'headers' => $op->getHeaders(),
        ]);
      } elseif ($op instanceof PostOperationInterface) {
        $response = $this->httpClient->post($op->getEndpoint(), [
          'headers' => $op->getHeaders(),
          'body' => $op->getData(),
        ]);
      } elseif ($op instanceof PatchOperationInterface) {
        $response = $this->httpClient->patch($op->getEndpoint(), [
          'headers' => $op->getHeaders(),
          'body' => $op->getData(),
        ]);
      } elseif ($op instanceof PutOperationInterface) {
        $response = $this->httpClient->put($op->getEndpoint(), [
          'headers' => $op->getHeaders(),
          'body' => $op->getData(),
        ]);
      } else {
        $response = $this->httpClient->get($op->getEndpoint());
      }
    } catch (GuzzleHttp\Exception\ClientException $e) {
      throw new Exception\ClientException('ClientException occurred in request to Orchestrate: ' . $e->getMessage(), $e->getCode(), $e);
    } catch (GuzzleHttp\Exception\ServerException $e) {
      throw new Exception\ServerException('ServerException occurred in request to Orchestrate: ' . $e->getMessage(), $e->getCode(), $e);
    }

    $refLink = null;
    $location = null;

    if ($response->hasHeader('ETag')) {
      $refLink = str_replace('"', '', $response->getHeaderLine('ETag'));
    } elseif ($response->hasHeader('Link')) {
      $refLink = str_replace(
        ['<', '>; rel="next"'],
        ['', ''],
        $response->getHeaderLine('Link')
      );
    }

    if ($response->hasHeader('Location')) {
      $location = $response->getHeaderLine('Location');
    }
    $rawValue = $response->getBody(true);
    $value = json_decode($rawValue, true);

    return $op->getObjectFromResponse($refLink, $location, $value, $rawValue);
  }
108773
protected function fireBeforeOperation($operation, OperationArguments $args)
    {
        $this->getEventManager()->triggerEvent(
            new OperationEvent('beforeOperation', $this, $operation, $args)
        );
    }
701239
protected function doOperation($operation, OperationArguments $args)
    {
        try {
            // Trigger 'beforeOperation' event.
            $this->fireBeforeOperation($operation, $args);
            // Run the internal operation.
            $forwardMethod = 'forward' . ucfirst($operation);
            $returnValue   = call_user_func([$this, $forwardMethod], $args);
            // Trigger 'afterOperation' event.
            $this->fireAfterOperation($operation, $args, $returnValue);
            // Return the operation result.
            return $returnValue;
        } catch (Exception $e) {
            // Trigger 'onOperationException' event.
            $this->fireOnOperationException($operation, $args, $e);
            // Throw the original exception.
            throw $e;
        }
    }
1201818
public function append($newvalue) : void
    {
        $index = count((array)$this);
        $this->offsetSet($index, $newvalue);
    }
592116
public function append()
    {
        foreach (func_get_args() as $value) {
            if ($value instanceof ResponseInterface
                || $value instanceof \Exception
                || $value instanceof PromiseInterface
                || is_callable($value)
            ) {
                $this->queue[] = $value;
            } else {
                throw new \InvalidArgumentException('Expected a response or '
                    . 'exception. Found ' . \GuzzleHttp\describe_type($value));
            }
        }
    }
1005788
public final void insertOp(Operation op) {
    ArrayList<Operation> tmp = new ArrayList<Operation>(inputQueue.size() + 1);
    tmp.add(op);
    inputQueue.drainTo(tmp);
    inputQueue.addAll(tmp);
  }
368601
protected function buildOperationCompletedResponse(array $newCIDs, array $successMessages)
    {
        $rf = $this->app->make(ResponseFactoryInterface::class);

        return $rf->json([
            'error' => false,
            'message' => implode("\n", $successMessages),
            'cID' => $newCIDs,
        ]);
    }