Search code examples
phplaravellumen

Where is "Closure" class located inside Lumen Framework?


Many of the processes inside lumen use the "closure" class. I know what a closure is, but still I'd like to know what it looks like in Lumen. Therefore, I need to find the file where the class is defined.

For example, my authenticate.php middleware uses "Closure", you can see it in the top of the code:

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

But unlike any other class in Lumen, this one doesn't provide any path to the location of the class in the source code. I've looked up the root directory, and it's not there.

So where is it?


Solution

  • You can scan in the documentation in PHP Closure Class. It was added in PHP 5.3 it is built in PHP not under Lumen Framework or Laravel.