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

Console Command for Listing All Available Prototypes #1001

Closed
butschster opened this issue Sep 29, 2023 · 0 comments · Fixed by #1003
Closed

Console Command for Listing All Available Prototypes #1001

butschster opened this issue Sep 29, 2023 · 0 comments · Fixed by #1003
Assignees
Labels
Component: Prototype Feature Help wanted Contributors, your turn to help us!
Milestone

Comments

@butschster
Copy link
Member

butschster commented Sep 29, 2023

The Spiral framework offers a brilliant development extension to streamline the creation of application services, controllers, middleware, and other classes through AST modification.

Currently, we can mark any class as prototyped with a given name using the #[Prototyped('name')] annotation as shown in the example below:

#[Prototyped('guard')]
final class GuardScope implements GuardInterface
{

}

After annotating our classes, we can run the php app.php prototype:dump command to index all classes marked as prototyped, which is quite handy.

Additionally, the framework allows us to use prototyped classes directly without any need for import using Spiral\Prototype\Traits\PrototypeTrait, as demonstrated below:

namespace App\Endpoint\Web;

use Spiral\Prototype\Traits\PrototypeTrait;

class HomeController
{
    use PrototypeTrait;

    public function index()
    {
        return $this->guard->....;
    }
}

With the existing setup, IDEs provide autocompletion suggestions for such classes, which is an excellent productivity booster.

Read more here https://spiral.dev/docs/basics-prototype

However, one feature that would further enhance this functionality is the ability to list all available prototypes through a console command. It's currently a bit of a hassle not having a straightforward way to view all available prototypes at a glance. Therefore, I propose the addition of a new console command, like:

php app.php prototypes

Upon executing this command, it should return a list of all available prototypes along with their target classes in a tabular format, as exemplified below:

| Name | Target                     |
|------|----------------------------|
| guard| \App\Security\GuardScope   |

This feature will provide a quick overview of all the prototyped classes, making it easier for developers to see what's available at a glance and perhaps aiding in debugging or refining the code structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Prototype Feature Help wanted Contributors, your turn to help us!
Projects
Status: Done
3 participants