此方法只现于无法正常运行执行composer update 或是composer require命令的情况下。
总有那么几个奇怪的主机无法远行composer,要么内存不够,要么其它的错误
本文以 auth2-client 为例
先在根目录下执行:
composer require league/oauth2-client --no-update
先安装获取到内容,但是不更新整个M2系统,因为我们要手动来完成它。
github上查找到此扩展内容位于链接:
https://github.com/thephpleague/oauth2-client
打包下载它,依据其composer.json内容
{
"name": "league/oauth2-client",
"description": "OAuth 2.0 Client Library",
"license": "MIT",
"config": {
"sort-packages": true
},
"require": {
"php": "^5.6 || ^7.0 || ^8.0",
"guzzlehttp/guzzle": "^6.0 || ^7.0",
"paragonie/random_compat": "^1 || ^2 || ^9.99"
},
"require-dev": {
"mockery/mockery": "^1.3.5",
"php-parallel-lint/php-parallel-lint": "^1.3.1",
"phpunit/phpunit": "^5.7 || ^6.0 || ^9.5",
"squizlabs/php_codesniffer": "^2.3 || ^3.0"
},
"keywords": [
"oauth",
"oauth2",
"authorization",
"authentication",
"idp",
"identity",
"sso",
"single sign on"
],
"authors": [
{
"name": "Alex Bilbie",
"email": "hello@alexbilbie.com",
"homepage": "http://www.alexbilbie.com",
"role": "Developer"
},
{
"name": "Woody Gilk",
"homepage": "https://github.com/shadowhand",
"role": "Contributor"
}
],
"autoload": {
"psr-4": {
"League\\OAuth2\\Client\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"League\\OAuth2\\Client\\Test\\": "test/src/"
}
},
"extra": {
"branch-alias": {
"dev-2.x": "2.0.x-dev"
}
}
}
,解压到目录
vendor\league\oauth2-client下
得到上图所示内容。
这样子只是把对应的包下载并解压到了vendor目录下,还未同M2程序相关联,所有的插件也无法直接引用它。还需要做以下操作
继续查看此扩展的composer.json文件装载到psr-4的目录路径一目了然。
"autoload": {
"psr-4": {
"League\\OAuth2\\Client\\": "src/"
}
},
打开
vendor\composer\autoload_psr4.php
默认内容如下
$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( .... .... )
需要修改为:
$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( .... 'League\\OAuth2\\Client\\' => array($vendorDir . '/league/oauth2-client/src'), .... )
增加了一行内容
'League\\OAuth2\\Client\\' => array($vendorDir . '/league/oauth2-client/src'),