Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow wildcard(*) in config namespace #2181

Open
mostafa-rz opened this issue Jul 12, 2022 · 1 comment
Open

Allow wildcard(*) in config namespace #2181

mostafa-rz opened this issue Jul 12, 2022 · 1 comment
Labels
enhancement A feature or improvement

Comments

@mostafa-rz
Copy link
Contributor

What problem does this feature proposal attempt to solve?

We can add a namespace to the config file and allow the lighthouse to search there for the classes. The namespaces can only be a folder and the class must be inside the folder. If the folder is nested then we have to add all of them. By adding wildcard functionality we can let the client just add the parent namespace, then we test the class name against all the files inside the main folder or nested folders.

|-- app
    |-- Models
        |-- Posts
            |--foo.php
        |-- Users
            |--bar.php
        |--baz.php

With the current solution:

'namespaces' => [
        'models' => ['App', 'App\\Models',  'App\\Models\\Posts',  'App\\Models\\Users'],
    ],

With the proposed feature:

'namespaces' => [
        'models' => ['App', 'App\\Models\\*'],
    ],

Which possible solutions should be considered?

If the wildcard exists in the namespace, then get all the directories inside the path with $fileSystem->directories($path). Try this again for the nested folders. Forming and testing the existence of the class will be the same as before.

Open questions

  1. Is there any predefined way to convert a namespace to the path?
  2. If the answer is no for 1, based on the PSR-4, are these correct?
Namespace Path
App\Models\* app/Models
App\Models\Posts\* app/Models/Posts
@spawnia spawnia added the enhancement A feature or improvement label Jul 12, 2022
@spawnia
Copy link
Collaborator

spawnia commented Jul 12, 2022

I might merge a pull request for this, given it is simple enough to implement and does not hurt performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants