ランサーズ(Lancers)エンジニアブログ > PHP > CakePHP > CakePHP 3 のマイナーバージョンを調べる方法あれこれ

CakePHP 3 のマイナーバージョンを調べる方法あれこれ

nakajiman|2017年07月12日
CakePHP

田園都市線のあざみ野駅、つくし野駅、つきみ野駅が、ときどき分からなくなる nakajiman です。

知らない誰かの CakePHP 3 環境を覗くとき、マイナーバージョンってどうやって調べてますか~ってはなしです。

VERSION.txt を見る

$ cat vendor/cakephp/cakephp/VERSION.txt
////////////////////////////////////////////////////////////////////////////////////////////////////
// +--------------------------------------------------------------------------------------------+ //
// CakePHP Version
//
// Holds a static string representing the current version of CakePHP
//
// CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
// Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
//
// Licensed under The MIT License
// Redistributions of files must retain the above copyright notice.
//
// @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
// @link          https://cakephp.org
// @since         CakePHP(tm) v 0.2.9
// @license       https://opensource.org/licenses/mit-license.php MIT License
// +--------------------------------------------------------------------------------------------+ //
////////////////////////////////////////////////////////////////////////////////////////////////////
3.4.9

Configure::version() を使う

ページで表示するなら

<?= Configure::version ?>

CakePHP Console なら

$ bin/cake console
>>> use Cake\Core\Configure;
>>> Configure::version();
=> "3.4.9"

Configure::version って、どう実装されてるのかなぁって見てみると、VERSION.txt を読み込んでいるだけでした。いぇい。

    /**
     * Used to determine the current version of CakePHP.
     *
     * Usage
     * ```
     * Configure::version();
     * ```
     *
     * @return string Current version of CakePHP
     */
    public static function version()
    {
        if (!isset(static::$_values['Cake']['version'])) {
            $config = require CORE_PATH . 'config/config.php';
            static::write($config);
        }

        return static::$_values['Cake']['version'];
    }
/**
 * Core Configurations.
 *
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 * @link          https://cakephp.org CakePHP(tm) Project
 * @since         1.1.11
 * @license       https://opensource.org/licenses/mit-license.php MIT License
 */
$versionFile = file(CORE_PATH . 'VERSION.txt');
return [
    'Cake.version' => trim(array_pop($versionFile))
];

Cake –version を指定する

試しにオプションを指定したら、表示されました。

$ bin/cake --version
3.4.9

その他

これ以外にマイナーバージョンを知る方法をご存じでしたら、ぜひ教えてください。ソースコードのこの部分が○○って書き方してるから、これは 3.3 だねとか、CakePHP 3 愛にあふれた変態級な方法が知りたいです。

追記

もう社内の CakePHP は 3.4.10 で、3.4.9 じゃないですって激しく怒られたので、名誉のための補足です。社内の CakePHP 3 ベースのプロダクトは 3.4.10 です。しかも 3.4.10 は昨日リリースされたばかりのものです。キリッ!

今夏、田園都市線で、時差Bizライナーっていう臨時特急があって、長津田駅から渋谷駅まで 30分かからないらしいす。乗りたいけど早起きできないのよね。