Standard route handler, pre-authenticated

@param Context $c

@return Response
@throws \Throwable
502221
public function handle(Context $c): Response
  {
    $response = null;
    $this->setContext($c);
    $this->_callStartTime = $this->_callStartTime ?: microtime(true);

    //Verify the request can be processed
    if($this->canProcess($response) !== true)
    {
      if($response instanceof Response)
      {
        return $this->_prepareResponse($c, $response, null);
      }
      throw new \Exception(self::ERROR_ACCESS_DENIED, 403);
    }

    return parent::handle($c);
  }
438297
public function redirect(AnCommandContext $context)
    {
        $url = null;

        if ($context->action == 'delete') {
            $url = 'option=com_'.$this->getIdentifier()->package.'&view='.AnInflector::pluralize($this->getIdentifier()->name);
        } elseif ($context->action == 'add') {
            $url = $context->result->getURL().'&get=settings';
        }

        if ($url) {
            $context->response->setRedirect(route($url));
        }
    }
731287
public void handle(RequestContext context, AuthenticationException e) throws SecurityProviderException,
            IOException {
        saveRequest(context);

        String loginFormUrl = getLoginFormUrl();

        if (StringUtils.isNotEmpty(loginFormUrl)) {
            RedirectUtils.redirect(context.getRequest(), context.getResponse(), loginFormUrl);
        } else {
            sendError(e, context);
        }
    }
243624
public function handle(
    Handler $handler, $sendResponse = true, $catchExceptions = true, $flushHeaders = true, $throwEventExceptions = false
  )
  {
    $this->_eventChannel->setShouldThrowExceptions($throwEventExceptions);
    $c = $this->getContext();
    if($handler instanceof ContextAware)
    {
      $handler->setContext($c);
    }

    try
    {
      $this->_eventChannel->trigger(PreExecuteEvent::i($c, $handler));
      $r = $handler->handle($c);
      $this->_eventChannel->trigger(ResponsePrepareEvent::i($c, $handler, $r));
      $r->prepare($c->request());
      $this->_eventChannel->trigger(ResponsePreparedEvent::i($c, $handler, $r));
    }
    catch(\Throwable $e)
    {
      if(!$catchExceptions)
      {
        throw $e;
      }
      $this->getLogger()->error($e->getMessage());
      $r = (new ExceptionHandler($e))->handle($c);
      $r->prepare($c->request());
    }
    try
    {
      if($sendResponse)
      {
        $this->_eventChannel->trigger(ResponsePreSendHeadersEvent::i($c, $handler, $r));
        $r->sendHeaders();
        if($flushHeaders)
        {
          flush();
        }
        $this->_eventChannel->trigger(ResponsePreSendContentEvent::i($c, $handler, $r));
        $r->send();
      }
      $this->_eventChannel->trigger(HandleCompleteEvent::i($c, $handler, $r));
    }
    catch(\Throwable $e)
    {
      if(!$catchExceptions)
      {
        throw $e;
      }
      $this->getLogger()->error($e->getMessage());
    }
    return $r;
  }
1212949
protected function _processHandler(Context $c, $handler, &$response): bool
  {
    $processed = $handler !== null && !is_string($handler);
    while(is_callable($handler))
    {
      $handler = $handler($c);
    }

    if($handler instanceof ContextAware)
    {
      $handler->setContext($c);
    }

    if($handler instanceof Handler)
    {
      $c->events()->trigger(PreExecuteEvent::i($c, $handler));
      $response = $handler->handle($c);
      return true;
    }

    if($handler)
    {
      $response = $handler;
    }

    return $processed;
  }
1362939
private void routeHandle(RouteContext context) {
        Object target = context.routeTarget();
        if (null == target) {
            Class<?> clazz = context.routeAction().getDeclaringClass();
            target = WebContext.blade().getBean(clazz);
        }
        if (context.targetType() == RouteHandler.class) {
            RouteHandler routeHandler = (RouteHandler) target;
            routeHandler.handle(context);
        } else if (context.targetType() == RouteHandler0.class) {
            RouteHandler0 routeHandler = (RouteHandler0) target;
            routeHandler.handle(context.request(), context.response());
        } else {
            Method   actionMethod = context.routeAction();
            Class<?> returnType   = actionMethod.getReturnType();

            Path path = target.getClass().getAnnotation(Path.class);
            JSON JSON = actionMethod.getAnnotation(JSON.class);

            boolean isRestful = (null != JSON) || (null != path && path.restful());

            // if request is restful and not InternetExplorer userAgent
            if (isRestful) {
                if (!context.isIE()) {
                    context.contentType(Const.CONTENT_TYPE_JSON);
                } else {
                    context.contentType(Const.CONTENT_TYPE_HTML);
                }
            }

            int len = actionMethod.getParameterTypes().length;

            MethodAccess methodAccess = BladeCache.getMethodAccess(target.getClass());

            Object returnParam = methodAccess.invoke(
                    target, actionMethod.getName(), len > 0 ?
                            context.routeParameters() : null);

            if (null == returnParam) {
                return;
            }

            if (isRestful) {
                context.json(returnParam);
                return;
            }
            if (returnType == String.class) {
                context.body(
                        ViewBody.of(new ModelAndView(returnParam.toString()))
                );
                return;
            }
            if (returnType == ModelAndView.class) {
                context.body(
                        ViewBody.of((ModelAndView) returnParam)
                );
            }
        }
    }
912074
final public function execute($action, AnCommandContext $context)
    {
        $method = '_'.AnInflector::variablize('authorize.'.$action);

        $result = self::AUTH_NOT_IMPLEMENTED;

        if (method_exists($this, $method)) {
            $this->_entity = $context->mixer;
            $this->_viewer = $context->viewer;
            $result = $this->$method($context);
        }

        return $result;
    }
787899
protected function _getHandler(Context $context)
  {
    $conditions = $this->_generateRoutes();
    if(is_iterable($conditions))
    {
      return $this->_traverseConditions($context, $conditions);
    }
    else if($conditions instanceof Handler || is_callable($conditions) || is_string($conditions))
    {
      return $conditions;
    }

    return null;
  }
804391
protected function _beforeAdd(KControllerContextInterface $context)
    {
        $context->request->data->ip = $this->getObject('request')->getAddress();
    }
449349
public function challengeResponse(DispatcherContext $context)
    {
        $response = $context->getResponse();

        //The response MUST include a WWW-Authenticate header field.
        if($response->getStatusCode() == HttpResponse::UNAUTHORIZED) {
            $response->headers->set('Www-Authenticate', ucfirst($this->getScheme()).' realm="'.$this->getRealm().'"', false);
        }
    }
521889
public function route(Route $route, $handler) 
	{
		if (!is_callable($handler)) {
			throw new Exception('Route handler must be callable.');
		}

		$this->currentContext->addRoute($route, $handler);
		return $this;
	}
1049695
public function process(Request $request, Handler $handler): Response
    {
        $method = $request->getMethod();
        $uri = $request->getUri()->getPath() ?: '/';

        $routeInfo = $this->getDispatcher()->dispatch($method, $uri);

        switch ($routeInfo[0]) {
            case Dispatcher::NOT_FOUND:
                throw new RouteNotFoundException($uri);
            case Dispatcher::METHOD_NOT_ALLOWED:
                throw new MethodNotAllowedException($method);
            case Dispatcher::FOUND:
                $handler = $routeInfo[1];
                $parameters = $routeInfo[2];

                return $handler($request, $parameters);
        }
    }
746293
public function handle(Context $c): Response
  {
    $result = ($this->_func)($c);
    if($result instanceof Handler)
    {
      $c->events()->trigger(PreExecuteEvent::i($c, $result));
      return $result->handle($c);
    }
    else if($result instanceof Response)
    {
      return $result;
    }
    throw new Exception("invalid lazy handler response " . gettype($result), 500);
  }
473633
protected function _actionCancel(KControllerContextInterface $context)
	{
        //Create the redirect
        $context->response->setRedirect($this->getReferrer($context));

        if ($context->result instanceof KModelEntityInterface) {
            $entity = $context->result;
        }
        else
        {
            $model  = $this->getModel();
            $entity = $model->getState()->isUnique() ? $model->fetch() : $model->create();
        }

        return $entity;
	}
519565
public function handler(): Response
    {
        $this->auth(null);
        $data = $this->validate([
            'username' => [
                new NotBlank()
            ],
            'password' => [
                new NotBlank()
            ]
        ]);
        $member = Member::search($data['username']);
        if (!$member) {
            throw new HttpUnauthorizedException();
        }
        if (password_verify($data['password'], $member->getPassword())) {
            $this->auth($member);
            $this->log('info', 'Login successfully');
            return response();
        } else {
            $this->log('info', 'Login failed');
            throw new HttpUnauthorizedException();
        }
    }
1286806
public function handle(Request $request) : Response
	{
		if ($result = $this->handleContext($request, $this->rootContext)) {
			return $result;
		}
		
		if ($defaultHandler = $this->rootContext->getDefault()) {
			return $this->resultToResponse(
				call_user_func($defaultHandler, $request, null)
			);
		}
		
		throw new Exception('No matching route found. Set a default handler on root context to cover this case.');
	}
956570
public function getRequestHandle(RequestContext $context)
    {
        $curlHandle = curl_init();

        $defaults = $this->getDefaultSettings($context);

        $defaults += $this->getCurlTimeoutSettings($context);

        $defaults += $this->getCurlSslSettings();

        $defaults += $this->getProxySettings($context);

        curl_setopt_array(
            $curlHandle, //@codeCoverageIgnore
            $context->getCurlOptions() + $defaults + $this->getRequestDataAndMethodOptions($context)
        );

        return $curlHandle;
    }