yii2-gii: Wrong capitals for class/files when table is uppercase

What steps will reproduce the problem?

yiisoft/yii2-gii uses BaseInflector::id2camel() to generate class names but, when getting upper case table names from db like MY_TABLE, id2camel() does not work properly.

If it is ok, I could do a PR removing id2camel() and doing an inline conversion inside Generator::generateClassNames().

What is the expected result?

'MY_TABLE' --> MyTable

What do you get instead?

'MY_TABLE' --> MYTABLE

Additional info

Q A
Yii version 2.0.15.1
PHP version 7.1.17
Operating system Win10

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 23 (21 by maintainers)

Commits related to this issue

Most upvoted comments

Yeah, I am on it. I would already do but i had no time this weekend. I’ll do this week. 👍

Just tested here breaking it in parts:

$data = [
            'MY_TABLE' => 'MyTable',
            'MyTable' => 'MyTable',
            'my_table' => 'MyTable',
            'myTable' => 'MyTable',
        ];

        // strtr(ucwords(implode(' ', explode('_', strtolower(strtr(Inflector::camel2words($schemaName.$className), [' ' => '_']))))), [' ' => '']);
        function genNames($input) {
            $cc = Inflector::camel2words($input);
            $cca = strtr($cc, [' '=>'_']);
            $ccal = strtolower($cca);
            $ccala = explode('_', $ccal);
            $ccalai = implode(' ', $ccala);
            $ccalaiw = ucwords($ccalai);
            $final = strtr($ccalaiw, [' '=>'']);
            return $final;
        }

        $result = '';
        foreach ($data as $orig => $expected) {
            $finalName = genNames($orig);
            $result .= $orig . ' would be changed to ' . $finalName . '<hr>';
        }

        return $result;

Result:

MY_TABLE would be changed to MyTable
MyTable would be changed to MyTable
my_table would be changed to MyTable
myTable would be changed to MyTable