Fire the magic!

Searches the method and sends the data to the client.

@return mixed
177116
public function run()
    {
        //check sub controller
        foreach ($this->controllers as $controller) {
            if ($result = $controller->run()) {
                return $result;
            }
        }

        $requestedUrl = $this->getClient()->getUrl();
        $this->normalizeUrl($requestedUrl);
        //check if its in our area
        if (strpos($requestedUrl, $this->triggerUrl) !== 0) return;

        $endPos = $this->triggerUrl === '/' ? 1 : strlen($this->triggerUrl) + 1;
        $uri = substr($requestedUrl, $endPos);

        if (!$uri) $uri = '';

        $route = false;
        $arguments = array();
        $requiredMethod = $this->getClient()->getMethod();

        //does the requested uri exist?
        list($callableMethod, $regexArguments, $method, $routeUri) = $this->findRoute($uri, $requiredMethod);

        if ((!$callableMethod || $method != 'options') && $requiredMethod == 'options') {
            $description = $this->describe($uri);
            $this->send($description);
        }

        if (!$callableMethod) {
            if (!$this->getParentController()) {
                if ($this->fallbackMethod) {
                    $m = $this->fallbackMethod;
                    $this->send($this->controller->$m());
                } else {
                    return $this->sendBadRequest('RouteNotFoundException', "There is no route for '$uri'.");
                }
            } else {
                return false;
            }
        }

        if ($method == '_all_')
            $arguments[] = $method;

        if (is_array($regexArguments)) {
            $arguments = array_merge($arguments, $regexArguments);
        }

        //open class and scan method
        if ($this->controller && is_string($callableMethod)) {
            $ref = new \ReflectionClass($this->controller);

            if (!method_exists($this->controller, $callableMethod)) {
                $this->sendBadRequest('MethodNotFoundException', "There is no method '$callableMethod' in ".
                    get_class($this->controller).".");
            }

            $reflectionMethod = $ref->getMethod($callableMethod);
        } else if (is_callable($callableMethod)) {
            $reflectionMethod = new \ReflectionFunction($callableMethod);
        }

        $params = $reflectionMethod->getParameters();

        if ($method == '_all_') {
            //first parameter is $pMethod
            array_shift($params);
        }

        //remove regex arguments
        for ($i=0; $i<count($regexArguments); $i++) {
            array_shift($params);
        }

        //collect arguments
        foreach ($params as $param) {
            $name = $this->argumentName($param->getName());

            if ($name == '_') {
                $thisArgs = array();
                foreach ($_GET as $k => $v) {
                    if (substr($k, 0, 1) == '_' && $k != '_suppress_status_code')
                        $thisArgs[$k] = $v;
                }
                $arguments[] = $thisArgs;
            } else {

                if (!$param->isOptional() && !isset($_GET[$name]) && !isset($_POST[$name])) {
                    return $this->sendBadRequest('MissingRequiredArgumentException', sprintf("Argument '%s' is missing.", $name));
                }

                $arguments[] = isset($_GET[$name]) ? $_GET[$name] : (isset($_POST[$name]) ? $_POST[$name] : $param->getDefaultValue());
            }
        }

        if ($this->checkAccessFn) {
            $args[] = $this->getClient()->getUrl();
            $args[] = $route;
            $args[] = $arguments;
            try {
                call_user_func_array($this->checkAccessFn, $args);
            } catch (\Exception $e) {
                $this->sendException($e);
            }
        }

        //fire method
        $object = $this->controller;

        return $this->fireMethod($callableMethod, $object, $arguments);

    }
692888
public function send()
    {
        $data = $this->getData();
        $reflect = new ReflectionClass($this);

        $this->trigger('before' . $reflect->getShortName(), new Event($this));
        
        $response = $this->sendData($data);

        $this->trigger('after' . $reflect->getShortName(), new Event($this));

        return $response;
    }
632911
public function sendOne() {
        $db = \Yii::$app->db;

        $transaction = $db->beginTransaction();
        try {
            $id = $db->createCommand('SELECT id FROM {{%email_message}} WHERE status=:status ORDER BY priority DESC, id ASC LIMIT 1 FOR UPDATE', [
                'status' => Message::STATUS_NEW,
            ])->queryScalar();

            if ($id === false) {
                $transaction->rollback();
                return false;
            }

            /** @var Message $model */
            $model = Message::findOne($id);
            $model->status = Message::STATUS_IN_PROGRESS;
            $model->updateAttributes(['status']);

            $transaction->commit();
        } catch (\Exception $e) {
            $transaction->rollback();
            throw $e;
        }

        $transaction = $db->beginTransaction();
        try {

            $result = EmailManager::getInstance()->send(
                $model->from,
                $model->to,
                $model->subject,
                $model->text,
                $model->files,
                $model->bcc
            );
            if ($result) {
                $model->sentAt = new Expression('NOW()');
                $model->status = Message::STATUS_SENT;
            } else {
                $model->status = Message::STATUS_ERROR;
            }

            $model->updateAttributes(['sentAt', 'status']);
            $transaction->commit();
        } catch (\Exception $e) {
            $transaction->rollback();
            throw $e;
        }

        return true;
    }
19715
public function getMethod()
    {
        if ($this->method === null) {
            if (is_null($this->method_override)) {
                $this->method = $this->server->get('request-method');
            } else {
                $this->method = $this->method_override;
            }
            $this->method = strtoupper($this->method);
        }
        return $this->method;
    }
294939
public function getMethod() 
    {
        $this->method || $this->method = strtoupper($this->getServer('REQUEST_METHOD'));
        
        return $this->method;
    }
917520
protected function fire()
    {
        $container = $this->loadTaskContainer();

        $exitCode = 0;

        foreach ($this->getTasks($container) as $task) {
            $thisCode = $this->runTask($container, $task);

            if (0 !== $thisCode) {
                $exitCode = $thisCode;
            }

            if ($thisCode > 0 && ! $this->input->getOption('continue')) {
                $this->output->writeln('[<fg=red>✗</>] <fg=red>This task did not complete successfully on one of your servers.</>');

                break;
            }
        }

        foreach ($container->getFinishedCallbacks() as $callback) {
            call_user_func($callback);
        }

        return $exitCode;
    }
740246
public function execute()
    {
        $result = empty($this->value) ? true : filter_var($this->value, FILTER_VALIDATE_REGEXP, [
            'options' => [
                'regexp' => '/^([\+][0-9]{1,3}[\ \.\-]?)?([\(]{1}[0-9]{2,6}[\)])?([0-9\ \.\-\/]{3,20})((x|ext|extension)[\ ]?[0-9]{1,4})?$/'
            ]
        ]);
        
        if (!$result) {
            $this->msg = 'validator.rule.phone';
        }
    }
1108958
public function execute()
    {
        $code = $this->getRequest()->getParam('code', false);
        $userId = $this->getRequest()->getParam('state');
        //load admin user
        $adminUser = $this->adminUser->create();
        $this->userResource->load($adminUser, $userId);
        //app code and admin user must be present
        if ($code && $adminUser->getId()) {
            $clientId = $this->scopeConfig->getValue(
                \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_ID
            );
            $clientSecret = $this->scopeConfig->getValue(
                \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID
            );
            //callback uri if not set custom
            $redirectUri = $this->storeManager->getStore()
                ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, true);
            $redirectUri .= 'connector/email/callback';

            $data = 'client_id=' . $clientId .
                '&client_secret=' . $clientSecret .
                '&redirect_uri=' . $redirectUri .
                '&grant_type=authorization_code' .
                '&code=' . $code;

            //callback url
            $url = $this->config->getTokenUrl();

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 60);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);

            $response = json_decode(curl_exec($ch));

            if ($response === false) {
                $this->helper->error('Error Number: ' . curl_errno($ch), []);
            }
            if (isset($response->error)) {
                $this->helper->error('OAUTH failed ' . $response->error, []);
            } elseif (isset($response->refresh_token)) {
                //save the refresh token to the admin user
                $adminUser->setRefreshToken(
                    $this->helper->encryptor->encrypt($response->refresh_token)
                );

                $this->userResource->save($adminUser);
            }

            //redirect to automation index page
            return $this->_redirect($this->adminHelper->getUrl('dotdigitalgroup_email/studio'));
        }

        return $this->resultPageFactory->create()
            ->setStatusHeader(404, '1.1', 'Not Found')
            ->setHeader('Status', '404 File not found');
    }
1207665
public function execute()
    {
        $indexIdentifiers = [SessionIndexInterface::INDEX_IDENTIFIER, EventIndexInterface::INDEX_IDENTIFIER];
        foreach ($indexIdentifiers as $indexIdentifier) {
            if (!$this->checkIndexPresence($indexIdentifier)) {
                $this->messageManager->addWarningMessage(
                    "{$indexIdentifier} index does not exist yet. Make sure everything is reindexed."
                );
            }
        }

        /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
        $resultPage = $this->resultPageFactory->create();
        $resultPage->setActiveMenu('Smile_ElasticsuiteAnalytics::search_usage');
        $resultPage->addBreadcrumb(__('Search Engine'), __('Analytics'));
        $resultPage->getConfig()->getTitle()->prepend(__('Search Usage Analytics'));

        return $resultPage;
    }
941387
public function fire()
    {
        $this->displayStatus();

        return $this->runWithBeforeAfterEvents(function () {
            return $this->local ? $this->on('local', [$this, 'execute']) : $this->execute();
        });
    }
1032133
public function send()
    {
        $arguments = func_get_args();
        $method    = array_shift($arguments);
        $args      = array_shift($arguments);

        foreach ($this as $helper) {
            $class = new ReflectionClass($helper);

            if ($class->hasMethod($method)) {
                return $class->getMethod($method)->invokeArgs($helper, $args);
            }
        }

        return parent::send($method);
    }
164918
public function send()
    {
        if (!$this->_user->has('email') || !$this->_user->has('name')) {
            throw new BadMethodCallException(__d('user', 'Missing "name" or "email" property when trying to send the email.'));
        }

        if ($this->config('updateToken') === true) {
            $this->loadModel('User.Users');
            $this->_user->updateToken();
        }

        $subject = $this->_parseVariables((string)$this->subject());
        $body = $this->_parseVariables((string)$this->body());

        if (empty($subject) || empty($body)) {
            return false;
        }

        $sender = new Email($this->config('emailConfig'));
        $sent = false;
        try {
            $sent = $sender
                ->to($this->_user->get('email'), $this->_user->get('name'))
                ->subject($subject)
                ->send($body);
        } catch (\Exception $e) {
            return false;
        }

        return $sent;
    }
894633
public function getMethod()
    {
        if (empty($this->method)) {
            $this->method = strtolower($this->httpRequest()->getRequestMethod());
        }

        return $this->method;
    }
88516
public function send()
    {
        try {
            $response = $this->guzzleClient->request($this->method, $this->uri, $this->options);
        } catch (ClientException $e) {
            $this->handleApiException($e->getResponse()->getBody()->getContents());
        }

        return $this->getBody($response);
    }
568533
protected function fireInputObserver()
    {
        $response = rtrim(self::input(), PHP_EOL);

        if (strcasecmp($response, $this->ec) === 0) {
            return null;
        }

        $callback = $this->io;

        $callback($response);

        usleep(100);

        $this->fireInputObserver();
    }
1026596
public function send()
  {
    if (!array_key_exists($this->code, Status::CODE)) return false;

    if ($this->with !== null || $this->with !== []) {
      $data = array_merge(isset($_SESSION['application']['with']) ? $_SESSION['application']['with'] : [], $this->with);
      $_SESSION['application']['with'] = $data;
    }

    header('Location: ' . $this->url);
    exit;
  }
1021465
public function send()
    {
        $this->hash();

        if ($data = $this->handle('beforeExecuteReturn')) {
            return $data;
        }

        if (!empty($this->payload)) {
            $this->serialized_payload = $this->handle('serialize', $this->payload);
        }

        $this->uri = $this->formatEndpoint();

        $this->handle('beforeExecute');

        $exception = false;
        $res       = null;

        try {
            $client = new Client();

            $res = $client->request(
                $this->method,
                $this->uri,
                $this->headers + $this->formatBody() + $this->options
            );

        } catch (Exception $e) {
            $exception = $e;
        }

        if (is_bool($exception) && $res instanceof Response) {
            $body = $this->handle('parse', $res->getBody());

            if ($data = $this->handle('afterExecuteReturn', $body)) {
                return $data;
            }

            $this->handle('afterExecute', $body);

            return $body;
        }

        $msg = null;

        if ($exception instanceof Exception) {
            $msg = $exception->getMessage();

            if ($exception instanceof RequestException) {
                $msg = $exception->getRequest();

                if ($exception->hasResponse()) {
                    $msg = $exception->getResponse()->getBody()->getContents();
                }
            }
        }

        return $this->handle('error', $msg, ['exception' => $exception instanceof Exception ? $exception : null]);
    }