Handle an incoming request.

@param  \Modulus\Http\Request $request
@param  bool $continue
@param  array $attributes
@return bool $continue
558072
public function handle($request, $continue, $attributes) : bool
  {
    if (
      $this->autoAssign($attributes) &&
      $this->canProceed($request)
    ) {
      return $continue;
    }

    throw new ClientErrorsException($request->isAjax(), 429);
  }
958297
public function handle($request)
    {
        $entity = $this->repository()->findById($request->getId());

        $this->authorize($request, $entity);

        $items = $this->getProperty($entity, $this->field());

        $replace = new ArrayCollection(array_map(
            function($raw) use ($entity) {
                return $this->getRelatedEntity($raw);
            },
            $request->getData()
        ));

        foreach ($items as $key => $item) {
            if (!$replace->contains($item)) {
                $items->remove($key);
            }
        }

        foreach ($replace as $item) {
            if (!$items->contains($item)) {
                $items->add($item);
            }
        }

        $this->setProperty($entity, $this->field(), $items);

        $this->repository()->getEntityManager()->flush($entity);

        return (
            new RelatedCollectionAction(
                $this->repository(),
                $this->mappedBy(),
                $this->related(),
                $this->transformer()
            )
        )->dispatch($request);
    }
695160
public function handleNew(array $request = [])
    {
        if (isset($request['class']) === true && $request['class'] === '') {
            unset($request['class']);
        }
        if (isset($request['type']) === true && $request['type'] === '') {
            unset($request['type']);
        }
        if (isset($request['navigation_block']) === true && $request['navigation_block'] === '') {
            unset($request['navigation_block']);
        }
        if (isset($request['navigation_id']) === true && $request['navigation_id'] === '') {
            unset($request['navigation_id']);
        }
        $validator = new \Valitron\Validator($request);
        $validator->rule(function ($field, $value, $params, $fields) {
            if ((empty($value) === true && empty($fields['link']) === true)
                || (empty($value) === false && empty($fields['link']) === false)) {
                return false;
            } elseif (empty($value) === false) {
                $page = Model\Page::find($value);
                if ($page === null) {
                    return false;
                }
            }
            return true;
        }, "page_id")->message("{field} is required, must be unique, without a link");
        $validator->rule(function ($field, $value, $params, $fields) {
            if ((empty($value) === true && empty($fields['page_id']) === true)
                || (empty($value) === false && empty($fields['page_id']) === false)) {
                return false;
            }
            return file_exists(rtrim(public_path(), '/') . $value) || (filter_var($value, FILTER_VALIDATE_URL) !== false);
        }, "link")->message("{field} is requried without a page ID");
        $validator->rule('required', ['title']);
        $validator->rule('optional', ['class', 'type', 'navigation_block', 'navigation_id']);
        $validator->rule('numeric', ['type', 'navigation_block']);
        $validator->rule(function ($field, $value, $params, $fields) {
            if (is_array($value) === true || preg_match('/\w+(,\s?\w+)*/', $value) === 1) {
                return true;
            }
            return false;
        }, "class")->message("{field} must be an array or comma-separated");
        $validator->rule(function ($field, $value, $params, $fields) {
            $navigation = Model\Navigation::find($value);
            if ($navigation === null) {
                return false;
            }
            return true;
        }, "navigation_id")->message("{field} must be child of a valid navigation link");
        if ($validator->validate() === false) {
            if (headers_sent() === false) {
                header('X-PHP-Response-Code: 422', true, 422);
            }
            $navigations_list = $this->core->api('Navigation/all/flatten', 'GET')->run();
            $pages = $this->core->api('Page/all', 'GET')->run();
            $pages_list = [];
            foreach ($pages['response'] as $key => $page) {
                if ($page->status === true) {
                    $pages_list[] = $page;
                }
            }
            return $this->templates->render("Main::Navigation", [
                "messages" => [
                    'error' => $validator->errors(),
                    'info' => '',
                    'success' => '',
                    'warning' => ''
                ],
                "navigations" => $navigations_list['response'],
                "pages" => $pages_list
            ]);
        }

        $response = $this->core->api('Navigation', 'POST')->run($request);

        if (headers_sent() === false) {
            foreach ($response["headers"] as $header) {
                header($header[0], $header[1], $header[2]);
            }
        }
        if ($response["headers"][0][2] === 422) {
            $navigations_list = $this->core->api('Navigation/all/flatten', 'GET')->run();
            $pages = $this->core->api('Page/all', 'GET')->run();
            $pages_list = [];
            foreach ($pages['response'] as $key => $page) {
                if ($page->status === true) {
                    $pages_list[] = $page;
                }
            }
            return $this->templates->render("Main::Navigation", [
                "messages" => [
                    'error' => $response['response'],
                    'info' => '',
                    'success' => '',
                    'warning' => ''
                ],
                "navigations" => $navigations_list['response'],
                "pages" => $pages_list
            ]);
        } elseif (($response["headers"][0][2] - 200) * ($response["headers"][0][2] - 299) <= 0) {
            if (isset($_GET['template']) === false) {
                return redirect($this->router->generate('navigations-page') . "?m=2");
            } else {
                return 'Redirect: ' . $this->router->generate('navigations-page') . "?m=2";
            }
        } else {
            return $this->templates->render("500", [
                "error" => $response['response'],
                "result" => ''
            ]);
        }
    }
72627
public function handle($request, $continue)
  {
    if ($request->isDownForMaintenance()) {
      $data = json_decode(file_get_contents($this->down), true);

      if (isset($data['allowed']) && in_array($request->ip(), (array)$data['allowed'])) {
        return $continue;
      }

      if ($this->inExceptArray($request)) {
        return $continue;
      }

      throw new ServiceUnavailableHttpException($data['message'] ?? 'Be right back.', $request->isAjax());
    }

    return $continue;
  }
1290086
public function handle(Request $request, Closure $next, $ability = null)
    {
        if (Auth::check() && $request->user()->can($ability ?: $this->requestedAbility($request), $request)) {
            return $next($request);
        }
        // TODO make abort 403 action configurable
        abort(403);
    }
463670
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        $model = ArrayObject::ensureArrayObject($request->getModel());
        $token = $request->getToken();

        if (isset($model['Status'])) {
            return;
        }

        $details = $this->api->prepareOffsiteDetails($model->toUnsafeArray()); // filter model details for request

        $missing = $this->api->getMissingDetails($details); // sagepay's api is wayward we should check for presence of required minimum

        if (count($missing) > 0) {
            throw new LogicException(
                sprintf(
                    'Missing: %s details are mandatory for current payment request!',
                    implode(", ", array_keys($missing))
                )
            );
        }

        $model['state'] = StateInterface::STATE_WAITING;

        // we do not need any sync action
        // but payum by default do not set any afterUrl to notify token
        if ($token) {
            $model['afterUrl'] = $token->getAfterUrl();
        }

        $response = $this->api->createOffsitePurchase($details);

        $responseArr = $response->toArray();
        $model['state'] = $responseArr['Status'] ==
            Api::STATUS_OK || $responseArr['Status'] == Api::STATUS_OK_REPEATED ?
                StateInterface::STATE_REPLIED :
                StateInterface::STATE_ERROR;

        $model->replace(
            array_merge(
                (array) $model->toUnsafeArray(),
                (array) $response->toArray()
            )
        );

        if ($responseArr['Status'] == Api::STATUS_OK ||
            $responseArr['Status'] == Api::STATUS_OK_REPEATED
        ) {

            throw new HttpRedirect(
                $responseArr['NextURL'] . '=' . $responseArr['VPSTxId']
            );
        }
    }
863298
protected function handle($request)
    {
        $headers = [];
        $class = $this->repository()->getClassName();

        $this->authorize($request, $class);
        $entity = $this->hydrateEntity($class, $request->getData());
        $this->validateEntity($entity);
        $this->repository()->getEntityManager()->persist($entity);
        $this->repository()->getEntityManager()->flush();

        if ($entity instanceof JsonApiResource) {
            $headers['Location'] = $this->repository()->linkJsonApiResource($request, $entity);
        }

        $resource = new Item($entity, $this->transformer());
        return $this->response()->resource($request, $resource, RestResponse::HTTP_CREATED, $headers);
    }
1193525
public function submitStep(Request $request)
    {
        if ($request->has('wizard-action-next')) {
            return $this->nextStep($request);
        }

        if ($request->has('wizard-action-back')) {
            return $this->previousStep($request);
        }

        throw new \RuntimeException('Unknown wizard action');
    }
461759
public function handle(Request $request, callable $next)
    {
        $response = $next($request);
        if ( is_string($response) ) {
            return new Response($response);
        }

        return $response;
    }
287630
public function handle($request, $continue) : bool
  {
    if (
      $this->isReading($request) ||
      $this->shouldIgnore($request) ||
      (
        $this->tokenMatches($request) &&
        $this->hasNotExpired($request)
      )
    ) {
      return $continue;
    }

    throw new TokenMismatchException(
      ($this->hasExpired) ? 'Session has expired' : 'Token mismatch'
    );
  }
1213968
public function executeRequest(Request $request)
    {
        $curl = curl_init();

        if ($request->getPostBody()) {
            curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getPostBody());
        }

        $requestHeaders = $request->getRequestHeaders();
        if ($requestHeaders && is_array($requestHeaders)) {
            $curlHeaders = array();
            foreach ($requestHeaders as $k => $v) {
                $curlHeaders[] = "$k: $v";
            }
            curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeaders);
        }
        curl_setopt($curl, CURLOPT_URL, $request->getUrl());

        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getRequestMethod());
        curl_setopt($curl, CURLOPT_USERAGENT, $request->getUserAgent());

        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
        // 1 is CURL_SSLVERSION_TLSv1, which is not always defined in PHP.
        curl_setopt($curl, CURLOPT_SSLVERSION, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, true);

        if ($request->canGzip()) {
            curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
        }

        $options = $this->client->getClassConfig('Goracash\IO\Curl', 'options');
        if (is_array($options)) {
            $this->setOptions($options);
        }

        foreach ($this->options as $key => $var) {
            curl_setopt($curl, $key, $var);
        }

        $this->client->getLogger()->debug(
            'cURL request',
            array(
                'url' => $request->getUrl(),
                'method' => $request->getRequestMethod(),
                'headers' => $requestHeaders,
                'body' => $request->getPostBody()
            )
        );

        $result = curl_exec($curl);
        if ($result === false) {
            $error = curl_error($curl);
            $code = curl_errno($curl);
            $this->client->getLogger()->error('cURL ' . $error);
            throw new Exception($error, $code);
        }

        $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        list($responseHeaders, $responseBody) = $this->parseHttpResponse($result, $headerSize);

        $response = new Response();
        $response->code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $response->url = $request->getUrl();
        $response->method = $request->getRequestMethod();
        $response->headers = $responseHeaders;
        $response->body = $responseBody;
        $response->status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $response->setContentType(curl_getinfo($curl, CURLINFO_CONTENT_TYPE));

        $this->client->getLogger()->debug(
            'cURL response',
            array(
                'code' => $response->code,
                'headers' => $response->headers,
                'body' => $response->body,
            )
        );
        return $response;
    }
898114
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        /** @var PaymentInterface $payment */
        $payment = $request->getModel();

        if (in_array($payment->getState(), array(PaymentInterface::STATE_APPROVED, PaymentInterface::STATE_DEPOSITED))) {
            $request->markCaptured();

            return;
        }

        if (in_array($payment->getState(), array(PaymentInterface::STATE_DEPOSITING))) {
            $request->markPending();

            return;
        }

        if (in_array($payment->getState(), array(PaymentInterface::STATE_CANCELED))) {
            $request->markCanceled();

            return;
        }

        if (in_array($payment->getState(), array(PaymentInterface::STATE_EXPIRED))) {
            $request->markExpired();

            return;
        }

        if (in_array($payment->getState(), array(PaymentInterface::STATE_FAILED))) {
            $request->markFailed();

            return;
        }

        if (in_array($payment->getState(), array(PaymentInterface::STATE_NEW, PaymentInterface::STATE_APPROVING))) {
            $request->markNew();

            return;
        }

        $request->markUnknown();
    }
761921
public function run(&$request)
    {
        $this->detect($request);
        $request = $this->driver->formatIncomingRequest($request);
    }
926196
public function handle($request, $next)
    {
        $this->debug->setWebhook($request->all());

        return $next($request);
    }
1082528
public function handle($request, Closure $next)
    {
        $this->aclPolicy->defineAbilities();

        if ( ! $this->aclPolicy->passesAuthorization() ) {
            abort(403, config('acl.unauthorized_message'));
        }

        return $next($request);
    }
887433
protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
    {
        foreach ($this->meta['fields'] as $field) {
            $field->fill($request, $model);
        }
    }
924941
public function update(Model $entity, array $attributes)
    {
        if ($entity->update($attributes)) {
            $this->flushCache();

            return true;
        }

        return false;
    }