Changeset 3474833
- Timestamp:
- 03/04/2026 06:15:41 PM (4 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin-menu-editor/trunk/customizables/Schemas/SchemaFactory.php
r3432926 r3474833 5 5 use YahnisElsts\AdminMenuEditor\ProCustomizable\Settings\WithSchema\CssPropertySetting; 6 6 use YahnisElsts\AdminMenuEditor\ProCustomizable\Settings\WithSchema\Font; 7 use YahnisElsts\AdminMenuEditor\ProCustomizable\Settings\WithSchema; 7 8 8 9 class SchemaFactory { 9 public function string($label = null) {10 public function string($label = null): StringSchema { 10 11 return new StringSchema($label); 11 12 } 12 13 13 public function boolean($label = null) {14 public function boolean($label = null): Schema { 14 15 return new Boolean($label); 15 16 } 16 17 17 public function number($label = null) {18 public function number($label = null): Number { 18 19 return new Number($label); 19 20 } 20 21 21 public function int($label = null) {22 public function int($label = null): Number { 22 23 return (new Number($label))->int(); 23 24 } 24 25 25 public function enum(array $values, $label = null) {26 public function enum(array $values, $label = null): Enum { 26 27 return (new Enum($label))->values($values); 27 28 } … … 31 32 } 32 33 33 public function struct(array $fieldSchemas, $label = null) {34 public function struct(array $fieldSchemas, $label = null): Struct { 34 35 return new Struct($fieldSchemas, $label); 35 36 } 36 37 37 public function record(Schema $keySchema, Schema $itemSchema, $label = null) {38 public function record(Schema $keySchema, Schema $itemSchema, $label = null): Record { 38 39 return new Record($keySchema, $itemSchema, $label); 39 40 } … … 66 67 * @return IndexedArray 67 68 */ 68 public function arr(Schema $itemSchema, $label = null){69 public function arr(Schema $itemSchema, ?string $label = null): IndexedArray { 69 70 return new IndexedArray($itemSchema, $label); 70 71 } … … 75 76 * @return Union 76 77 */ 77 public function union(array $schemas, $label = null){78 public function union(array $schemas, ?string $label = null): Union { 78 79 return new Union($schemas, $label); 79 80 } 80 81 81 public function cssColor($label = null) { 82 return (new Color($label))->orTransparent()->settingClassHint(CssPropertySetting::class); 82 public function cssColor($label = null, ?string $cssProperty = null): Color { 83 $params = []; 84 if ( $cssProperty !== null ) { 85 $params['cssProperty'] = $cssProperty; 86 } 87 return (new Color($label))->orTransparent()->s(CssPropertySetting::class, $params); 83 88 } 84 89 85 public function cssFont($label = null) { 86 return (new PlaceholderStruct($label))->settingClassHint(Font::class); 90 public function cssLength(?string $label = null, ?string $cssProperty = null): Number { 91 $params = []; 92 if ( $cssProperty !== null ) { 93 $params['cssProperty'] = $cssProperty; 94 } 95 return (new Number($label))->s(WithSchema\CssLengthSetting::class, $params); 96 } 97 98 public function cssFont(?string $label = null, ?bool $includesLineHeight = null): Struct { 99 $params = []; 100 if ( $includesLineHeight !== null ) { 101 $params['includesLineHeight'] = $includesLineHeight; 102 } 103 return Font::createDefaultSchema($this, $label, $params); 104 } 105 106 public function cssPadding(): Struct { 107 return WithSchema\CssBoxDimensions::createPaddingSchema($this); 108 } 109 110 public function cssMargin(): Struct { 111 return WithSchema\CssBoxDimensions::createMarginSchema($this); 112 } 113 114 public function cssBorders(): Struct { 115 return WithSchema\Borders::createDefaultSchema($this)->settingParams(['label' => 'Border']); 116 } 117 118 public function cssBorderStyle(?string $label = 'Border style', bool $nullAllowed = true): Enum { 119 $allowedValues = ['none', 'solid', 'dashed', 'dotted', 'double', 'groove', 'ridge', 'inset', 'outset']; 120 if ( $nullAllowed ) { 121 array_unshift($allowedValues, null); 122 } 123 124 $schema = $this 125 ->enum($allowedValues, $label) 126 ->s(CssPropertySetting::class, ['cssProperty' => 'border-style']); 127 128 if ( $nullAllowed ) { 129 $schema->defaultValue(null); 130 } 131 return $schema; 87 132 } 88 133 … … 95 140 * @return JsonValue 96 141 */ 97 public function json( $valueSchema = null, $label = null){142 public function json(?Schema $valueSchema = null, ?string $label = null): JsonValue { 98 143 if ( $valueSchema === null ) { 99 144 $valueSchema = new Anything();
Note: See TracChangeset
for help on using the changeset viewer.