Yii Framework – 永夜 https://www.shuijingwanwq.com 没有不值得去解决的问题,也没有不值得去学习的技术! Thu, 20 Feb 2020 05:36:14 +0000 zh-Hans hourly 1 https://wordpress.org/?v=7.0 在 Yii 2.0 中,唯一性验证失败时,提示不够友好,自动调整优化的分析 https://www.shuijingwanwq.com/2020/02/20/3949/ https://www.shuijingwanwq.com/2020/02/20/3949/#respond Thu, 20 Feb 2020 05:36:14 +0000 https://www.shuijingwanwq.com/?p=3949 浏览量: 109 1、测试人员提交了一个 Bug,认为唯一性验证失败时,提示不够友好(中英文混杂,用户不易理解),提示信息如图1
测试人员提交了一个 Bug,认为唯一性验证失败时,提示不够友好(中英文混杂,用户不易理解)

图1

2、在本地环境的最新版本中,准备复现时,意外发现提示信息已经全部显示为中文,提示信息如图2
在本地环境的最新版本中,准备复现时,意外发现提示信息已经全部显示为中文

图2



{
    "code": 226004,
    "message": "数据验证失败:租户ID, 栏目名称, 是否被删除 与 删除时间 的值 \"\"015ce30b116ce86058fa6ab4fea4ac63\"-\"深圳市9\"-\"0\"-\"0\"\" 已经被占用了。"
}


3、查看相应程序文件,并未针对提示信息做相应调整,查看 Git 日志,提交:通过运行 composer update 来更新 Yii 2 至最新版本,已将 Yii Framework 从 2.0.15.1 版本升级到 2.0.31。初步怀疑是由于 Yii 框架版本的升级,进而调整了提示信息。如图3
查看相应程序文件,并未针对提示信息做相应调整,查看 Git 日志,提交:通过运行 composer update 来更新 Yii 2 至最新版本,已将 Yii Framework 从 2.0.15.1 版本升级到 2.0.31。初步怀疑是由于 Yii 框架版本的升级,进而调整了提示信息。

图3

4、部署标签:1.10.4-alpha.5,为升级前的版本,Bug 已复现,如图4
部署标签:1.10.4-alpha.5,为升级前的版本,Bug 已复现

图4



{
    "code": 226004,
    "message": "数据验证失败:The combination \"015ce30b116ce86058fa6ab4fea4ac63\"-\"深圳市1\"-\"0\"-\"0\" of 租户ID, 栏目名称, 是否被删除 and 删除时间 has already been taken."
}


5、部署标签:1.10.4-alpha.6,为升级后的版本,Bug 已修复,英文已经消失,提示信息更友好,如图5
部署标签:1.10.4-alpha.6,为升级后的版本,Bug 已修复,英文已经消失,提示信息更友好

图5



{
    "code": 226004,
    "message": "数据验证失败:租户ID, 栏目名称, 是否被删除 与 删除时间 的值 \"\"015ce30b116ce86058fa6ab4fea4ac63\"-\"深圳市1\"-\"0\"-\"0\"\" 已经被占用了。"
}


6、由此得出结论,唯一性验证失败时,提示更友好的缘故在于,已将 Yii Framework 从 2.0.15.1 版本升级到 2.0.31。究竟是期间的哪个版本导致的,查看 /vendor/yiisoft/yii2/messages/zh-CN/yii.php 的 Github 日志。参考网址:https://github.com/yiisoft/yii2/commit/b8a3fa4ff96cb80d77fcf8003163c9001770ae8b#diff-9083c63f8544587712f4083785a317cf ,在提交:b8a3fa 中,新增加了一行。提交于 2018年4月5日,如图6
由此得出结论,唯一性验证失败时,提示更友好的缘故在于,已将 Yii Framework 从 2.0.15.1 版本升级到 2.0.31。究竟是期间的哪个版本导致的,查看 /vendor/yiisoft/yii2/messages/zh-CN/yii.php 的 Github 日志。参考网址:https://github.com/yiisoft/yii2/commit/b8a3fa4ff96cb80d77fcf8003163c9001770ae8b#diff-9083c63f8544587712f4083785a317cf ,在提交:b8a3fa 中,新增加了一行。提交于 2018年4月5日

图6



    'The combination {values} of {attributes} has already been taken.' => '{attributes} 的值 "{values}" 已经被占用了。',


7、参考网址:https://github.com/yiisoft/yii2/tree/2.0.16/framework/messages/zh-CN ,提交:b8a3fa 存在于 Tag:2.0.16 中。因此,可以确定 Yii Framework 的 2.0.16 版本,已经优化了相应提示信息。如图7
参考网址:https://github.com/yiisoft/yii2/tree/2.0.16/framework/messages/zh-CN ,提交:b8a3fa 存在于 Tag:2.0.16 中。因此,可以确定 Yii Framework 的 2.0.16 版本,已经优化了相应提示信息。

图7

]]>
https://www.shuijingwanwq.com/2020/02/20/3949/feed/ 0
基于 Composer 更新 Yii 2 至最新版本后,软件包:guzzlehttp guzzle 的丢失的分析 https://www.shuijingwanwq.com/2020/01/21/3894/ https://www.shuijingwanwq.com/2020/01/21/3894/#respond Tue, 21 Jan 2020 03:18:22 +0000 https://www.shuijingwanwq.com/?p=3894 浏览量: 136 1、参考网址:https://www.shuijingwanwq.com/2020/01/19/3869/ ,将 Yii Framework 从 2.0.15.1 版本升级到 2.0.31 2、在一些使用了:\GuzzleHttp\json_encode、\GuzzleHttp\json_decode 的程序中报错,最终分析发现,原因在于,目录:/vendor/guzzlehttp/guzzle、/vendor/guzzlehttp/promises 已经不存在。如图1
在一些使用了:\GuzzleHttp\json_encode、\GuzzleHttp\json_decode 的程序中报错,最终分析发现,原因在于,目录:/vendor/guzzlehttp/guzzle、/vendor/guzzlehttp/promises 已经不存在

图1

3、仔细分析后,发现参考网址中的第 2 个步骤,运行 composer update 时,卸载了:guzzlehttp/promises、guzzlehttp/guzzle,如图2
仔细分析后,发现参考网址中的第 2 个步骤,运行 composer update 时,卸载了:guzzlehttp/promises、guzzlehttp/guzzle

图2

4、步骤 2 的问题,最终通过 Yii 帮助类 Json: https://www.yiiframework.com/doc/api/2.0/yii-helpers-json 得以解决,执行相应的替换操作


\GuzzleHttp\json_decode
\yii\helpers\Json::decode

\GuzzleHttp\json_encode
\yii\helpers\Json::encode


5、在一个 Yii 2 版本仍然为:2.0.15.1 的分支中,使用 依赖性检测 depends 命令可以查出已安装在你项目中的某个包,是否正在被其它的包所依赖,并列出他们。得出结论:guzzlehttp/promises 依赖于 guzzlehttp/guzzle,guzzlehttp/guzzle 依赖于 codeception/base,codeception/base 依赖于 yiisoft/yii2-app-advanced。如图3
在一个 Yii 2 版本仍然为:2.0.15.1 的分支中,使用 依赖性检测 depends 命令可以查出已安装在你项目中的某个包,是否正在被其它的包所依赖,并列出他们。得出结论:guzzlehttp/promises 依赖于 guzzlehttp/guzzle,guzzlehttp/guzzle 依赖于 codeception/base,codeception/base 依赖于 yiisoft/yii2-app-advanced

图3

<pre class="wp-block-syntaxhighlighter-code">

PS E:\wwwroot\pcs-api-feature-config-group-task-step> ./yii

This is Yii version 2.0.15.1.

The following commands are available:

- asset                        Allows you to combine and compress your JavaScript and CSS files.
    asset/compress (default)   Combines and compresses the asset files according to the given configuration.
    asset/template             Creates template of configuration file for [[actionCompress]].

- cache                        Allows you to flush cache.
    cache/flush                Flushes given cache components.
    cache/flush-all            Flushes all caches registered in the system.
    cache/flush-schema         Clears DB schema cache for a given connection component.
    cache/index (default)      Lists the caches that can be flushed.

- cmc-console-user             框架服务控制台的用户
    cmc-console-user/sync      同步框架服务控制台的用户模型(Http)至框架服务控制台的用户模型(R
                               edis)

- config-column-user           栏目人员配置
    config-column-user/sync    同步框架服务控制台的用户模型(Http)至栏目人员配置模型(MySQL)

- fixture                      Manages fixture data loading and unloading.
    fixture/load (default)     Loads the specified fixture data.
    fixture/unload             Unloads the specified fixtures.

- gii                          This is the command line version of Gii - a code generator.
    gii/controller             Controller Generator
    gii/crud                   CRUD Generator
    gii/extension              Extension Generator
    gii/form                   Form Generator
    gii/index (default)
    gii/model                  Model Generator
    gii/module                 Module Generator

- help                         Provides help information about console commands.
    help/index (default)       Displays available commands or the detailed information
    help/list                  List all available controllers and actions in machine readable format.
    help/list-action-options   List all available options for the $action in machine readable format.
    help/usage                 Displays usage information for $action.

- log                          日志
    log/delete                 日志的删除

- message                      Extracts messages to be translated from source files.
    message/config             Creates a configuration file for the "extract" command using command line options
                               specified.
    message/config-template    Creates a configuration file template for the "extract" command.
    message/extract (default)  Extracts messages to be translated from source code.

- migrate                      Manages application migrations.
    migrate/create             Creates a new migration.
    migrate/down               Downgrades the application by reverting old migrations.
    migrate/fresh              Truncates the whole database and starts the migration from the beginning.
    migrate/history            Displays the migration history.
    migrate/mark               Modifies the migration history to the specified version.
    migrate/new                Displays the un-applied new migrations.
    migrate/redo               Redoes the last few migrations.
    migrate/to                 Upgrades or downgrades till the specified version.
    migrate/up (default)       Upgrades the application by applying new migrations.

- plan-task                    选题任务
    plan-task/close            关闭选题任务

- serve                        Runs PHP built-in web server.
    serve/index (default)      Runs PHP built-in web server.


To see the help of each command, enter:

  yii help <command-name>

PS E:\wwwroot\pcs-api-feature-config-group-task-step> composer depends guzzlehttp/promises
guzzlehttp/guzzle  6.3.3  requires  guzzlehttp/promises (^1.0)
PS E:\wwwroot\pcs-api-feature-config-group-task-step> composer depends guzzlehttp/guzzle
codeception/base  2.5.2  requires  guzzlehttp/guzzle (>=4.1.4 <7.0)
PS E:\wwwroot\pcs-api-feature-config-group-task-step> composer depends codeception/base
shuijingwan/yii2-app-advanced  dev-feature-config-group-task-step  requires (for development)  codeception/base (^2.2.3)


</pre>
6、分别查看 codeception/base 的两个版本的 composer.json,Yii Framework 从 2.0.15.1 版本升级到 2.0.31,进而导致 codeception/base 从版本 2.5.2 升级到 2.5.6,而 codeception/base 的版本 2.5.6 已经放弃依赖 guzzlehttp/guzzle。观察可发现,codeception/base 的依赖类型为:require-dev,因此,其仅能够用于开发阶段,而不能够用于生产阶段。


    "require-dev": {
        "yiisoft/yii2-debug": "~2.0.0",
        "yiisoft/yii2-gii": "~2.0.0",
        "yiisoft/yii2-faker": "~2.0.0",
        "codeception/base": "^2.2.3",
        "codeception/verify": "~0.3.1"
    },


 ]]>
https://www.shuijingwanwq.com/2020/01/21/3894/feed/ 0
基于 Composer 更新 Yii 2 至最新版本,将 Yii Framework 从 2.0.15.1 版本升级到 2.0.31 https://www.shuijingwanwq.com/2020/01/19/3869/ https://www.shuijingwanwq.com/2020/01/19/3869/#comments Sun, 19 Jan 2020 02:26:51 +0000 https://www.shuijingwanwq.com/?p=3869 浏览量: 181 1、之前已安装 Composer,为确保使用最新版本。可以通过运行 composer self-update 来更新 Composer 至版本 1.9.2,如图1
之前已安装 Composer,为确保使用最新版本。可以通过运行 composer self-update 来更新 Composer 至版本 1.9.2

图1



PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer self-update
Updating to version 1.9.2 (stable channel).
   Downloading (100%)
Use composer self-update --rollback to return to version 1.8.3


2、通过运行 composer update 来更新 Yii 2 至最新版本,已将 Yii Framework 从 2.0.15.1 版本升级到 2.0.31,如图2
通过运行 composer update 来更新 Yii 2 至最新版本,已将 Yii Framework 从 2.0.15.1 版本升级到 2.0.31

图2



PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 7 installs, 42 updates, 5 removals
  - Removing symfony/process (v4.2.2)
  - Removing symfony/contracts (v1.0.2)
  - Removing guzzlehttp/promises (v1.3.1)
  - Removing guzzlehttp/guzzle (6.3.3)
  - Removing facebook/webdriver (1.6.0)
  - Updating yiisoft/yii2-composer (2.0.7 => 2.0.8): Loading from cache
  - Updating bower-asset/jquery (3.2.1 => 3.4.1): Loading from cache
  - Updating bower-asset/bootstrap (v3.4.0 => v3.4.1): Loading from cache
  - Updating ezyang/htmlpurifier (v4.10.0 => v4.12.0): Loading from cache
  - Updating cebe/markdown (1.1.2 => 1.2.1): Loading from cache
  - Updating yiisoft/yii2 (2.0.15.1 => 2.0.31): Loading from cache
  - Updating yiisoft/yii2-bootstrap (2.0.9 => 2.0.10): Loading from cache
  - Updating yii2tech/ar-softdelete (1.0.3 => 1.0.4): Downloading (100%)
  - Updating sebastian/exporter (3.1.0 => 3.1.2): Loading from cache
  - Updating sebastian/environment (4.0.2 => 4.2.3): Downloading (100%)
  - Updating sebastian/diff (3.0.1 => 3.0.2): Downloading (100%)
  - Updating phpunit/php-timer (2.0.0 => 2.1.2): Downloading (100%)
  - Updating theseer/tokenizer (1.1.0 => 1.1.3): Loading from cache
  - Updating phpunit/php-token-stream (3.0.1 => 3.1.1): Downloading (100%)
  - Updating symfony/polyfill-ctype (v1.10.0 => v1.13.1): Loading from cache
  - Updating webmozart/assert (1.4.0 => 1.6.0): Loading from cache
  - Updating phpdocumentor/reflection-common (1.0.1 => 2.0.0): Loading from cache
  - Updating phpdocumentor/type-resolver (0.4.0 => 1.0.1): Loading from cache
  - Updating phpdocumentor/reflection-docblock (4.3.0 => 4.3.4): Loading from cache
  - Updating doctrine/instantiator (1.1.0 => 1.3.0): Loading from cache
  - Updating phpspec/prophecy (1.8.0 => 1.10.1): Loading from cache
  - Updating myclabs/deep-copy (1.8.1 => 1.9.4): Loading from cache
  - Updating phpunit/phpunit (7.5.2 => 7.5.20): Downloading (100%)
  - Updating symfony/yaml (v4.2.2 => v4.4.2): Loading from cache
  - Updating codeception/phpunit-wrapper (7.6.1 => 7.8.0): Downloading (100%)
  - Updating codeception/stub (2.0.4 => 2.1.0): Downloading (100%)
  - Updating symfony/polyfill-mbstring (v1.10.0 => v1.13.1): Loading from cache
  - Updating symfony/dom-crawler (v4.2.2 => v4.4.2): Loading from cache
  - Updating symfony/css-selector (v4.2.2 => v4.4.2): Loading from cache
  - Updating symfony/browser-kit (v4.2.2 => v4.4.2): Downloading (100%)
  - Installing psr/container (1.0.0): Loading from cache
  - Installing symfony/event-dispatcher-contracts (v1.1.7): Loading from cache
  - Updating symfony/event-dispatcher (v4.2.2 => v4.4.2): Loading from cache
  - Installing symfony/service-contracts (v2.0.1): Downloading (100%)
  - Installing symfony/polyfill-php73 (v1.13.1): Loading from cache
  - Updating symfony/console (v4.2.2 => v4.4.2): Loading from cache
  - Updating symfony/finder (v4.2.2 => v4.4.2): Loading from cache
  - Updating ralouphie/getallheaders (2.0.5 => 3.0.3): Loading from cache
  - Updating guzzlehttp/psr7 (1.5.2 => 1.6.1): Loading from cache
  - Updating codeception/base (2.5.2 => 2.5.6): Downloading (100%)
  - Updating hprose/hprose (v2.0.37 => v2.0.39): Downloading (100%)
  - Updating yiisoft/yii2-httpclient (2.0.7 => 2.0.12): Downloading (100%)
  - Updating fzaninotto/faker (v1.8.0 => v1.9.1): Loading from cache
  - Installing symfony/polyfill-php72 (v1.13.1): Loading from cache
  - Installing symfony/polyfill-intl-idn (v1.13.1): Loading from cache
  - Installing symfony/polyfill-iconv (v1.13.1): Loading from cache
  - Updating doctrine/lexer (v1.0.1 => 1.2.0): Downloading (100%)
  - Updating egulias/email-validator (2.1.7 => 2.1.14): Loading from cache
  - Updating swiftmailer/swiftmailer (v6.1.3 => v6.2.3): Loading from cache
symfony/event-dispatcher-contracts suggests installing psr/event-dispatcher
symfony/service-contracts suggests installing symfony/service-implementation
Writing lock file
Generating autoload files

  Seems you have upgraded Yii Framework from version 2.0.15.1 to 2.0.31.

  Please check the upgrade notes for possible incompatible changes
  and adjust your application code accordingly.

  Upgrade from Yii 2.0.30
  -----------------------
  * `yii\helpers\BaseInflector::slug()` now ensures there is no repeating $replacement string occurrences.
    In case you rely on Yii 2.0.16 - 2.0.30 behavior, consider replacing `Inflector` with your own implementation.

  Upgrade from Yii 2.0.20
  -----------------------

  * `yii\db\Query::select()` and `addSelect()` now normalize the format that columns are stored in when saving them
    to `$this->select`, so code that works directly with that property may need to be modified.

    For the following code:

    ```php
    $a = $query->select('*');
    $b = $query->select('id, name');
    ```

    The value was stored as is i.e.

    ```php
    // a
    ['*']

    // b
    ['id', 'name']
    ```

    Now it is stored as

    ```php
    // a
    ['*' => '*']

    // b
    ['id' => 'id', 'name' => 'name']
    ```

  Upgrade from Yii 2.0.16
  -----------------------

  * In case you have extended the `yii\web\DbSession` class you should check if your
    custom implementation is compatible with the new `yii\web\DbSession::$fields` attribute.
    Especially when overriding the `yii\web\DbSession::writeSession($id, $data)` function.

  Upgrade from Yii 2.0.15
  -----------------------

  * Updated dependency to `cebe/markdown` to version `1.2.x`.
    If you need stick with 1.1.x, you can specify that in your `composer.json` by
    adding the following line in the `require` section:

    ```json
    "cebe/markdown": "~1.1.0",
    ```

  * `yii\mutex\Mutex::acquire()` no longer returns `true` if lock is already acquired by the same component in the same
process.
    Make sure that you're not trying to acquire the same lock multiple times in a way that may create infinite loops, fo
r example:

    ```php
    if (Yii::$app->mutex->acquire('test')) {
         while (!Yii::$app->mutex->acquire('test')) {
             // `Yii::$app->mutex->acquire('test')` will always return `false` here, since lock is already acquired
        }
    }
    ```

  * Formatter methods `asInteger`, `asDecimal`, `asPercent`, and `asCurrency` are using now inner fallback methods to ha
ndle
    very big number values to counter inner PHP casting and floating point number presentation issues. Make sure to prov
ide
    such values as string numbers.

  * Active Record relations are now being reset when corresponding key fields are changed. If you have relied on the fac
t
    that relations are never reloaded you have to adjust your code.

  You can find the upgrade notes for all versions online at:
  https://github.com/yiisoft/yii2/blob/2.0.31/framework/UPGRADE.md



3、在线查看 Yii Framework 2.0 升级说明:https://github.com/yiisoft/yii2/blob/2.0.31/framework/UPGRADE.md ,了解可能不兼容的更改,比如,扩展了某些类,而这些类的属性与方法在新版本中有所调整。如图3
在线查看 Yii Framework 2.0 升级说明:https://github.com/yiisoft/yii2/blob/2.0.31/framework/UPGRADE.md ,了解可能不兼容的更改,比如,扩展了某些类,而这些类的属性与方法在新版本中有所调整。

图3

 ]]>
https://www.shuijingwanwq.com/2020/01/19/3869/feed/ 1