Composer安装及更新YII2框架遇到问题梳理

2019-07-04 10:55:00 浏览数 (1)

我们在使用YII2框架的过程中,对于框架有两种安装方式,一种是使用官网归档文件,一种是使用Compoer包管理工具。本文讨论的问题集中在使用Compoer安装YII2框架及更新组件包,升级YII2主版本时遇到的一些问题。

前置条件

首先使用Composer包工具的需要满足以下两个前提,不区分操作系统。

1 电脑需要安装Composer包管理工具,并且全局可直接使用

2 安装Composer Asset插件,Asset插件需要合适的版本。

两个条件在安装的同时,都必须注意合适的版本。以下附上Mac安装composer和插件的主要步骤

Mac系统安装compoer

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组件的最新版本,然后再安装。

查看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](https://wiki.php.net/rfc/object-typehint), we needed to rename `yiibaseObject` to `yiibaseBaseObject`. `yiibaseObject` still exists for backwards compatibility and will be loaded if needed in projects that are running on PHP <7.2. The compatibility class `yiibaseObject` extends from `yiibaseBaseObject` so if you have classes that extend from `yiibaseObject` these would still work. What does not work however will be code that relies on `instanceof` checks or `is_subclass_of()` calls for `yiibaseObject` on framework classes as these do not extend `yiibaseObject` anymore but only extend from `yiibaseBaseObject`. In general such a check is not needed as there is a `yiibaseConfigurable` interface you should check against instead.

更新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插件问题并且更新对应的版本,之后顺利更新依赖包及主框架版本。

0 人点赞