yangze/lamen

在Laravel框架中使用Lumen,支持php-fpm和swoole模型。

v5.5.5 2019-03-06 08:53 UTC

This package is auto-updated.

Last update: 2024-09-06 23:46:41 UTC


README

在Laravel框架中支持Lumen的运行,运行模式包含php-fpm和swoole两种模式。

Lumen可以使用Laravel框架大部分代码,包括配置,路由,控制器,模型,集合,缓存,队列,事件。

目前代码仅在laravel5.5中测试 基于swooletw/laravel-swoole仓库修改 注意事项较多,有问题请留言

快速入门

务必注意Lumen的bug,查看本页Lumen bug说明

1、安装包

composer require yangze/lamen --prefer-dist

2、修改config/app.php,添加provider引用

Lamen\Http\LaravelServiceProvider::class

3、发布配置文件

php artisan vendor:publish --tag=lamen-swoole

4、修改config/lamen.php文件(重要,影响程序运行

变量说明

5、运行 以Laravel模型运行

php artisan lamen:http start

以Lumen模式运行

php artisan_lumen lamen:http start

以nginx+php-fpm模式运行

注意修改public/lamen.php文件,将其设置为入口文件。有两种方法,二选一:

  • nginx 配置文件中 index 设置为lamen.php
  • 将public/lamen.php移动为public/index.php

配置文件说明

运行方式

备注说明

已知问题

1、路由正则配置模式有差别,在针对Lumen的路由中不要出现Laravel路由相应的写法,否则会提示route找不到或者为空的情况

2、Laravel中获取路由参数和Lumen中获取路由参数不一样,需要写兼容方法调用 在Lumen的collection或者middleware中使用request()->get(),request()->all(),

需要修改成

$route=$request->route();
$route[2]['url参数'];

在POST中可以使用request()->input

3、Lumen bug

Type error: Too few arguments to function Illuminate\Cache\Console\ClearCommand::__construct(), 1 passed in vendor/laravel/lumen-framework/src/Console/ConsoleServiceProvider.php on line 113 and exactly 2 expected

修改文件: vendor/laravel/lumen-framework/src/Console/ConsoleServiceProvider.php,将代码

    protected function registerCacheClearCommand()
    {
        $this->app->singleton('command.cache.clear', function ($app) {
            return new CacheClearCommand($app['cache']);
        });
    }

修改为:

    protected function registerCacheClearCommand()
    {
        $this->app->singleton('command.cache.clear', function ($app) {
            return new CacheClearCommand($app['cache'], $app['files']);
        });
    }