Find route from context

@param Context $context
@return Context

@throws NotFoundException
184284
protected function route(Context $context)
    {
        $this->logger->debug('kernel.route: find route from http query');

        // logic already specified
        if($context->logic) {
            $this->logger->debug('kernel.route: forward to #' . $context->logic->name . ', skip routing');
            return $context;
        }

        // find route
        $query = $context->request->method . ' ' . $context->request->uri->path;
        $route = $this->router->find($query);

        // 404
        if(!$route) {
            throw new NotFoundException('No route found for query ' . $query);
        }

        // update context
        $context->route = $route;
        $context->params = $route->params;
        $context->logic = $route->resource;

        $this->logger->debug('kernel.route: #' . $context->logic->name . ' found for query ' . $query);

        return $context;
    }
67102
public function context($context = null)
    {
        if (is_null($context) || empty($context) || $context == "this") {
            $context = null;
        } else {
            $this->__contextAwareContext = $context;
        }
        return $this;
    }
1098983
public function getContext(string $class): Context
    {
        if (!isset($this->contexts[$class])) {
            throw new ContextNotFoundException(sprintf(
                '`%s` context is not found in the suite environment. Have you registered it?',
                $class
            ), $class);
        }

        return $this->contexts[$class];
    }
747486
public function setContext(Context $context)
    {
        $this->context = $context;

        if (empty($this->parameters['secret'])) {
            $this->parameters['secret'] = $context->getSecret();
        }

        return $this;
    }
1204734
public function evaluate( Context $context ) {
		/* @var \Ruler\Variable $left */
		list( $left ) = $this->getOperands();

		return null === $left->prepareValue( $context )->getValue();
	}
610350
public function getRootCategoriesForContext(ContextInterface $context = null)
    {
        $context = $this->getContext($context);

        $this->loadCategories($context);

        return $this->categories[$context->getId()];
    }
184829
public function goBegin(Context $context = null)
    {
        $id = $this->bind($context);
        return $this->getDBQueryBuilder($context)->go($id, 'begin');
    }
1113195
public function setContext($context)
    {
        Assert::isTraversable($context);

        $this->context = MutableBag::from($context);

        return $this;
    }
373256
public function getChildren(OperationContextInterface $context = null)
    {
        $context = $this->ensureContext($context);
        $children = $this->getBinding()->getNavigationService()->getChildren(
            $this->getRepositoryId(),
            $this->getId(),
            $context->getQueryFilterString(),
            $context->getOrderBy(),
            $context->isIncludeAllowableActions(),
            $context->getIncludeRelationships(),
            $context->getRenditionFilterString(),
            $context->isIncludePathSegments()
        );

        $result = [];
        $objectFactory = $this->getObjectFactory();
        foreach ($children->getObjects() as $objectData) {
            if ($objectData->getObject() !== null) {
                $result[] = $objectFactory->convertObject($objectData->getObject(), $context);
            }
        }

        return $result;
    }
1329197
public function getSeoPageContext($context)
    {
        if (isset($this->seoPagesContext[$context])) {
            return $this->seoPagesContext[$context];
        }
        $contextTemplate = $this->findOneBy(['context' => $context]);

        if ($contextTemplate) {
            $this->seoPagesContext[$context] = $contextTemplate;

            return $this->seoPagesContext[$context];
        }

        return null;
    }
704970
public function bind(Context $context)
    {
        if (! isset($context->__UBID)) {
            $context->__UBID = 0;
        }
        $context->__UBID ++;
        
        return spl_object_hash($context) . $context->__UBID;
    }
1343047
protected function loadContextObject()
    {
        $route = $this->getObjectRouteFromPath();

        $obj = $this->modelFactory()->create($route->routeObjType());
        $obj->load($route->routeObjId());

        return $obj;
    }
1285029
private static function parseContext($context)
    {
        if(!isset($context['trace']))
        {
            $context['trace'] = static::getTrace();
        }
        if(!isset($context['errorFile']))
        {
            list($file, $line) = static::getErrorFile();
            $context['errorFile'] = $file;
            $context['errorLine'] = $line;
        }
        return $context;
    }
543359
public function fetchLocation(AnCommandContext $context)
   {
       $data = $context->data;

       if($data->location_id){
           $attr = array('id' => $data->location_id);
       } else {
           $attr = array(
              'latitude' => $data->latitude,
              'longitude' => $data->longitude,
              'name' => $data->name,
              'address' => $data->address,
              'city' => $data->city,
              'state_province' => $data->state_province,
              'country' => $data->country,
              'postalcode' => $data->postalcode
           );
       }

       $this->_location = $this->getService('repos:locations.location')->findOrAddNew($attr);

       return $this->_location;
   }
825391
function getAwaiting(\CharlotteDunois\Livia\Commands\Context $context) {
        if(!\array_key_exists($context->message->author->id.'-'.$context->message->channel->id, $this->awaiting)) {
            throw new \RuntimeException('Context does not exist');
        }
        
        return $this->awaiting[$context->message->author->id.'-'.$context->message->channel->id];
    }
993076
protected function getMappedContext($contextName)
    {
        $this->checkMappedContext($contextName);
        $mappingList = $this->getMappingList();

        return $mappingList[$contextName];
    }
325017
protected function findContextByUser($context_name = 'default', $user = null)
    {
        $context_full_name = strtolower($user->getUsername()) . '_' . strtolower($context_name);

        /* @var $context DefaultResourceContext */
        $context = $this->findOneOrNullBy(array('name' => $context_full_name));

        if (is_null($context)) {
            $context = $this->createNewInstance();
            $context->setName($context_full_name);
            $context->setTitle($context_name);
            $this->persist($context);
        }

        return $context;
    }