zhwei/laravel-autowire

Laravel Autowire Kit

1.1.0 2020-09-10 12:37 UTC

README

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);