### Install Tourze Enum Extra Source: https://github.com/tourze/enum-extra/blob/master/README.md Installs the tourze/enum-extra package using Composer. This command is essential for adding the package's functionalities to your PHP project. ```bash composer require tourze/enum-extra ``` -------------------------------- ### Generate Select Options Source: https://github.com/tourze/enum-extra/blob/master/README.md Demonstrates the usage of the genOptions() method to convert enum cases into an array of options suitable for UI select components. ```php $options = Status::genOptions(); ``` -------------------------------- ### SelectDataFetcher Interface Source: https://github.com/tourze/enum-extra/blob/master/README.md Defines the SelectDataFetcher interface, standardizing the process of fetching data specifically for select components, ensuring consistent data retrieval. ```apidoc interface SelectDataFetcher { public function genSelectData(): iterable; } ``` -------------------------------- ### BoolEnum Implementation Source: https://github.com/tourze/enum-extra/blob/master/README.md Provides a ready-to-use BoolEnum implementation with helper methods like toBool() for converting the enum case to a boolean value and genBoolOptions() for generating boolean select options. ```php use Tourze\EnumExtra\BoolEnum; $value = BoolEnum::YES; $boolValue = $value->toBool(); // true // Generate boolean options $options = BoolEnum::genBoolOptions(); // Result: [['label' => '是', 'text' => '是', 'value' => true, 'name' => '是'], ...] ``` -------------------------------- ### Selectable Interface Source: https://github.com/tourze/enum-extra/blob/master/README.md Defines the Selectable interface, providing static methods to generate collections of select options from enum cases, often used for UI dropdowns. ```apidoc interface Selectable { public static function genOptions(): array; } ``` -------------------------------- ### PHP Enum Definition and Usage Source: https://github.com/tourze/enum-extra/blob/master/README.md Demonstrates defining a PHP enum that implements Labelable, Itemable, and Selectable interfaces, along with basic usage for generating select options and converting enum cases to arrays. ```php use Tourze\EnumExtra\Itemable; use Tourze\EnumExtra\ItemTrait; use Tourze\EnumExtra\Labelable; use Tourze\EnumExtra\Selectable; use Tourze\EnumExtra\SelectTrait; enum Status: string implements Labelable, Itemable, Selectable { use ItemTrait; use SelectTrait; case ACTIVE = 'active'; case INACTIVE = 'inactive'; public function getLabel(): string { return match($this) { self::ACTIVE => 'Active', self::INACTIVE => 'Inactive', }; } } // Generate select options $options = Status::genOptions(); // Result: [['label' => 'Active', 'text' => 'Active', 'value' => 'active', 'name' => 'Active'], ...] // Convert single case to array $array = Status::ACTIVE->toArray(); // Result: ['value' => 'active', 'label' => 'Active'] ``` -------------------------------- ### Labelable Interface Source: https://github.com/tourze/enum-extra/blob/master/README.md Defines the Labelable interface, which requires implementing classes to provide a getLabel() method for returning a human-readable string representation of an enum case. ```apidoc interface Labelable { public function getLabel(): string; } ``` -------------------------------- ### TreeDataFetcher Interface Source: https://github.com/tourze/enum-extra/blob/master/README.md Defines the TreeDataFetcher interface, which outlines methods for generating hierarchical tree data structures from enum cases or related data. ```apidoc interface TreeDataFetcher { public function genTreeData(): array; } ``` -------------------------------- ### Filter Select Options via Environment Source: https://github.com/tourze/enum-extra/blob/master/README.md Shows how to filter enum select options based on environment variables. Setting `enum-display:{enum}-{value}` to false in the environment will exclude that specific enum case from generated options. ```php // In your .env file or server configuration // $_ENV['enum-display:App\\Enums\\Status-inactive'] = false; // Now Status::genOptions() will exclude the INACTIVE option ``` -------------------------------- ### Enum Array Conversion Source: https://github.com/tourze/enum-extra/blob/master/README.md Illustrates converting individual enum cases into a simple associative array format, typically containing 'value' and 'label' keys, useful for serialization or data transfer. ```php $array = Status::ACTIVE->toArray(); // Result: ['value' => 'active', 'label' => 'Active'] ``` -------------------------------- ### Itemable Interface Source: https://github.com/tourze/enum-extra/blob/master/README.md Defines the Itemable interface, enabling enum cases to be converted into a structured array format suitable for select option items. ```apidoc interface Itemable { public function toSelectItem(): array; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.