Skip to content

Commit

Permalink
Merge pull request #7789 from cakephp/enums
Browse files Browse the repository at this point in the history
Enum update
  • Loading branch information
markstory authored Jan 4, 2024
2 parents 4c6c867 + 3050e78 commit e6a11a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions en/contributing/cakephp-coding-conventions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,17 @@ underscore character, for example::

define('LONG_NAMED_CONSTANT', 2);

Enums
-----

Enum cases are defined in ``CamelCase`` style::

enum ArticleStatus: string
{
case Published = 'Y';
case NotPublishedYet = 'N';
}

Careful when using empty()/isset()
==================================

Expand Down
4 changes: 4 additions & 0 deletions en/intro/conventions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ Entity class names are singular CamelCased and have no suffix. ``User``,
matching the ``users``, ``menu_links`` and ``user_favorite_pages``
tables respectively.

Enum class names should use a ``{Entity}{Column}`` convention, and enum cases
should use CamelCased names.


View Conventions
================

Expand Down
10 changes: 8 additions & 2 deletions en/orm/database-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,16 @@ Where ``ArticleStatus`` contains something like::

enum ArticleStatus: string
{
case PUBLISHED = 'Y';
case UNPUBLISHED = 'N';
case Published = 'Y';
case Unpublished = 'N';
}

CakePHP recommends a few conventions for enums:

- Enum classnames should follow ``{Entity}{ColumnName}`` style to enable
detection while running bake and to aid with project consistency.
- Enum cases should use CamelCase style.

.. _adding-custom-database-types:

Adding Custom Types
Expand Down

0 comments on commit e6a11a1

Please sign in to comment.