2016-12-28 57 views
1

所以,在Laravel,有在使用类路由一个web.php文件,它的静态函数获取和匹配称为类路径。我想了解一下web.php使用

的问题是,这个类是怎样的一个谜给我的,我无法找到它在我的laravel项目源,niether可以找到关于它的任何互联网。 如果你谷歌它,你会发现Illuminate \ Routing \ Route,但我认为这不是我正在寻找的类,因为那个没有静态函数获取和匹配。 我也试过寻找它,我的项目目录,我发现我认为这样的名称的四个类,但他们都没有这些功能,这是在我的web.php中使用。

这里是我的web.php:

<?php 

/* 
|-------------------------------------------------------------------------- 
| Web Routes 
|-------------------------------------------------------------------------- 
| 
| Here is where you can register web routes for your application. These 
| routes are loaded by the RouteServiceProvider within a group which 
| contains the "web" middleware group. Now create something great! 
| 
*/ 

Route::get('/', function() { 
    return view('welcome'); 
}); 

Auth::routes(); 

Route::get('/', '[email protected]')->name('post.all'); 

Route::match(['get', 'post'], '/article/create', '[email protected]')->name('post.create') 
    ->middleware('auth'); 

Route::get('/article/{id}', '[email protected]')->name('post.single'); 

Route::match(['get', 'post'], '/article/{id}/delete', '[email protected]')->name('post.delete') 
    ->middleware('auth', 'author'); 

Route::match(['get', 'post'], '/article/{id}/edit', '[email protected]')->name('post.edit') 
    ->middleware('auth', 'author'); 

Route::get('/author/{id}', '[email protected]')->name('post.author'); 

Route::get('/category/{id}', '[email protected]')->name('post.category'); 

Route::match(['get', 'post'], '/user/create', '[email protected]')->name('user.create') 
    ->middleware('auth'); 

Route::get('/home', '[email protected]'); 

回答

1

你几乎没有;

你会发现它的Illuminate\Routing\Router类下。

,你不会看到在这里静态函数究其原因,是因为Laravel使用一种叫“门面”,它提供了访问实例化类的静态方法。它基本上包装了Route类并为你调用了这些函数。

通过在别名键下查看config/app.php,您可以看到注册到Laravel的所有正面(包括Route一个正面)。

1

你要找的​​类

1

Laravel使用一些OOP的概念,使您的生活更轻松,但的,当你发现了翻盖侧是它也很难得到“引擎盖下”和看看到底发生了什么。

很多这些概念在文档中解释得很好,但我认为你是在寻找可以在https://laravel.com/docs/5.3/facades#how-facades-work中发现的一个。我还会进一步向下滚动到Facade Class Reference部分,您可以轻松查看每个Facade“指向”哪些类。从本质上讲,这一切归结为使用神奇的方法__callStatic(),它允许这种魔法发生。

另外,在文档是“核心概念”的分标题。我建议通过阅读每个人来熟悉服务容器的工作方式和使用方法,这应该让您更好地了解外墙自身的工作原理。

我也将假设你想要找的Route门面背后的类,看看有什么其他的方法还有,在这种情况下,你也应该看项目https://github.com/barryvdh/laravel-ide-helper这将给你的IDE都更好的主意每个门面提供的方法。它可以为你节省很多时间。