PHP code example of y-tsuzaki / php-enum-spy

1. Go to this page and download the library: Download y-tsuzaki/php-enum-spy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

y-tsuzaki / php-enum-spy example snippets

:ExampleEnum.php


declare(strict_types=1);

namespace YTsuzaki\PhpEnumSpyExample;

enum ExampleEnum: string
{
    case TODO = 'todo';
    case IN_PROGRESS = 'in_progress';
    case DONE = 'done';

    case PUNIRU = "puniru_is_cute_slime";

    public function toDisplay(): string
    {
        return match ($this) {
            self::TODO => '未完了',
            self::IN_PROGRESS => '進行中',
            self::DONE => '完了',
            self::PUNIRU => 'ぷにるはかわいいスライム',
        };
    }
}
:php-enum-spy.config.php


$config = [
  "dirs" => [
    // Add the directory where the Enum class file is located
    "src",
  ],
  "convert_functions" => [],
];

return $config;
:php-enum-spy.config.php


$config = [
  "dirs" => [
    // Add the directory where the Enum class file is located
    "src",
  ],
  "convert_functions" => [
      // Add your custom convert function if needed
      "your_custom_function" => function (UnitEnum $enum) {
          if (method_exists($enum, 'toJapanese')) {
              return $enum->toJapanese();
          }
          return null;
      },
  ],
];

return $config;
bash
vi php-enum-spy.config.php
bash
vendor/bin/php-enum-spy