Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2de47ab
For models generator enum fields values constant names and methods sy…
uldisn Jun 16, 2025
0059a5d
fixed
uldisn Jun 16, 2025
6322210
Code formatting and added debug info in test
uldisn Jun 21, 2025
e0b7bcc
Adde to enum constant generation spcial case for 'minus' (-)
uldisn Jun 21, 2025
5ea3ed8
Class constant array changed to property array
uldisn Jun 21, 2025
1fd8c53
Added exception for "-" and validation for duplicate enum value const…
uldisn Jun 23, 2025
3ca2fbd
fixed bug
uldisn Jun 23, 2025
5957916
fixed bug
uldisn Jun 23, 2025
c7b1a87
Refactored enum test to use centralized loop for constant and method …
uldisn Jul 11, 2025
22498d2
Fixed method existence checks in `ModelGeneratorTest` and corrected t…
uldisn Jul 11, 2025
45874c9
Refactored `ModelGeneratorTest` to update setter and checker method n…
uldisn Jul 11, 2025
cb4c5a8
Updated setter method names in `ModelGeneratorTest` for consistency b…
uldisn Jul 11, 2025
15098f6
Fixed typo in `ModelGeneratorTest`: corrected method name `assertTrru…
uldisn Jul 11, 2025
9b01122
Fixed typo in `ModelGeneratorTest`: corrected `isTypeMinusB` to `isTy…
uldisn Jul 11, 2025
ecef46f
Refactored `Generator` to introduce `EnumGenerator` for cleaner ENUM …
uldisn Jul 23, 2025
6170d24
Fixed bug #558: Resolved issue with generating rules for multiple fie…
uldisn Jul 23, 2025
9b9507c
Removed duplicate changelog entries for bug fixes #556 and #558.
uldisn Jul 23, 2025
78469ef
Added changelog entry for bug #558: Fixed issue with generating rules…
uldisn Jul 23, 2025
81febdd
Added missing newline in changelog after bug #558 entry.
uldisn Jul 23, 2025
b6c63c2
Updated `EnumGenerator` to accept `Generator` instance, refactored me…
uldisn Jul 23, 2025
e449482
Updated `EnumGenerator` to accept `Generator` instance, refactored me…
uldisn Jul 23, 2025
5d0fd23
Removed changelog entry for bug #556 as unnecessary.
uldisn Jul 23, 2025
886b5ca
Fixed duplicate constant name generation in `EnumGenerator` and updat…
uldisn Jul 23, 2025
96c2def
Refactored `EnumGenerator` to replace `createValueForName` with `crea…
uldisn Jul 23, 2025
ac27c75
Update CHANGELOG.md
uldisn Sep 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/generators/model/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,42 @@ class Generator extends \yii\gii\Generator
const JUNCTION_RELATION_VIA_TABLE = 'table';
const JUNCTION_RELATION_VIA_MODEL = 'model';

const SYMBOLS_ABBREVIATION = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const SYMBOLS_ABBREVIATION = [
const SYMBOLS_ABBREVIATION = [

'!' => 'exclamation',
'@' => 'at',
'#' => 'number',
'$' => 'dollar',
'%' => 'percent',
'^' => 'caret',
'&' => 'and',
'*' => 'asterisk',
'(' => 'open_parenthesis',
')' => 'close_parenthesis',
'-' => 'dash',
'_' => 'underscore',
'=' => 'equals',
'+' => 'plus',
'{' => 'open_curly_brace',
'}' => 'close_curly_brace',
'[' => 'open_square_bracket',
']' => 'close_square_bracket',
'|' => 'pipe',
'\\' => 'backslash',
'/' => 'forward_slash',
':' => 'colon',
';' => 'semicolon',
'"' => 'double_quote',
'\'' => 'single_quote',
'<' => 'less_than',
'>' => 'greater_than',
',' => 'comma',
'.' => 'dot',
'?' => 'question_mark',
'~' => 'tilde',
'`' => 'backtick'
];


public $db = 'db';
public $ns = 'app\models';
/**
Expand Down Expand Up @@ -1218,8 +1254,12 @@ public function getEnum($columns)
$enum[$column->name]['columnName'] = $column->name;
$enum[$column->name]['values'] = [];

foreach ($column->enumValues as $value) {
$abbreviations = array_map(function($item) {
return ' ' . $item . ' ';
}, self::SYMBOLS_ABBREVIATION);

foreach ($column->enumValues as $value) {
$value = strtr($value, $abbreviations);
$constantName = strtoupper(Inflector::slug($column->name . ' ' . $value, '_'));
$label = Inflector::camel2words($value);

Expand Down
8 changes: 7 additions & 1 deletion tests/generators/ModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,12 @@ public static function getTableSchema(){
$this->assertTrue($testEnumModel->isTypeConsignees());
$this->assertEquals(\TestEnumModel::TYPE_CONSIGNEES,$testEnumModel->displayType());

/** test enum value with symbols */
$testEnumModel->type = \TestEnumModel::TYPE_B_PLUS;
$this->assertTrue($testEnumModel->isTypeBPlus());
$this->assertFalse($testEnumModel->isTypeConsignees());


/** test validate */
$this->assertTrue($testEnumModel->validate());
$testEnumModel->type = '11111';
Expand Down Expand Up @@ -576,7 +582,7 @@ public function createEnumTableSchema()
'allowNull' => true,
'type' => 'string',
'phpType' => 'string',
'dbType' => 'enum(\'Client\',\'Consignees\',\'Car cleaner\')',
'dbType' => 'enum(\'Client\',\'Consignees\',\'Car cleaner\',\'B +\')',
'enumValues' => [
0 => 'Client',
1 => 'Consignees',
Expand Down
Loading