本文整理汇总了PHP中Symfony\Component\Routing\Router::setContext方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::setContext方法的具体用法?PHP Router::setContext怎么用?PHP Router::setContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Router
的用法示例。
在下文中一共展示了Router::setContext方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* @param ApiDoc $annotation
* @param array $annotations
* @param Route $route
* @param \ReflectionMethod $method
*/
public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
{
if (!($resource = $this->getResource($route))) {
return;
}
$context = new RequestContext('', $resource->getActions()->getActionForRoute($route)->getMethods()[0]);
$this->router->setContext($context);
$routeName = $this->router->match($route->getPath())['_route'];
$section = $this->getSection($routeName, $resource);
foreach ($annotations as $annot) {
if ($annot instanceof GenerateApiDoc) {
$annotation->setSection($section);
if ($this->returnsEntity($route)) {
$this->setOutput($annotation, $resource);
}
if ($this->expectsInput($route)) {
if ($resource->getFormTypeClass() == DynamicFormType::class) {
$entityClass = $resource->getEntityClass();
$handler = new DynamicFormSubscriber($this->em, new $entityClass());
foreach ($handler->getFields() as $field) {
$annotation->addParameter($field, ['dataType' => 'string', 'required' => false]);
}
} else {
$this->setInput($annotation, $resource);
}
}
if ($roles = $route->getDefault('_roles')) {
$annotation->setAuthentication(true);
$annotation->setAuthenticationRoles($roles);
}
$annotation->setDescription($this->getDescription($resource, $route));
$annotation->setDocumentation($this->getDescription($resource, $route));
if ($resource->getActions()->getActionForRoute($route) instanceof Index) {
$this->addFilter($annotation, $resource);
$this->addPagination($annotation, $resource);
}
}
}
}