-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
add Classes for Options
class ContentOptions implements \ArrayAccess
{
private function __construct(
private array $data = []
) {
}
public static function new(array $options = []): self
{
return new self($options);
}
public function offsetExists(mixed $offset): bool
{
return isset($this->options[$offset]);
}
public function offsetGet(mixed $offset): mixed
{
return $this->options[$offset];
}
public function offsetSet(mixed $offset, mixed $value): void
{
$this->options[$offset] = $value;
}
public function offsetUnset(mixed $offset): void
{
unset($this->options[$offset]);
}
public function setLabel(string $value): self
{
$this->options[Content::OPT_LABEL] = $value;
return $this;
}
public function getLabel(): string
{
if (isset($this->options['Content::OPT_LABEL'])) {
return $this->options['Content::OPT_LABEL'];
}
return 'no Label';
}
public function setFormatter(string $value): self
{
$this->options[Content::OPT_FORMATTER] = $value;
return $this;
}
public function getFormatter(): string
{
if (isset($this->options['Content::OPT_FORMATTER'])) {
return $this->options['Content::OPT_FORMATTER'];
}
return null;
}
}usage:
$builder
->addBlock('example', null, [
'label' => 'Example Block',
])
->addContent('firstname', null,
ContentOption::new()
->setLabel('your Name')
)
->addContent('lastname', null, [
'label' => 'Your Lastname',
])
->addContent('company', null, [
'label' => 'Your Company',
])
->addContent('email', null,
ContentOption::new()
->setLabel('Your Company')
->setFormatter(EmailFormatter::class),
])
;Pros:
- type safety
- code completion (PHP native)
- compatible to ArrayAnnotation
Cons:
- Lot of boilerplate code
- OptionsResolver already implemented, addtional to OptionsResolver
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request