Lumen PHP Framework

repository·10.x·Indexed 27 days ago

https://github.com/laravel/lumen

A high-performance PHP micro-framework for building web applications and microservices. It provides simplified routing, database abstraction, queueing, and caching, utilizing the Laravel\Lumen\Application instance as both the IoC container and router.

Tokens
699
Snippets
6
Records
7
Agent score
43%

What's inside Lumen

  1. Overview of Lumen PHP Framework

    10.x

    Lumen is a fast PHP micro-framework designed for building web applications with expressive syntax. It simplifies common web development tasks such as routing, database abstraction, queueing, and caching.

    Important Recommendation: Due to performance improvements in PHP and the availability of Laravel Octane, it is no longer recommended to start new projects with Lumen. For new projects, it is recommended to use Laravel instead.

  2. Configure Application Routes

    10.x

    Routes are typically loaded by including a routes file (e.g., routes/web.php) within a router group. This allows you to define a default namespace for your controllers.

    $app->router->group([
        'namespace' => 'App\Http\Controllers',
    ], function ($router) {
        require __DIR__.'/../routes/web.php';
    });
  3. Register Global and Route Middleware

    10.x

    Middleware can be registered in two ways:

    1. Global Middleware: Runs on every request. Use $app->middleware([...]).
    2. Route Middleware: Assigned to specific routes via a key. Use $app->routeMiddleware([...]).

    Register these in bootstrap/app.php.

    $app->middleware([
        App\Http\Middleware\ExampleMiddleware::class
    ]);
    
    $app->routeMiddleware([
        'auth' => App\Http\Middleware\Authenticate::class,
    ]);
  4. Register configuration files

    10.x

    To load configuration files into the application, use the $app->configure() method. This will look for the specified file in your config directory. If the file does not exist, it will load the default version.

    $app->configure('app');
  5. Enable Facades and Eloquent ORM

    10.x

    By default, Facades and Eloquent are disabled in Lumen to maintain high performance. To use them, call the corresponding methods on the $app instance in bootstrap/app.php.

    $app->withFacades();
    
    $app->withEloquent();
  6. Initialize the Lumen Application instance

    10.x

    The core of a Lumen application is the Laravel\\Lumen\\\Application instance. It acts as both the IoC container and the router. You can instantiate it by passing the base directory of your project as the first argument.

    $app = new Laravel\Lumen\Application(
        dirname(__DIR__)
    );