"Closure" class 在 Lumen Framework 中的什么位置?
Where is "Closure" class located inside Lumen Framework?
lumen 中的许多进程使用 "closure" class。我知道闭包是什么,但我仍然想知道它在 Lumen 中的样子。因此,我需要找到定义 class 的文件。
比如我的authenticate.php中间件使用的是"Closure",在代码最上面可以看到:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Factory as Auth;
class Authenticate
{
/**
* The authentication guard factory instance.
*
* @var \Illuminate\Contracts\Auth\Factory
*/
protected $auth;
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
* @return void
*/
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if ($this->auth->guard($guard)->guest()) {
return response('Unauthorized.', 401);
}
return $next($request);
}
}
但与 Lumen 中的任何其他 class 不同的是,这个 class 不提供源代码中 class 位置的任何路径。我查了根目录,没有。
那么它在哪里呢?
您可以扫描PHPClosure Class中的文档。它是在 PHP 5.3 中添加的,它是在 PHP 中构建的,而不是在 Lumen Framework 或 Laravel.
中构建的
lumen 中的许多进程使用 "closure" class。我知道闭包是什么,但我仍然想知道它在 Lumen 中的样子。因此,我需要找到定义 class 的文件。
比如我的authenticate.php中间件使用的是"Closure",在代码最上面可以看到:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Factory as Auth;
class Authenticate
{
/**
* The authentication guard factory instance.
*
* @var \Illuminate\Contracts\Auth\Factory
*/
protected $auth;
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
* @return void
*/
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if ($this->auth->guard($guard)->guest()) {
return response('Unauthorized.', 401);
}
return $next($request);
}
}
但与 Lumen 中的任何其他 class 不同的是,这个 class 不提供源代码中 class 位置的任何路径。我查了根目录,没有。
那么它在哪里呢?
您可以扫描PHPClosure Class中的文档。它是在 PHP 5.3 中添加的,它是在 PHP 中构建的,而不是在 Lumen Framework 或 Laravel.
中构建的