<?php
|
|
namespace JVBase\managers\SEO;
|
|
|
/**
|
* Field Builder - Fluent API for field definitions
|
*/
|
class FieldBuilder
|
{
|
private SchemaBuilder $schema;
|
private string $name;
|
private array $definition = [];
|
|
public function __construct(SchemaBuilder $schema, string $name, array $baseDefinition = [])
|
{
|
$this->schema = $schema;
|
$this->name = $name;
|
$this->definition = $baseDefinition;
|
}
|
|
public function type(string $type): self
|
{
|
$this->definition['type'] = $type;
|
return $this;
|
}
|
|
public function label(string $label): self
|
{
|
$this->definition['label'] = $label;
|
return $this;
|
}
|
|
public function description(string $description): self
|
{
|
$this->definition['description'] = $description;
|
return $this;
|
}
|
|
public function transformer(string $transformer): self
|
{
|
$this->definition['transformer'] = $transformer;
|
return $this;
|
}
|
|
public function required(bool $required = true): self
|
{
|
$this->definition['required'] = $required;
|
return $this;
|
}
|
|
public function repeater(bool $repeater = true): self
|
{
|
$this->definition['repeater'] = $repeater;
|
return $this;
|
}
|
|
public function options(array $options): self
|
{
|
$this->definition['options'] = $options;
|
return $this;
|
}
|
|
public function placeholder(string $placeholder): self
|
{
|
$this->definition['placeholder'] = $placeholder;
|
return $this;
|
}
|
|
public function fields(array $fields): self
|
{
|
$this->definition['fields'] = $fields;
|
return $this;
|
}
|
|
public function default($default): self
|
{
|
$this->definition['default'] = $default;
|
return $this;
|
}
|
|
/**
|
* Finish building and register the field
|
*/
|
public function __destruct()
|
{
|
$this->schema->registerField($this->name, $this->definition);
|
}
|
}
|