mirror of
https://github.com/archtechx/enums.git
synced 2025-12-12 11:14:05 +00:00
* Metadata * Fix code style (php-cs-fixer) * Code style Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
38 lines
799 B
PHP
38 lines
799 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace ArchTech\Enums\Meta;
|
|
|
|
abstract class MetaProperty
|
|
{
|
|
final public function __construct(
|
|
public mixed $value,
|
|
) {
|
|
$this->value = $this->transform($value);
|
|
}
|
|
|
|
public static function make(mixed $value): static
|
|
{
|
|
return new static($value);
|
|
}
|
|
|
|
protected function transform(mixed $value): mixed
|
|
{
|
|
// Feel free to override this to transform the value during instantiation
|
|
|
|
return $value;
|
|
}
|
|
|
|
/** Get the name of the accessor method */
|
|
public static function method(): string
|
|
{
|
|
if (property_exists(static::class, 'method')) {
|
|
return static::${'method'};
|
|
}
|
|
|
|
$parts = explode('\\', static::class);
|
|
|
|
return lcfirst(end($parts));
|
|
}
|
|
}
|