/laravel-autowire

Laravel Autowire

Primary LanguagePHP

Laravel Autowire

Latest Stable Version Total Downloads tests

Usage

  1. Composer
composer require zhwei/laravel-autowire
  1. Register Service Provider (Lumen only)
$app->register(\Zhwei\LaravelAutowire\AutowireServiceProvider::class);
  1. Autowire

Any class implemented the Zhwei\LaravelAutowire\AutowireAble interface will trigger auto-wire after container resolution.

class HelloController implements Zhwei\LaravelAutowire\AutowireAble
{
    /**
     * @autowire
     * @var \Illuminate\Contracts\Cache\Factory
     */
    protected $cache;

    public function hello()
    {
        return $this->cache->store()->get('hello');
    }
}

or trigger by your self:

$hello = new HelloController();
Zhwei\LaravelAutowire\AutowireInjector::inject(app(), $hello);