yiisoft / yiisoft/file-router

feat: Namespace autorecognition

Open
#2 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
7
Forks
0
Avg merge
59m
Merged PRs (30d)
1

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;
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading FileRouter::withNamespace and the router entry points that currently require it, then inspect how the yiisoft/aliases dependency resolves the controller directory. Compare the proposed namespace lookup with the existing routing flow; done means a controller namespace can be detected automatically without calling withNamespace, while preserving explicit configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.