spiral/prototype

Automatic dependency injection

v1.0.12 2019-10-11 15:34 UTC

README

Latest Stable Version Build Status Codecov

This spiral framework extension enables IDE friendly helpers and let's you to convert this ...

namespace App\Controller;

use Spiral\Prototype\Traits\PrototypeTrait;

class HomeController
{
    use PrototypeTrait;

    public function index()
    {
        $select = $this->users->select();
    }
}

... into that via php app.php proto:inject -r console command:

namespace App\Controller;

use App\UserRepository;

class HomeController
{
    /** @var UserRepository */
    private $users;

    /**
     * @param UserRepository $users
     */
    public function __construct(UserRepository $users)
    {
        $this->users = $users;
    }

    public function index()
    {
        $select = $this->users->select();
    }
}

Plugin includes collision prevention mechanism and able to modify existed constructors.

License:

MIT License (MIT). Please see LICENSE for more information. Maintained by Spiral Scout.