Executes `change_account_key` transaction.

@param ChangeAccountKeyCommand $command
@param bool $isDryRun if true, transaction won't be send to network
@return ChangeAccountKeyResponse
514681
public function changeAccountKey(ChangeAccountKeyCommand $command, bool $isDryRun = false): ChangeAccountKeyResponse
    {
        $this->prepareTransaction($command);
        $response = $this->driver->executeTransaction($command, $isDryRun);

        return new ChangeAccountKeyResponse($response->getRawData());
    }
1062516
function grantPermission (commandOptions, { accountId, grantablePermissionName }) {
  return command(
    commandOptions,
    txHelper.addCommand(
      txHelper.emptyTransaction(),
      'grantPermission',
      {
        accountId,
        grantablePermissionName
      }
    )
  )
}
896584
public function command($command, $args = [], $id = null)
    {
        $target = Router::getInstance()->getTarget($command);
        $fn = function () use ($target) {
            return $target->run();
        };

        return $this->call($fn, $args, $id);
    }
1076278
public function executeAsTransaction($query, $arg_sets, $which_connection='')
    {
        $which_connection = $which_connection === '' ? $this->default_db : $which_connection;
        $ret = true;
        $statement = $this->prepare($query, $which_connection);
        $this->startTransaction($which_connection);
        $this->lockTimeout(5, $which_connection);
        foreach ($arg_sets as $args) {
            if (!$this->execute($statement, $args, $which_connection)) {
                $ret = false;
                break;
            }
        }
        if ($ret === true) {
            $this->commitTransaction($which_connection);
        } else {
            $this->rollbackTransaction($which_connection);
        }

        return $ret;
    }
497658
protected function run($command)
    {
        if (array_key_exists('migrationPath', $this->config)) {
            $migrationPaths = $this->config['migrationPath'];

            if (is_string($migrationPaths)) {
                $migrationPaths = [$migrationPaths];
            }

            $this->runMigrationByPaths($migrationPaths, $command);
        } elseif (array_key_exists('migrationNamespaces', $this->config)) {
            $migrationNamespaces = $this->config['migrationNamespaces'];

            if (is_string($migrationNamespaces)) {
                $migrationNamespaces = [$migrationNamespaces];
            }

            $this->runMigrationByNamespaces($migrationNamespaces, $command);
        } else {
            $this->runMigrationByApplication($command);
        }
    }
4171
public function change($key, $value, $backup = true)
    {
        $yaml = $this->lines->join("\n");

        $pattern = '/^' . str_replace('/', ':.*?', $key) . '(:\s*)/mis';
        preg_match($pattern, $yaml, $matches, PREG_OFFSET_CAPTURE);
        if (!$matches) {
            // Throw exception by default in v4.0 instead of returning boolean.
            if (func_num_args() === 4 && func_get_arg(3)) {
                throw new \InvalidArgumentException(sprintf("The key '%s' was not found in %s.", $key, $this->file->getFullPath()));
            }

            return false;
        }

        $column = $matches[1][1] + strlen($matches[1][0]);
        $line = substr_count($yaml, "\n", 0, $column);

        $this->lines[$line] = preg_replace('/^(.*?):(.*(?= #)|.*$)/', '$1: ' . Inline::dump($value), $this->lines[$line]);

        $this->save($backup);

        return true;
    }
551327
public function run(CommandInterface $command)
    {
        $result = null;

        /** @var RunnerInterface $runner */
        foreach($this->runners as $runner) {
            $result = $runner->run($command, $result);
        }

        return $result;
    }
666021
public function send($dry_run = false)
    {
        switch (count($this->messages)) {
            case 0:
                throw new RuntimeException("No messages to send.");
            case 1:
                return $this->sendOne($dry_run);
        }

        $xml = new SimpleXMLExtended('<?xml version="1.0" encoding="utf-8" ?><messages></messages>');
        $xml->addAttribute('xmlns', 'http://www.unwire.com/UM/core/v1.3');
        $xml->addAttribute('xsi:schemaLocation', 'http://www.unwire.com/UM/core/v1.3 https://gw.unwire.com/service/xmlinterface/core-1.3.xsd', 'http://www.w3.org/2001/XMLSchema-instance');
        $xml->addAttribute('count', count($this->messages));
        $xml->addAttribute('service', 'mt');
        $xml->addAttribute('sessionid', (session_id() ?: time()));

        $default = $xml->addChild('defaultvalues');
        $default->addAttribute('type', 'text');

        // set default values
        foreach ($this->getDefaultValues() as $key => $value) {
            if ($key == 'content') {
                $content = $default->addChild($key);
                $content->addChild('text', $value);
            } else if ($key == 'price') {
                $price = $default->addChild('price', $value['amount']);
                $price->addAttribute('currency', $value['currency']);
                if (!is_null($value['vat'])) {
                    $price->addAttribute('vat', $value['vat']);
                }
            } else {
                if ($value) {
                    $default->addChild($key, $value);
                }
            }
        }

        $i=1;

        // add messages
        foreach ($this->messages as $message) {
            $msg = $xml->addChild('sms');
            $msg->addAttribute('id', $i);
            $msg->addAttribute('type', 'text');
            $msg->addChild('msisdn', $message->to);

            if (empty($this->defaults['content'])) {
                $content = $msg->addChild('content');
                $content->addChild('text', $message->message);
            }

            if (empty($this->defaults['operator']) && isset($message->options['smsc'])) {
                $msg->addChild('operator', $message->options['smsc']);
            }

            if (isset($message->options['shortcode'])) {
                $msg->addChild('mediacode', $message->options['shortcode']);
            } else if (empty($this->defaults['shortcode'])) {
                $msg->addChild('shortcode', $this->config['appnr']);
            }

            if (isset($message->options['mediacode'])) {
                $msg->addChild('mediacode', $message->options['mediacode']);
            } else if (empty($this->defaults['mediacode'])) {
                $msg->addChild('mediacode', $this->config['mediacode']);
            }

            if (isset($message->options['price'])) {
                preg_match('/([0-9.]+)([A-Z]{3})/', $message->options['price'], $matches);

                $price = $msg->addChild('price', $matches[1]);
                $price->addAttribute('currency', $matches[2]);
                if (!is_null($this->defaults['price']['vat'])) {
                    $price->addAttribute('vat', $this->defaults['price']['vat']);
                }
            }

            $i++;
        }

        $endpoint = str_replace('://', '://'.$this->config['user'].':'.$this->config['password'].'@', self::BATCH_ENDPOINT);

        $adapter = $this->getAdapter();
        $adapter->setEndpoint($endpoint);
        $adapter->setBody($xml->asXML());

        if ($dry_run) {
            $response = $adapter->dryRun();
        } else {
            $response = $adapter->post();
        }

        // empty query
        $this->messages = array();

        return $response;
    }
897208
public function commandToRequestTransformer(CommandInterface $command)
    {
        $name = $command->getName();
        if (!isset($this->api[$name])) {
            throw new CommandException('Command not found', $command);
        }
        $action = $this->api[$name];

        $prefix = '';
        if (isset($action['public']) && $command->hasParam('public')) {
            $prefix = '/public';
        }

        $prefixes = [
            'system' => '/systems/{system}',
            'issuer' => '/issuers/{issuer}',
            'program' => '/programs/{program}',
        ];
        if (isset($action['admin_contexts'])) {
            $prefix .= implode('', array_intersect_key($prefixes, array_flip($action['admin_contexts']), array_merge($command->toArray(), $this->adminContext)));
        }
        $path = GuzzleHttp\uri_template($prefix.$action['path'], array_merge($command->toArray(), $this->adminContext));

        $headers = [];
        $body = null;
        if ($command->hasParam('body')) {
            $headers = ['Content-Type' => 'application/json'];
            $body = GuzzleHttp\json_encode($command['body']);
        }

        if ($command->hasParam('query')) {
            $path .= '?'.Psr7\build_query($command['query']);
        }

        return new Psr7\Request($action['method'], $path, $headers, $body);
    }
150829
public function execute($command, callable $next)
    {
        $this->entityManager->beginTransaction();

        try {
            $returnValue = $next($command);

            $this->entityManager->flush();
            $this->entityManager->commit();
        } catch (Exception $e) {
            $this->rollbackTransaction();

            throw $e;
        } catch (Throwable $e) {
            $this->rollbackTransaction();

            throw $e;
        }

        return $returnValue;
    }
898775
public final function run(bool $checkRun = true)
    {
        // run once
        if ($checkRun) {
            $this->___checkRun(new ServiceException("You cannot call {$this->name}::run() anymore, it's ".
                "already called in App::run() once"));
        }

        $request = $this->app->request();
        $response = $this->app->response();

        [$serviceMain, $methodMain, $methodOnBefore, $methodOnAfter] = [
            self::SERVICE_MAIN, self::METHOD_MAIN, self::METHOD_ON_BEFORE, self::METHOD_ON_AFTER];

        $serviceName = $request->uri()->segment(1);
        if ($serviceName != null && strtolower($serviceName) == strtolower($serviceMain)) {
            // redirect "main/" to "/" (301 Moved Permanently)
            return $response->redirect('/', 301)->end();
        }
        $serviceMethod = $request->uri()->segment(2);
        if ($serviceMethod != null && strtolower($serviceMethod) == $methodMain) {
            // redirect "<service>/main" to "<service>/" (301 Moved Permanently)
            return $response->redirect('/'. strtolower($serviceName), 301)->end();
        }

        // request method is allowed?
        if (!$this->isAllowedRequestMethod($request->method()->getName())) {
            $response->setStatus(405);
        }

        // call service onbefore
        if (method_exists($this, $methodOnBefore)) {
            $this->$methodOnBefore();
        }

        $output = null;

        // check site/rest, call the target method
        if ($this->isSite()) {
            $methodArguments = (array) $this->getMethodArguments($this->method);
            if ($this->method == '' || $this->method == $methodMain) {
                $output = $this->$methodMain($methodArguments);
            } elseif (method_exists($this, $this->method)) {
                $output = call_user_func_array([$this, $this->method], $methodArguments);
            } else {
                $output = $this->$methodMain($methodArguments); // calls FailService::main() actually
            }
        } elseif ($this->isRest()) {
            $methodArguments = (array) $this->getMethodArguments($this->method);
            if ($this->method == '' || $this->method == $methodMain) {
                $output = $this->$methodMain($methodArguments);
            } elseif (in_array($this->method, ['get', 'post', 'put', 'delete'])) {
                $output = call_user_func_array([$this, $this->method], $methodArguments);
            } else {
                $output = $this->$methodMain($methodArguments); // calls FailService::main() actually
            }
        }

        // call service onafter
        if (method_exists($this, $methodOnAfter)) {
            $this->$methodOnAfter();
        }

        return $output;
    }
1156799
public function handle($command)
    {
        $user = new User();
        $user
            ->setEmail($command->getEmail())
            ->setPassword($command->getPassword())
            ->setRoles($this->registeredUserRoles)
            ->setEnabled(true);

        // validate user
        $errors = $this->validator->validate($user);
        if (count($errors) > 0) {
            $exception = new InvalidCommandException("User is invalid");
            $exception->setConstraintViolationList($errors);
            throw $exception;
        }

        // persist user
        $this->entityManager->persist($user);
        $this->entityManager->flush();

        return $user;
    }
1292827
protected function call(iApiCommand $command)
    {
        $recall = 1;

recall:

        if (method_exists($command, 'setToken')) {
            $token = $this->tokenProvider->getToken();
            $command->setToken($token);
        }


        $response = parent::call($command);

        if ($ex = $response->hasException()) {

            if ( $ex instanceof exTokenMismatch && $recall > 0 ) {
                // Token revoked or mismatch
                // Refresh Token
                // TODO Handle Errors while retrieve token (delete cache)
                try {
                    $this->tokenProvider->exchangeToken();

                } catch (\Exception $e) {
                    // Exchange Not Implemented
                }


                $recall--;

                goto recall;
            }

            throw $ex;
        }


        return $response;
    }
1243816
public function dispatch($command): void
    {
        $this->commandStack[] = $command;

        if ($this->executing) {
            return;
        }

        $this->transactionManager->begin();
        try {
            while ($command = array_shift($this->commandStack)) {
                $this->invokeHandler($command);
            }
            $this->eventPublisher->publishEvents();
            $this->transactionManager->commit();
        } catch (Exception $e) {
            $this->transactionManager->rollback();
            throw $e;
        }
    }
1312647
public function drush($command, array $arguments = array(), array $options = array()) {
    $arguments = implode(' ', $arguments);

    // Disable colored output from drush.
    if (isset(static::$isLegacyDrush) && static::$isLegacyDrush) {
      $options['nocolor'] = TRUE;
    }
    else {
      $options['no-ansi'] = NULL;
    }
    $string_options = $this->parseArguments($options);

    $alias = isset($this->alias) ? "@{$this->alias}" : '--root=' . $this->root;

    // Add any global arguments.
    $global = $this->getArguments();

    $process = new Process("{$this->binary} {$alias} {$string_options} {$global} {$command} {$arguments}");
    $process->setTimeout(3600);
    $process->run();

    if (!$process->isSuccessful()) {
      throw new \RuntimeException($process->getErrorOutput());
    }

    // Some drush commands write to standard error output (for example enable
    // use drush_log which default to _drush_print_log) instead of returning a
    // string (drush status use drush_print_pipe).
    if (!$process->getOutput()) {
      return $process->getErrorOutput();
    }
    else {
      return $process->getOutput();
    }

  }
106909
public <R> R executeTransactionalCommand(final TransactionalCommand<R> command, final int retryCount)
            throws MithraBusinessException
    {
        return this.executeTransactionalCommand(command, new TransactionStyle(this.transactionTimeout, retryCount));
    }
828709
public function runCommand($command, array $options = [])
    {
        if (!is_array($command) && !is_object($command)) {
            throw new InvalidArgumentException(
                sprintf(
                    '$command must be an array or an object, %s given.',
                    \Tequila\MongoDB\getType($command)
                )
            );
        }

        $readPreference = isset($options['readPreference'])
            ? $options['readPreference']
            : $this->readPreference;

        if (!$readPreference instanceof ReadPreference) {
            throw new InvalidArgumentException(
                sprintf(
                    'Option "readPreference" is expected to be an instance of %s, %s given.',
                    ReadPreference::class,
                    \Tequila\MongoDB\getType($readPreference)
                )
            );
        }

        if (!$command instanceof \MongoDB\Driver\Command) {
            $command = new \MongoDB\Driver\Command($command);
        }
        $server = $this->manager->selectServer($readPreference);
        $cursor = $server->executeCommand($this->databaseName, $command);

        return new CommandCursor($cursor);
    }