[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/php-ai-client/src/Common/ -> AbstractEnum.php (summary)

Abstract base class for enum-like behavior in PHP 7.4. This class provides enum-like functionality for PHP versions that don't support native enums. Child classes should define uppercase snake_case constants for enum values.

File Size: 349 lines (11 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 18 functions

  __construct()
  __get()
  __set()
  from()
  tryFrom()
  cases()
  equals()
  is()
  getValues()
  isValidValue()
  getInstance()
  getConstants()
  determineClassEnumerations()
  __call()
  __callStatic()
  camelCaseToConstant()
  __toString()
  jsonSerialize()

Functions
Functions that are not part of a class:

__construct(string $value, string $name)   X-Ref
Constructor is private to ensure instances are created through static methods.

param: string $value The enum value.
param: string $name The constant name.

__get(string $property)   X-Ref
Provides read-only access to properties.

return: mixed The property value.
param: string $property The property name.

__set(string $property, $value)   X-Ref
Prevents property modification.

param: string $property The property name.
param: mixed $value The value to set.

from(string $value)   X-Ref
Creates an enum instance from a value, throws exception if invalid.

return: static The enum instance.
param: string $value The enum value.

tryFrom(string $value)   X-Ref
Tries to create an enum instance from a value, returns null if invalid.

return: static|null The enum instance or null.
param: string $value The enum value.

cases()   X-Ref
Gets all enum cases.

return: static[] Array of all enum instances.

equals($other)   X-Ref
Checks if this enum has the same value as the given value.

return: bool True if values are equal.
param: string|self $other The value or enum to compare.

is(self $other)   X-Ref
Checks if this enum is the same instance type and value as another enum.

return: bool True if enums are identical.
param: self $other The other enum to compare.

getValues()   X-Ref
Gets all valid values for this enum.

return: string[] List of all enum values.

isValidValue(string $value)   X-Ref
Checks if a value is valid for this enum.

return: bool True if value is valid.
param: string $value The value to check.

getInstance(string $value, string $name)   X-Ref
Gets or creates a singleton instance for the given value and name.

return: static The enum instance.
param: string $value The enum value.
param: string $name The constant name.

getConstants()   X-Ref
Gets all constants for this enum class.

return: array<string, string> Map of constant names to values.

determineClassEnumerations(string $className)   X-Ref
Determines the class enumerations by reflecting on class constants.

This method can be overridden by subclasses to customize how
enumerations are determined (e.g., to add dynamic constants).

return: array<string, string> Map of constant names to values.
param: class-string $className The fully qualified class name.

__call(string $name, array $arguments)   X-Ref
Handles dynamic method calls for enum checking.

return: bool True if the enum value matches.
param: string $name The method name.
param: array<mixed> $arguments The method arguments.

__callStatic(string $name, array $arguments)   X-Ref
Handles static method calls for enum creation.

return: static The enum instance.
param: string $name The method name.
param: array<mixed> $arguments The method arguments.

camelCaseToConstant(string $camelCase)   X-Ref
Converts camelCase to CONSTANT_CASE.

return: string The CONSTANT_CASE version.
param: string $camelCase The camelCase string.

__toString()   X-Ref
Returns string representation of the enum.

return: string The enum value.

jsonSerialize()   X-Ref
Converts the enum to a JSON-serializable format.

return: string The enum value.



Generated : Sat Jun 13 09:38:55 2026 Cross-referenced by PHPXref