为lumen添加session支持,同时配置全局函数csrf_token可用

首先laravel和lumen框架的版本要一致,我这里版本都是5.4

1.复制laravel框架config目录下的session.php到lumen框架config目录下

2.修改bootstrap目录下的app.php

添加

//加载配置

$app->configure('session');

//注册中间件

$app->middleware([
    Illuminate\Session\Middleware\StartSession::class,
    App\Http\Middleware\VerifyCsrfToken::class,
]);

//注册服务提供者

$app->register(Illuminate\Session\SessionServiceProvider::class);

//添加全局函数csrf_token

3.修改\vendor\laravel\lumen-framework\src\helpers.php

添加(该函数从拷贝自laravel框架下\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php)
if (! function_exists('csrf_token')) {
/**
* Get the CSRF token value.
*
* @return string
*
* @throws \RuntimeException
*/
function csrf_token()
{
    $session = app('session');

if (isset($session)) {
        return $session->token();
    }

throw new RuntimeException('Application session store not set.');
    }
}

4.添加文件\app\Http\Middleware\VerifyCsrfToken.php拷贝自laravel
\app\Http\Middleware\VerifyCsrfToken.php

5.添加文件\vendor\illuminate\http\Middleware\VerifyCsrfToken.php拷贝自
laravel框架\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php
该文件拷贝过去后需要修改命名空间,因为lumen下命名空间变化了

6.修改\vendor\laravel\lumen-framework\src\Application.php
在方法
registerContainerAliases中添加
'Illuminate\Session\SessionManager'=>'session',别名

为lumen添加session支持的更多相关文章

  1. Spring Boot 添加Shiro支持

    前言: Shiro是一个权限.会话管理的开源Java安全框架:Spring Boot集成Shiro后可以方便的使用Session: 工程概述: (工程结构图) 一.建立Spring Boot工程 参照 ...

  2. 手动添加SSH支持、使用c3p0

    之前做的笔记,现在整理一下:大家有耐心的跟着做就能成功: SSH(struts2.spring.hibernate) *  struts2      *  充当mvc的角色 *  hibernate ...

  3. 【 Linux 】为lnmp架构添加memcached支持

    一.首先搭建lnmp平台,这里不再演示.通过php页面来进行测试如下: [root@node1 ~]# vim /usr/local/nginx/html/info.php <?php $lin ...

  4. 把自己Github上的代码添加Cocoapods支持

    转载请注明原链接:http://www.cnblogs.com/zhanggui/p/6003481.html 一.前言 这两天被cocoapods折磨的心力憔悴.看cocoapods官网的添加支持, ...

  5. 在IntelliJ IDEA中添加框架支持时找不到Hibernate的解决办法

    问题描述 第一次在Add Frameworks support界面中添加hibernate支持的时候,异常中断,导致没有成功添加. 第二次进入Add Frameworks support窗口时,发现找 ...

  6. 别再为了iOS新系统设备而重新安装一个新版Xcode了.其实我们可以添加版本支持

    众所周知,Xcode7.3的代码补全是有问题的  如导入自定义类之后,在代码中并不会补全相应的类名... 但Xcode7.2是没有这个问题的,但很多时候我们自己的设备都升级到了iOS9.3.X系统,导 ...

  7. 将自己库添加Cocoapods支持

    给库添加Cocoapods支持, 使这个工具使用起来更加方便, 更好的使用Cocoapods, 助力iOS程序开发, 下面进入正题, 想要实现这个过程, 绝对不虚此读. 首先写好一个要添加Cocoap ...

  8. net-snmp源码VS2013编译添加加密支持(OpenSSL)

    net-snmp源码VS2013编译添加加密支持(OpenSSL) snmp v3 协议使用了基于用户的安全模型,具有认证和加密两个模块. 认证使用的算法是一般的消息摘要算法,例如MD5/SHA等.这 ...

  9. net-snmp源码VS2013编译添加加密支持(OpenSSL)(在VS里配置编译OpenSSL)

    net-snmp源码VS2013编译添加加密支持(OpenSSL) snmp v3 协议使用了基于用户的安全模型,具有认证和加密两个模块. 认证使用的算法是一般的消息摘要算法,例如MD5/SHA等.这 ...

随机推荐

  1. ubuntu 完全干净的卸载docker

    1. 删除某软件,及其安装时自动安装的所有包 sudo apt-get autoremove docker docker-ce docker-engine docker.io containerd r ...

  2. 【高维前缀和】8.15B. 组合数

    题目分析 没有接触过高维前缀和的话会有一点抽象

  3. 前端css知识实现自动打字,文字滚动

    HTML部分: <div class="div1"> <div class="div2">文字文字文字文字文字文字文字文字文字文字文字文 ...

  4. Nginx的TCP/UDP调度器

    安装nginx [root@proxy ~]# yum –y install gcc pcre-devel openssl-devel //安装依赖包 [root@proxy ~]# .tar.gz ...

  5. Python 练习实例1

    Python 练习实例1 题目:有四个数字:1.2.3.4,能组成多少个互不相https://www.xuanhe.net/同且无重复数字的三位数?各是多少? 程序分析:可填在百位.十位.个位的数字都 ...

  6. 010_linuxC++之_运算符重载

    (一)运算符重载:运算符重载,就是对已有的运算符重新进行定义,赋予其另一种功能,以适应不同的数据类型. (二)实现类不同对象里中变量的相加 (三)程序 #include <iostream> ...

  7. [Luogu] 时间复杂度

    https://www.luogu.org/problemnew/show/P3952 考场上输出的是 "YES" "NO" ++ ,如果不是亲身经历,打死我我 ...

  8. django-配置相关

    1 自己配置一个静态文件夹 settings.py中 # 用户上传的文件配置 MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'me ...

  9. Dean and Schedule (URAL 2026)

    Problem A new academic year approaches, and the dean must make a schedule of classes for first-year ...

  10. mysql被收购 用mariadb

    ~]# systemctl start mysql.service 要启动MySQL数据库是却是这样的提示 Failed to start mysqld.service: Unit not found ...