| @@ 15-74 (lines=60) @@ | ||
| 12 | * Class Audio |
|
| 13 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio |
|
| 14 | */ |
|
| 15 | final class Audio extends AbstractElement implements ParentElementInterface |
|
| 16 | { |
|
| 17 | public function __construct(AttributeSet $attributes = null, ElementSet $children = null) |
|
| 18 | { |
|
| 19 | $this->attributes = $attributes ?? new AttributeSet(); |
|
| 20 | $this->children = $children ?? new ElementSet(); |
|
| 21 | $this->tag = new Standard('audio', $attributes, $children); |
|
| 22 | } |
|
| 23 | ||
| 24 | public function withAttribute(string $name, string $value = null): Audio |
|
| 25 | { |
|
| 26 | if ($value) { |
|
| 27 | $attribute = new StandardAttribute($name, $value); |
|
| 28 | } else { |
|
| 29 | $attribute = new BooleanAttribute($name); |
|
| 30 | } |
|
| 31 | ||
| 32 | return new Audio($this->attributes->add($attribute), $this->children); |
|
| 33 | } |
|
| 34 | ||
| 35 | public function withChild(ElementInterface $element): Audio |
|
| 36 | { |
|
| 37 | return new Audio($this->attributes, $this->children->add($element)); |
|
| 38 | } |
|
| 39 | ||
| 40 | public function withAutoplay(): Audio |
|
| 41 | { |
|
| 42 | return $this->withAttribute('autoplay'); |
|
| 43 | } |
|
| 44 | ||
| 45 | public function withControls(): Audio |
|
| 46 | { |
|
| 47 | return $this->withAttribute('controls'); |
|
| 48 | } |
|
| 49 | ||
| 50 | public function withLoop(): Audio |
|
| 51 | { |
|
| 52 | return $this->withAttribute('loop'); |
|
| 53 | } |
|
| 54 | ||
| 55 | public function withMuted(): Audio |
|
| 56 | { |
|
| 57 | return $this->withAttribute('muted'); |
|
| 58 | } |
|
| 59 | ||
| 60 | public function withPreload(string $preload = 'metadata'): Audio |
|
| 61 | { |
|
| 62 | return $this->withAttribute('preload', $preload); |
|
| 63 | } |
|
| 64 | ||
| 65 | public function withSrc(string $src): Audio |
|
| 66 | { |
|
| 67 | return $this->withAttribute('src', $src); |
|
| 68 | } |
|
| 69 | ||
| 70 | public function withVolume(string $volume): Audio |
|
| 71 | { |
|
| 72 | return $this->withAttribute('volume', $volume); |
|
| 73 | } |
|
| 74 | } |
|
| 75 | ||
| @@ 15-84 (lines=70) @@ | ||
| 12 | * Class Script |
|
| 13 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script |
|
| 14 | */ |
|
| 15 | final class Script extends AbstractElement implements ParentElementInterface |
|
| 16 | { |
|
| 17 | public function __construct(AttributeSet $attributes = null, ElementSet $children = null) |
|
| 18 | { |
|
| 19 | $this->attributes = $attributes ?? new AttributeSet(); |
|
| 20 | $this->children = $children ?? new ElementSet(); |
|
| 21 | $this->tag = new Standard('script', $attributes, $children); |
|
| 22 | } |
|
| 23 | ||
| 24 | public function withAttribute(string $name, string $value = null): Script |
|
| 25 | { |
|
| 26 | if ($value) { |
|
| 27 | $attribute = new StandardAttribute($name, $value); |
|
| 28 | } else { |
|
| 29 | $attribute = new BooleanAttribute($name); |
|
| 30 | } |
|
| 31 | ||
| 32 | return new Script($this->attributes->add($attribute), $this->children); |
|
| 33 | } |
|
| 34 | ||
| 35 | public function withChild(ElementInterface $element): Script |
|
| 36 | { |
|
| 37 | return new Script($this->attributes, $this->children->add($element)); |
|
| 38 | } |
|
| 39 | ||
| 40 | public function withAsync(): Script |
|
| 41 | { |
|
| 42 | return $this->withAttribute('async'); |
|
| 43 | } |
|
| 44 | ||
| 45 | /** |
|
| 46 | * @param string $meta |
|
| 47 | * @return Script |
|
| 48 | * @see https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity |
|
| 49 | */ |
|
| 50 | public function withIntegrity(string $meta): Script |
|
| 51 | { |
|
| 52 | return $this->withAttribute('integrity', $meta); |
|
| 53 | } |
|
| 54 | ||
| 55 | public function withSrc(string $url): Script |
|
| 56 | { |
|
| 57 | return $this->withAttribute('src', $url); |
|
| 58 | } |
|
| 59 | ||
| 60 | public function withType(string $mime): Script |
|
| 61 | { |
|
| 62 | return $this->withAttribute('type', $mime); |
|
| 63 | } |
|
| 64 | ||
| 65 | public function withText(string $code): Script |
|
| 66 | { |
|
| 67 | return $this->withAttribute('text', $code); |
|
| 68 | } |
|
| 69 | ||
| 70 | public function withDefer(): Script |
|
| 71 | { |
|
| 72 | return $this->withAttribute('defer'); |
|
| 73 | } |
|
| 74 | ||
| 75 | /** |
|
| 76 | * @param string $policy |
|
| 77 | * @return Script |
|
| 78 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes |
|
| 79 | */ |
|
| 80 | public function withCrossOrigin(string $policy): Script |
|
| 81 | { |
|
| 82 | return $this->withAttribute('crossorigin', $policy); |
|
| 83 | } |
|
| 84 | } |
|
| 85 | ||
| @@ 15-79 (lines=65) @@ | ||
| 12 | * Class Select |
|
| 13 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select |
|
| 14 | */ |
|
| 15 | final class Select extends AbstractElement implements ParentElementInterface |
|
| 16 | { |
|
| 17 | public function __construct(AttributeSet $attributes = null, ElementSet $children = null) |
|
| 18 | { |
|
| 19 | $this->attributes = $attributes ?? new AttributeSet(); |
|
| 20 | $this->children = $children ?? new ElementSet(); |
|
| 21 | $this->tag = new Standard('select', $attributes, $children); |
|
| 22 | } |
|
| 23 | ||
| 24 | public function withAttribute(string $name, string $value = null): Select |
|
| 25 | { |
|
| 26 | if ($value) { |
|
| 27 | $attribute = new StandardAttribute($name, $value); |
|
| 28 | } else { |
|
| 29 | $attribute = new BooleanAttribute($name); |
|
| 30 | } |
|
| 31 | ||
| 32 | return new Select($this->attributes->add($attribute), $this->children); |
|
| 33 | } |
|
| 34 | ||
| 35 | public function withChild(ElementInterface $element): Select |
|
| 36 | { |
|
| 37 | return new Select($this->attributes, $this->children->add($element)); |
|
| 38 | } |
|
| 39 | ||
| 40 | public function withAutoFocus(): Select |
|
| 41 | { |
|
| 42 | return $this->withAttribute('autofocus'); |
|
| 43 | } |
|
| 44 | ||
| 45 | public function withDisabled(): Select |
|
| 46 | { |
|
| 47 | return $this->withAttribute('disabled'); |
|
| 48 | } |
|
| 49 | ||
| 50 | public function withForm(string $id): Select |
|
| 51 | { |
|
| 52 | return $this->withAttribute('form', $id); |
|
| 53 | } |
|
| 54 | ||
| 55 | public function withMultiple(): Select |
|
| 56 | { |
|
| 57 | return $this->withAttribute('multiple'); |
|
| 58 | } |
|
| 59 | ||
| 60 | public function withName(string $name): Select |
|
| 61 | { |
|
| 62 | return $this->withAttribute('name', $name); |
|
| 63 | } |
|
| 64 | ||
| 65 | public function withRequired(): Select |
|
| 66 | { |
|
| 67 | return $this->withAttribute('required'); |
|
| 68 | } |
|
| 69 | ||
| 70 | public function withSelected(): Select |
|
| 71 | { |
|
| 72 | return $this->withAttribute('selected'); |
|
| 73 | } |
|
| 74 | ||
| 75 | public function withSize(int $rows): Select |
|
| 76 | { |
|
| 77 | return $this->withAttribute('size', $rows); |
|
| 78 | } |
|
| 79 | } |
|
| 80 | ||