需求背景:以前的tp5.0项目中没有使用过composer,现在要装一个 firebase/php-jwt
1、获取一个composer.json文件
require里面就是需要安装的插件
{"name": "topthink/think","description": "the new thinkphp framework","type": "project","keywords": ["framework","thinkphp","ORM"],"homepage": "http://thinkphp.cn/","license": "Apache-2.0","authors": [{"name": "liu21st","email": "liu21st@gmail.com"}],"require": {"php": ">=5.4.0","topthink/framework": "^5.0","paragonie/sodium_compat": "^1.17","firebase/php-jwt": "^6.0"},"extra": {"think-path": "thinkphp"},"config": {"preferred-install": "dist"}}
2、执行命令安装json中的所有插件内容
新建test文件夹把composer.json文件放进去
打开shell窗口执行 composer install
安装完成
3、安装好以后把需要的插件考入到自己项目的vendor文件夹中
插件目录tests1/vendor/firebase (我这里只需要这个)
4、直接复制过去是不能使用的需要修改vendor/composer/autoload_psr4.php
test1中的autoload_psr4.php文件内容是这样的:
<?php// autoload_psr4.php @generated by Composer$vendorDir = dirname(dirname(__FILE__));$baseDir = dirname($vendorDir);return array('think\\composer\\' => array($vendorDir . '/topthink/think-installer/src'),'Firebase\\JWT\\' => array($vendorDir . '/firebase/php-jwt/src'),);
需要把这一句复制到自己项目的autoload_psr4.php文件中
'Firebase\\JWT\\' => array($vendorDir . '/firebase/php-jwt/src'),
5、项目中去试试引入,如果可以用IDE追踪到就证明可以了
use Firebase\JWT\JWT;use Firebase\JWT\Key;
注:现在只试试了tp5.0, 接手的别人的项目尽量小的改动,其它的以后再说!!

