CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.0 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.0
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
      • Driver
      • Exception
      • Expression
      • Log
      • Query
      • Retry
      • Schema
      • Statement
      • Type
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class EnumType

Enum type converter.

Use to convert string data between PHP and the database types.

Namespace: Cake\Database\Type

Property Summary

  • $_name protected
    string|null

    Identifier name for this type

  • $backingType protected
    string

    The type of the enum which is either string or int

  • $enumClassName protected
    class-string<BackedEnum>

    The enum classname which is associated to the type instance

Method Summary

  • __construct() public
  • from() public static

    Create an EnumType that is paired with the provided $enumClassName.

  • getBaseType() public

    Returns the base type name that this class is inheriting.

  • getEnumClassName() public
  • getName() public

    Returns type identifier name for this object.

  • marshal() public

    Marshals request data

  • newId() public

    Generate a new primary key value for a given type.

  • toDatabase() public

    Convert enum instances into the database format.

  • toPHP() public

    Transform DB value to backed enum instance

  • toStatement() public

    Get the binding type to use in a PDO statement.

Method Detail

__construct() ¶ public

__construct(string $name, class-string<BackedEnum> $enumClassName)
Parameters
string $name

The name identifying this type

class-string<BackedEnum> $enumClassName

The associated enum class name

from() ¶ public static

from(class-string<BackedEnum> $enumClassName): string

Create an EnumType that is paired with the provided $enumClassName.

Usage

// In a table class
$this->getSchema()->setColumnType('status', EnumType::from(StatusEnum::class));
Parameters
class-string<BackedEnum> $enumClassName

The enum class name

Returns
string

getBaseType() ¶ public

getBaseType(): string|null

Returns the base type name that this class is inheriting.

This is useful when extending base type for adding extra functionality, but still want the rest of the framework to use the same assumptions it would do about the base type it inherits from.

Returns
string|null

getEnumClassName() ¶ public

getEnumClassName(): class-string<BackedEnum>
Returns
class-string<BackedEnum>

getName() ¶ public

getName(): string|null

Returns type identifier name for this object.

Returns
string|null

marshal() ¶ public

marshal(mixed $value): BackedEnum|null

Marshals request data

Most useful for converting request data into PHP objects, that make sense for the rest of the ORM/Database layers.

Parameters
mixed $value

The value to convert.

Returns
BackedEnum|null

newId() ¶ public

newId(): mixed

Generate a new primary key value for a given type.

This method can be used by types to create new primary key values when entities are inserted.

Returns
mixed

toDatabase() ¶ public

toDatabase(mixed $value, Cake\Database\Driver $driver): string|int|null

Convert enum instances into the database format.

Parameters
mixed $value

The value to convert.

Cake\Database\Driver $driver

The driver instance to convert with.

Returns
string|int|null

toPHP() ¶ public

toPHP(mixed $value, Cake\Database\Driver $driver): BackedEnum|null

Transform DB value to backed enum instance

Parameters
mixed $value

The value to convert.

Cake\Database\Driver $driver

The driver instance to convert with.

Returns
BackedEnum|null

toStatement() ¶ public

toStatement(mixed $value, Cake\Database\Driver $driver): int

Get the binding type to use in a PDO statement.

Parameters
mixed $value
Cake\Database\Driver $driver
Returns
int

Property Detail

$_name ¶ protected

Identifier name for this type

Type
string|null

$backingType ¶ protected

The type of the enum which is either string or int

Type
string

$enumClassName ¶ protected

The enum classname which is associated to the type instance

Type
class-string<BackedEnum>
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs