class Sivujetti\BlockType\PropertiesBuilder
Builder-luokka, jolla voi määritellä lohkotyypin kentät. Esim. ImageBlockTypellä on src-, altText-, ja caption-kentät.
Synopsis
final class PropertiesBuilder {
/* Vakiot */
const DATA_TYPE_TEXT = BlockProperty::DATA_TYPE_TEXT;
const DATA_TYPE_UINT = BlockProperty::DATA_TYPE_UINT;
/* Metodit */
public newProperty(string $name, ?string $dataType = null): $this
public dataType(string $type, ?int $length = null, ?array $validationRules = null): $this
public getResult(): ArrayObject<int, BlockProperty>
}
Vakiot
- DATA_TYPE_TEXT
- ...
- DATA_TYPE_UINT
- ...
Metodit
newProperty()
Määrittelee uuden kentän.
Signature
public function newProperty(string $name, ?string $dataType = null): PropertiesBuilder
Esimerkit
$builder->newProperty("numColumns", $builder::DATA_TYPE_UINT);
Tietotyypeillä on oletuksena seuraavat validaattorit:
| Tyypi | Validaattorit |
|---|---|
"text" ($builder::DATA_TYPE_TEXT) | ["type", "string"]["maxLength", 1024] |
"json" | ["type", "string"]["maxLength", 256000] |
"int" | ["type", "number"] |
"uint" ($builder::DATA_TYPE_UINT) | ["type", "number"]["min", 0] |
Jos haluat yliajaa oletusvalidaattorien asetuksia, korvaa $builder->newProperty("year", $builder::DATA_TYPE_TEXT) -> $builder->newProperty("year")->dataType($builder::DATA_TYPE_TEXT, validationRules: [["maxLength", 4]]).
dataType()
Määrittelee edellisen kentän tietotyypin.
Signature
public function dataType(string $type, ?int $length = null, ?array $validationRules = null): PropertiesBuilder
Esimerkit
$builder
->newProperty("stringPropWithLength")
->dataType($builder::DATA_TYPE_TEXT, 64);
getResult()
…
Signature
public function getResult(): \ArrayObject<int, BlockProperty>