generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
There is a way to find the namespace of the controller automatically, instead of calling \Yiisoft\FileRouter\FileRouter::withNamespace.
It costs additional io call, regexp parsing and dependency yiisoft/aliases, but it's good feature not to configure the router.
$controllerDirectory = $this->aliases->get('src') . DIRECTORY_SEPARATOR . $this->baseControllerDirectory;
$classPath = $controllerDirectory . DIRECTORY_SEPARATOR . $directoryPath . DIRECTORY_SEPARATOR . $controller;
$filename = $classPath . '.php';
if (file_exists($filename)) {
$content = file_get_contents($filename);
$namespace = preg_match('#namespace\s+(.+?);#', $content, $matches) ? $matches[1] : '';
if (class_exists($namespace . '\\' . $controller)) {
return $namespace . '\\' . $controller;
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels