Yii2: message/extract (except option does not filter files with slash)

Created on 18 Jul 2016  ·  3Comments  ·  Source: yiisoft/yii2

What steps will reproduce the problem?

Using autogenerated config file (yii message/config)

Except array from here
https://github.com/yiisoft/yii2/blob/6728d5d0e094fb85a1707dc581ec1dd7ad305df2/framework/console/controllers/MessageController.php#L98

Remove vendor dir from exception list

What is the expected result?

Exception of /BaseYii.php from processing

What do you get instead?

Extracting messages from excepted files.

yii message/extract "@app/config/i18n.php" | grep BaseYii
Extracting messages from /home/www/vendor/yiisoft/yii2/BaseYii.php...

Additional info

| Q | A |
| --- | --- |
| Yii version | 2.0.7 |
| PHP version | 5.6.23 |
| Operating system | Debian 8 |

my @app/config/i18n.php file

<?php
// yii message/extract "@app/config/i18n.php"
/**
 * Configuration file for 'yii message/extract' command.
 *
 * This file is automatically generated by 'yii message/config' command.
 * It contains parameters for source code messages extraction.
 * You may modify this file to suit your needs.
 *
 * You can use 'yii message/config-template' command to create
 * template configuration file with detaild description for each parameter.
 */
return [
    'color' => null,
    'interactive' => true,
    'sourcePath' => '@app/../',
    'messagePath' => '@app/../common/messages',
    'languages' => ['ru'],
    'translator' => 'Yii::t',
    'sort' => false, //false - новые вверху, true - новые и старые строки будут вперемешку
    'overwrite' => false, //false - создаст файл "ru/app.php.merge" вместо перезаписи оригинала "ru/app.php"
    'removeUnused' => false,
    'markUnused' => false, //true - помечает неиспользуемые строки @@строка@@
    'except' => [
        '.svn',
        '.git',
        '.gitignore',
        '.gitkeep',
        '.hgignore',
        '.hgkeep',
        '/messages',
//     '/vendor', //commented for tests
        '/BaseYii.php', //<-- work only if 'BaseYii.php' not '/BaseYii.php'
        'CountyHelper.php', //<--- does not work if '/CountyHelper.php'
    ],
    'only' => [
        '*.php',
    ],
    'format' => 'php',
    'db' => 'db',
    'sourceMessageTable' => '{{%source_message}}',
    'messageTable' => '{{%message}}',
    'catalog' => 'messages',
    'ignoreCategories' => [],
];
to be verified bug

Most helpful comment

Because / means root dir and not subdirs?

All 3 comments

Problem affects only recursive file finding (files inside subdirs)

use yii;
use yii\helpers\FileHelper

$options = [
    'recursive' => true,
];

$dirPath = realpath(Yii::getAlias('@app/config')); // /console/config/ (no subdirs inside)

$files = FileHelper::findFiles($dirPath, $options);
echo 'options (no except): '.count($files)."\n";

$options_2 = array_merge($options, ['except' => ['/params.php']]);
$files = FileHelper::findFiles($dirPath, $options_2);
echo 'options_2 (except "/params.php"): '.count($files)."\n";

$options_3 = array_merge($options, ['except' => ['params.php']]);
$files = FileHelper::findFiles($dirPath, $options_3);
echo 'options_3 (except "params.php"): '.count($files)."\n";

output

options (no except): 7
options_2 (except "/params.php"): 6 <--- 1 file excluded. all ok.
options_3 (except "params.php"): 6

now same test with subdirs

use yii;
use yii\helpers\FileHelper

$options = [
    'recursive' => true,
];

$dirPath = realpath(Yii::getAlias('@app/')); // /console/* (subdirs with files)

$files = FileHelper::findFiles($dirPath, $options);
echo 'options (no except): '.count($files)."\n";

$options_2 = array_merge($options, ['except' => ['/params.php']]);
$files = FileHelper::findFiles($dirPath, $options_2);
echo 'options_2 (except "/params.php"): '.count($files)."\n";

$options_3 = array_merge($options, ['except' => ['params.php']]);
$files = FileHelper::findFiles($dirPath, $options_3);
echo 'options_3 (except "params.php"): '.count($files)."\n";

output

options (no except): 78
options_2 (except "/params.php"): 78 <--- 0 file excluded. error.
options_3 (except "params.php"): 77 <--- 1 file excluded

Because / means root dir and not subdirs?

Yes, you are right. Thanks.
Problem solved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AstRonin picture AstRonin  ·  3Comments

newscloud picture newscloud  ·  3Comments

indicalabs picture indicalabs  ·  3Comments

chaintng picture chaintng  ·  3Comments

jpodpro picture jpodpro  ·  3Comments