diff --git a/src/Command/EnumCommand.php b/src/Command/EnumCommand.php index 092bb033..42ad11f1 100644 --- a/src/Command/EnumCommand.php +++ b/src/Command/EnumCommand.php @@ -17,6 +17,7 @@ namespace Bake\Command; use Cake\Console\Arguments; +use Cake\Console\ConsoleIo; use Cake\Console\ConsoleOptionParser; use Cake\Utility\Inflector; use InvalidArgumentException; @@ -174,4 +175,26 @@ protected function formatCases(array $cases): array return $formatted; } + + /** + * Generate a class stub + * + * @param string $name The class name + * @param \Cake\Console\Arguments $args The console arguments + * @param \Cake\Console\ConsoleIo $io The console io + * @return void + */ + protected function bake(string $name, Arguments $args, ConsoleIo $io): void + { + parent::bake($name, $args, $io); + + $path = $this->getPath($args); + $filename = $path . $name . '.php'; + + // Work around composer caching that classes/files do not exist. + // Check for the file as it might not exist in tests. + if (file_exists($filename)) { + require_once $filename; + } + } } diff --git a/src/Command/ModelCommand.php b/src/Command/ModelCommand.php index ec7d8354..d495cfc0 100644 --- a/src/Command/ModelCommand.php +++ b/src/Command/ModelCommand.php @@ -1439,6 +1439,12 @@ protected function possibleEnumFields(TableSchemaInterface $schema): array foreach ($schema->columns() as $column) { $columnSchema = $schema->getColumn($column); + if (str_starts_with($columnSchema['type'], 'enum-')) { + $fields[] = $column; + + continue; + } + if (!in_array($columnSchema['type'], ['string', 'integer', 'tinyinteger', 'smallinteger'], true)) { continue; } diff --git a/src/View/Helper/BakeHelper.php b/src/View/Helper/BakeHelper.php index 5fe7f33d..52e11dd6 100644 --- a/src/View/Helper/BakeHelper.php +++ b/src/View/Helper/BakeHelper.php @@ -233,7 +233,7 @@ public function getViewFieldsData(array $fields, SchemaInterface $schema, array if (isset($associationFields[$field])) { return 'string'; } - if (str_starts_with($type, 'enum-')) { + if ($type && str_starts_with($type, 'enum-')) { return 'enum'; } $numberTypes = ['decimal', 'biginteger', 'integer', 'float', 'smallinteger', 'tinyinteger'];