spiral / framework

High-Performance PHP Framework
https://spiral.dev
MIT License
1.8k stars 87 forks source link

Console Command for Listing All Available Prototypes #1001

Closed butschster closed 11 months ago

butschster commented 1 year ago

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.