Composer安裝及更新YII2框架遇到問題梳理

我們在使用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 `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.

更新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插件問題並且更新對應的版本,之後順利更新依賴包及主框架版本。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章