Skip to content

Conflict between namespace psr-4 prefix and target directory structure #242

@gmanen

Description

@gmanen

Steps to reproduce:

  • Create a symfony project and leave App\ as a psr-4 prefix
  • Create a controller with make:controller App\MyController

Expected behaviour:

  • Generated class named MyController
  • Generated namespace App\Controller\App\MyController
  • Generated file src/Controller/App/MyController.php

Actual result:

  • Generated class named MyController
  • Generated namespace App\Controller\App\MyController
  • Generated file src/Controller/MyController.php

This is because when generating the file path, the psr-4 prefix is replaced in all of the path string like so (Symfony\Bundle\MakerBundle\Util\AutoloaderUtil::getPathForFutureClass()):
str_replace($prefix, '', $className)

If at any point in your directory structure, a directory is named exactly as your psr-4 prefix, it will be removed from the file path.

A simple fix would be to only remove the prefix at the begining of the string. Suggested implementation would be:
substr($className, strlen($prefix))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions