首先使用Composer包工具的需要满足以下两个前提,不区分操作系统。
1 电脑需要安装Composer包管理工具,并且全局可直接使用
2 安装Composer Asset插件,Asset插件需要合适的版本。
两个条件在安装的同时,都必须注意合适的版本。以下附上Mac安装composer和插件的主要步骤
curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading…
Composer (version 1.8.0) successfully installed to: /Users/wangmingming/composer.phar
Use it: php composer.phar
将composer 设置为全局可用
mv composer.phar /usr/local/bin/composer
安装Composer Asset插件
安装完Composer,运行下面的命令来安装Composer Asset插件
This command installs the composer asset plugin which allows managing bower and npm package dependencies through Composer.
查阅网络很多资料, Asset插件相关的问题主要集中在【安装Composer Asset插件老是失败】,解决方案都是给出执行具体的命令,安装这个插件的关键在于 确定当时fxp/composer-asset-plugin组件的最新版本,然后再安装。
https://packagist.org/packages/fxp/composer-asset-plugin
执行如下命令安装
composer global require “fxp/composer-asset-plugin:~1.4.4”
Changed current directory to /Users/path/.composer.
/composer.json has been updatedLoading composer repositories with package information
Updating dependencies (including require-dev)Package operations: 0 installs, 1 update, 0 removals - Updating fxp/composer-asset-plugin (v1.2.2 => v1.4.4): Loading from cache
Writing lock fileGenerating autoload files
服务器部署YII2 2.0.6,采用PHP7.2 报错
For compatibiliy with PHP 7.2 which does not allow classes to be named Object
anymore, we needed to rename yii\base\Object
to yii\base\BaseObject
. yii\base\Object
still exists for backwards compatibility and will be loaded if needed in projects that are running on PHP <7.2. The compatibility class yii\base\Object
extends from yii\base\BaseObject
so if you have classes that extend from yii\base\Object
these would still work. What does not work however will be code that relies on instanceof
checks or is_subclass_of()
calls for yii\base\Object
on framework classes as these do not extend yii\base\Object
anymore but only extend from yii\base\BaseObject
. In general such a check is not needed as there is a yii\base\Configurable
interface you should check against instead.
3. 更新YII2 框架至2.0.14 遇到问题
Problem 1 - yiisoft/yii2 2.0.15.1 requires bower-asset/inputmask ~3.2.2 | ~3.3.5 -> no matching package found. - yiisoft/yii2 2.0.15 requires bower-asset/inputmask ~3.2.2 | ~3.3.5 -> no matching package found. - yiisoft/yii2 2.0.14.2 requires bower-asset/inputmask ~3.2.2 | ~3.3.5 -> no matching package found. - yiisoft/yii2 2.0.14.1 requires bower-asset/inputmask ~3.2.2 | ~3.3.5 -> no matching package found. - yiisoft/yii2 2.0.14 requires bower-asset/inputmask ~3.2.2 | ~3.3.5 -> no matching package found. - Installation request for yiisoft/yii2 ~2.0.14 -> satisfiable by yiisoft/yii2[2.0.14, 2.0.14.1, 2.0.14.2, 2.0.15, 2.0.15.1].
New personal access token
简单理解为设置程序远程更新包时的访问token,在github处于登录状态时,生成token,就可以畅通的下载 形如https://api.github.com/repos/ 这样的包文件了。
以上解决问题的路径是这样的,发现目前的YII2版本不支持PHP7及以上环境,于是使用Composer更新YII2框架版本,更新过程中一系列问题造成更新识别,依次定位到Asset插件问题并且更新对应的版本,之后顺利更新依赖包及主框架版本。