1

I'm starting a fresh Laravel 4 application for the first time and one of the things I notice is that there is some magic going on when I follow the quick start guide. It suggests things like this to set up routes:

Route::get(...)

But when I went to find the static get function in the \Illuminate\Routing\Route class it wasn't there. It seems to actually be calling Illuminate\Routing\Router. I haven't dug into how it is calling this on the Router class yet.

But when I looked at the Router class's get function it's not static. Following a stack trace it seems that it is going through some Facade classes that manage a singleton instance of the class, and then use __callStatic to call the instance methods.

Is it possible to write my code without taking advantage of some of these shortcuts? My IDE is not able to follow these things very well so I lose autocomplete and function details. I tried to instantiate a Router instance manually and call the get function dynamically but it did not seem to get hooked into the application and was ignored. I would also like to explicitly include Laravel namespaces, but it seems to convert things like Route to \Illuminate\Routing\Router automatically, which I'm finding difficult to follow.

4

2 回答 2

4

是的,可以不使用 Facades,但不建议这样做。

相反,请考虑使用 IDE 帮助程序,例如https://github.com/barryvdh/laravel-ide-helper

于 2013-06-26T18:55:25.733 回答
0

Laravel 使用 Facade 模式是为了方便。您确实可以在不使用外观的情况下编写您的应用程序,但这会更加乏味。门面只是访问 App 容器上的项目,因此如果您查看各种服务提供者,您可以获取您需要的内容。

于 2013-06-26T18:42:27.597 回答