1
0
Fork 0
mirror of https://github.com/archtechx/enums.git synced 2026-02-04 17:44:06 +00:00

Metadata (#8)

* Metadata

* Fix code style (php-cs-fixer)

* Code style

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
This commit is contained in:
Samuel Štancl 2022-03-29 20:11:06 +02:00 committed by GitHub
parent cc5bba1912
commit 55478c4eb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 400 additions and 46 deletions

38
src/Meta/MetaProperty.php Normal file
View file

@ -0,0 +1,38 @@
<?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));
}
}