bnomei/kirby-blueprints

View on GitHub
classes/Blueprints/Attributes/Property.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Bnomei\Blueprints\Attributes;

use Attribute;
use Kirby\Toolkit\Str;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
class Property extends GenericAttribute
{
    /**
     * Attach a property to the field with given key and value
     */
    public function __construct(
        public string $key,
        public string|bool|array $value
    ) {}

    public function toArray(): array
    {
        $key = strtolower(Str::camel($this->key));

        return [
            $key => $this->value,
        ];
    }
}