public function getMetadata($controllerName, $actionName = null, $technology = Context::TECH_GENERIC) { if (!$this->reader) { return null; } $key = $controllerName . '::' . $actionName; if (array_key_exists($key, $this->cache)) { return $this->cache[$key]; } $metadata = null; if (!is_array($this->namespaces[$technology])) { $this->namespaces[$technology] = []; } $className = $this->getControllerClassName($controllerName, $technology); if ($technology == Context::TECH_WEB && !$className) { $className = $this->getControllerClassName($controllerName, Context::TECH_GENERIC); } $classExists = class_exists($className); if (!$classExists && $technology == Context::TECH_REST) { $className = 'App\\Rest\\Controller'; $classExists = true; } if ($classExists) { $metadata = new ContextMetadata(); if (!$actionName) { $metadata->setMappedTo($controllerName); } /** @var Description $classDescr */ $classDescr = $actionName ? null : $this->reader->getClassAnnotation($className, 'VulnModule\\Config\\Annotations\\Description'); /** @var Route $classRouter */ $classRouter = $this->reader->getClassAnnotation($className, 'VulnModule\\Config\\Annotations\\Route'); /** @var ContextAnnotation $classContext */ $classContext = $actionName ? null : $this->reader->getClassAnnotation($className, 'VulnModule\\Config\\Annotations\\Context'); if ($classDescr) { if ($classDescr->description) { $metadata->setDescription($classDescr->description); } } if ($classRouter) { if ($classRouter->name) { $metadata->setRoute($classRouter->name); } $metadata->setRouteParams($classRouter->params); } if ($classContext) { $metadata->setName($classContext->name); } if (!$actionName) { $metadata->setType(Context::TYPE_CONTROLLER); } } else { $this->cache[$key] = null; return null; } if (!$actionName) { $this->cache[$key] = $metadata; return $metadata; } $metadata->setType(Context::TYPE_ACTION); $metadata->setMappedTo($actionName); $methodName = $this->getMethodNameByActionName($actionName, $technology); /** @var Description $methodDescr */ $methodDescr = $this->reader->getMethodAnnotation($className, $methodName, 'VulnModule\\Config\\Annotations\\Description', true); /** @var Route $methodRoute */ $methodRoute = $this->reader->getMethodAnnotation($className, $methodName, 'VulnModule\\Config\\Annotations\\Route', true); /** @var ContextAnnotation $methodContext */ $methodContext = $this->reader->getMethodAnnotation($className, $methodName, 'VulnModule\\Config\\Annotations\\Context', true); if ($methodDescr) { if ($methodDescr->description) { $metadata->setDescription($methodDescr->description); } } if ($methodRoute) { if ($methodRoute->name) { $metadata->setRoute($methodRoute->name); } $metadata->setRouteParams($methodRoute->params); } if ($methodContext) { if ($methodContext->name) { $metadata->setName($methodContext->name); } } $this->cache[$key] = $metadata; return $metadata; }
public function getURL() { $routeName = null; $params = []; $metadata = null; /** @var ContextMetadataFactory $metadataFactory */ $metadataFactory = $this->pixie->container['vulnerability.context_metadata_factory']; if ($this->type == self::TYPE_CONTROLLER) { $metadata = $metadataFactory->getMetadata($this->getMappedTo(), null, $this->technology); $params = ['controller' => $this->getMappedTo()]; } else { if ($this->type == self::TYPE_ACTION && $this->getParent()) { $metadata = $metadataFactory->getMetadata($this->getParent()->getMappedTo(), $this->getMappedTo(), $this->technology); $params = ['controller' => $this->getParent() ? $this->getParent()->getMappedTo() : false, 'action' => $this->getMappedTo()]; } } if ($this->technology == self::TECH_REST) { if (!$metadata) { $metadata = new ContextMetadata(); } if (!$metadata->getRoute()) { $metadata->setRoute('rest'); } } /** @var Vuln\Route $annotation */ if ($metadata) { if ($metadata->getRoute()) { $routeName = $metadata->getRoute(); } else { $routeName = 'default'; } if (count($metadata->getRouteParams())) { $params = array_merge($params, $metadata->getRouteParams()); } if ($metadata->getDescription()) { $this->routeDescription = $metadata->getDescription(); } } if ($this->technology == self::TECH_REST) { if (!$params['controller']) { $params['controller'] = false; } } if ($routeName && in_array($this->technology, [self::TECH_GENERIC, self::TECH_WEB, self::TECH_REST])) { $url = $this->pixie->router->generateUrl($routeName, $params, false, 'http', false); if ($this->technology == self::TECH_REST && $params['action']) { $url .= ' [ ' . strtoupper($params['action']) . ' ]'; } return $url; } $url = $this->getParent() ? $this->getParent()->getURL() : new URL(); if (!is_object($url)) { $parentUrl = $url; $url = new URL(); $url->addSegment($parentUrl); } $url->setTechnology($this->getTechnology()); if ($this->getMappedTo() == 'default' && !$this->parent) { $url->addSegment('/'); } else { if ($this->type == self::TYPE_CONTROLLER) { $url->setService($this->getMappedTo()); } else { if ($this->type == self::TYPE_ACTION) { $url->setMethod($this->getMappedTo()); } else { $url->addSegment($this->getMappedTo()); } } } return $url; }