singleton(ClassInterface::class, T1Impl::class); $out1 = app(ClassInterface::class)(); $this->assertEquals("T1?", $out1); app()->bind(ClassInterface::class, T2Impl::class); $out2 = app(ClassInterface::class)(); $this->assertEquals("T2!", $out2); app()->bind(T1Impl::class, T2Impl::class); $out3 = app(T1Impl::class)(); $this->assertEquals("T2!", $out3); app()->bind(T2Impl::class, T3Impl::class); app()->bind(T1Impl::class, T2Impl::class); app()->singleton(ClassInterface::class, T1Impl::class); $out4 = app(ClassInterface::class)(); $this->assertEquals("T3!", $out4); $user = User::factory()->create(['name'=>'Tomas']); $out5 = app(T4::class, ['user'=>$user])(); $this->assertEquals("Tomas", $out5); }); interface ClassInterface { public function __invoke(); } class T1Impl implements ClassInterface { public function __invoke() { return "T1?"; } } class T2Impl implements ClassInterface { public function __invoke() { return "T2!"; } } class T3Impl implements ClassInterface { public function __invoke() { return "T3!"; } } class T4 { public function __construct( public User $user ){} public function __invoke() { return $this->user->name; } }
而且..這意味著如果我「正確」地執行laravel,它可以讓我刪除「nwidard/larave-modules」模組並覆蓋程式碼的任何部分?
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3