├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml └── src ├── Attribute ├── AttributeInterface.php ├── BooleanAttribute.php └── StandardAttribute.php ├── Document.php ├── Element ├── Abbreviation.php ├── AbstractElement.php ├── Address.php ├── Anchor.php ├── Arbitrary.php ├── ArbitraryEmpty.php ├── Area.php ├── Article.php ├── Aside.php ├── Audio.php ├── B.php ├── Base.php ├── BiDirectionalIsolation.php ├── BiDirectionalOverride.php ├── BlockQuote.php ├── Body.php ├── Br.php ├── Button.php ├── Canvas.php ├── Caption.php ├── Cite.php ├── Code.php ├── Column.php ├── ColumnGroup.php ├── Data.php ├── DataList.php ├── Definition.php ├── Deleted.php ├── Description.php ├── DescriptionList.php ├── DescriptionTerm.php ├── Details.php ├── Division.php ├── ElementInterface.php ├── Embed.php ├── Emphasis.php ├── FieldSet.php ├── Figure.php ├── FigureCaption.php ├── Footer.php ├── Form.php ├── Head.php ├── Header.php ├── Heading.php ├── Hr.php ├── Html.php ├── I.php ├── Iframe.php ├── Image.php ├── Input.php ├── Inserted.php ├── Keyboard.php ├── Label.php ├── Legend.php ├── Link.php ├── ListItem.php ├── Main.php ├── Map.php ├── Mark.php ├── Meta.php ├── Meter.php ├── Nav.php ├── NoScript.php ├── ObjectEmbed.php ├── Option.php ├── OptionGroup.php ├── OrderedList.php ├── Output.php ├── Paragraph.php ├── Parameter.php ├── ParentElementInterface.php ├── Pre.php ├── Progress.php ├── Quote.php ├── Rp.php ├── Rt.php ├── Ruby.php ├── Sample.php ├── Script.php ├── Section.php ├── Select.php ├── Shadow.php ├── Small.php ├── Source.php ├── Span.php ├── Strike.php ├── Strong.php ├── Style.php ├── Subscript.php ├── Summary.php ├── Superscript.php ├── Table.php ├── TableBody.php ├── TableCell.php ├── TableFoot.php ├── TableHeader.php ├── TableHeaderCell.php ├── TableRow.php ├── Template.php ├── Text.php ├── TextArea.php ├── Time.php ├── Title.php ├── Track.php ├── Underline.php ├── UnorderedList.php ├── Variable.php ├── Video.php └── WordBreak.php ├── RenderInterface.php ├── Set ├── AttributeSet.php ├── ElementSet.php └── SetInterface.php └── Tag ├── EmptyTag.php ├── Standard.php └── TagInterface.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Royall Spence 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # html-document 2 | 3 | [![SensioLabsInsight](https://insight.sensiolabs.com/projects/ee8a0fc2-0db8-45b2-86b9-35ff7e165b4c/mini.png)](https://insight.sensiolabs.com/projects/ee8a0fc2-0db8-45b2-86b9-35ff7e165b4c) 4 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/royallthefourth/html-document/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/royallthefourth/html-document/?branch=master) 5 | 6 | `html-document` is an object oriented tool for building HTML documents. 7 | It's intended to be more practical than the standard DOM implementation, but it's not exactly a by-the-book DOM implementation. 8 | 9 | ## What does it do? 10 | * Provides all standard HTML5 elements as classes 11 | * Provides methods to compose these elements into a document hierarchy 12 | * Renders a hierarchy of elements into a single string for output to the browser 13 | 14 | ## What does it not do? 15 | * Provide any validation for the documents you create (for now) 16 | * Prevent XSS or other injection-related attacks 17 | * Read or manipulate already existing documents 18 | 19 | ## Installation 20 | Install with [Composer](https://getcomposer.org/). 21 | Add the library to your `composer.json`: 22 | 23 | ```json 24 | { 25 | "require": { 26 | "royallthefourth/html-document": "^1.0" 27 | } 28 | } 29 | ``` 30 | Then install: 31 | ``` 32 | composer install --no-dev 33 | ``` 34 | 35 | This library has no dependencies. 36 | 37 | ## Example 38 | Building all or part of an HTML document with this library is easy. Take a look: 39 | ```php 40 | use RoyallTheFourth\HtmlDocument\Document; 41 | use RoyallTheFourth\HtmlDocument\Element\Body; 42 | use RoyallTheFourth\HtmlDocument\Element\Head; 43 | use RoyallTheFourth\HtmlDocument\Element\Html; 44 | use RoyallTheFourth\HtmlDocument\Element\Paragraph; 45 | use RoyallTheFourth\HtmlDocument\Element\Text; 46 | use RoyallTheFourth\HtmlDocument\Element\Title; 47 | 48 | echo (new Document()) 49 | ->add((new Html()) 50 | ->withChild((new Head()) 51 | ->withChild((new Title()) 52 | ->withChild(new Text('HTML Document')) 53 | ) 54 | ) 55 | ->withChild((new Body()) 56 | ->withChild((new Paragraph()) 57 | ->withChild(new Text('Build a whole document at once like this, or piece existing parts together')) 58 | ) 59 | ) 60 | )->render(); 61 | ``` 62 | 63 | This returns a complete HTML page as a string: 64 | 65 | ```html 66 | 67 | 68 | 69 | 70 | HTML Document 71 | 72 | 73 | 74 | 75 | 76 |

77 | Build a whole document at once like this, or piece existing parts together 78 |

79 | 80 | 81 | 82 | 83 | 84 | ``` 85 | 86 | Of course, you're unlikely to want to build whole documents in place like this. 87 | The real idea behind this library is to allow objects to represent themselves as elements to put on a page. 88 | For example, you might have an object that can take a `Layout` object to provide presentation behavior. 89 | Injecting a `TableRowLayout` object will provide the behaviors of the layout object without breaking encapsulation. 90 | Now your object can represent itself as a `` without the need for a templating engine, public properties, or getter methods. 91 | With this approach, a thoughtfully composed system of objects leads directly to a finished HTML document. 92 | See [my blog](https://royall.us/ditch-the-template-system/) for a more detailed example. 93 | 94 | One important difference from the usual conception of HTML documents is that these elements do not have values. 95 | Instead, the library provides a special element type called `Text` that can be used to place arbitrary text within any node that has open and close tags. 96 | 97 | There are also `Arbitrary` and `ArbitraryEmpty` elements in case you need a nonstandard element. 98 | The only difference between these two is that `Arbitrary` has a closing tag while `ArbitraryEmpty` does not. 99 | For example, `
` could be implemented as an `ArbitraryEmpty`. 100 | 101 | For more examples, see the `tests` directory. 102 | My intention is for this library to be very straightforward and self-documenting. 103 | 104 | ## Safety 105 | This library **does not** sanitize its inputs at all. 106 | Treat everything you pass into this library as if it's getting echoed directly onto the page. 107 | [`htmlspecialchars()`](http://php.net/htmlspecialchars) should be enough to prevent any unwanted markup from appearing. 108 | 109 | If I am mistaken about any of this, please notify me right away. 110 | 111 | ## Contributing 112 | Bug reports, bug fixes, tests, and documentation are heartily welcomed. 113 | If something in the library is missing or out of date, I'd love for it to be brought up to standard. 114 | If it's a simple bugfix, go ahead and open a pull request. 115 | Please include a test that exposes the bug along with your bugfix. 116 | 117 | For anything more complex, open an issue first so we can discuss how to handle it. 118 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "royallthefourth/html-document", 3 | "description": "An object-oriented tool for building HTML documents", 4 | "minimum-stability": "stable", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Royall Spence", 9 | "email": "royall@royall.us" 10 | } 11 | ], 12 | "require": { 13 | "php": "^7" 14 | }, 15 | "require-dev": { 16 | "phpunit/phpunit": "^5.6" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "RoyallTheFourth\\HtmlDocument\\": "src" 21 | } 22 | }, 23 | "autoload-dev": { 24 | "psr-4": { 25 | "RoyallTheFourth\\HtmlDocument\\Test\\": "tests" 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tests 5 | 6 | 7 | 8 | 9 | src 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/Attribute/AttributeInterface.php: -------------------------------------------------------------------------------- 1 | name = $name; 12 | } 13 | 14 | public function render(): string 15 | { 16 | return $this->name; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Attribute/StandardAttribute.php: -------------------------------------------------------------------------------- 1 | name = $name; 13 | $this->value = $value; 14 | } 15 | 16 | public function render(): string 17 | { 18 | return "{$this->name}=\"{$this->value}\""; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Document.php: -------------------------------------------------------------------------------- 1 | elements = $elements ?? new ElementSet(); 15 | } 16 | 17 | public function add(ElementInterface $element): Document 18 | { 19 | return new Document($this->elements->add($element)); 20 | } 21 | 22 | public function render(): string 23 | { 24 | $output = $this->elements->render(); 25 | 26 | return "\n{$output}"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Element/Abbreviation.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | 22 | $this->tag = new Standard('abbr', $attributes, $children); 23 | } 24 | 25 | public function withAttribute(string $name, string $value = null): Abbreviation 26 | { 27 | if ($value) { 28 | $attribute = new StandardAttribute($name, $value); 29 | } else { 30 | $attribute = new BooleanAttribute($name); 31 | } 32 | 33 | return new Abbreviation($this->attributes->add($attribute), $this->children); 34 | } 35 | 36 | public function withChild(ElementInterface $element): Abbreviation 37 | { 38 | return new Abbreviation($this->attributes, $this->children->add($element)); 39 | } 40 | 41 | public function withTitle(string $title): Abbreviation 42 | { 43 | return $this->withAttribute('title', $title); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Element/AbstractElement.php: -------------------------------------------------------------------------------- 1 | tag->render(); 25 | } 26 | 27 | /** 28 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/accesskey 29 | */ 30 | public function withAccessKey(string $key): self 31 | { 32 | return $this->withAttribute('accesskey', $key); 33 | } 34 | 35 | /** 36 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class 37 | */ 38 | public function withClass(string $class): self 39 | { 40 | return $this->withAttribute('class', $class); 41 | } 42 | 43 | /** 44 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable 45 | */ 46 | public function withContentEditable(string $editable = 'true'): self 47 | { 48 | return $this->withAttribute('contenteditable', $editable); 49 | } 50 | 51 | /** 52 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contextmenu 53 | */ 54 | public function withContextMenu(string $id): self 55 | { 56 | return $this->withAttribute('contextmenu', $id); 57 | } 58 | 59 | /** 60 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir 61 | */ 62 | public function withDir(string $direction = 'auto'): self 63 | { 64 | return $this->withAttribute('dir', $direction); 65 | } 66 | 67 | /** 68 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden 69 | */ 70 | public function withHidden(): self 71 | { 72 | return $this->withAttribute('hidden'); 73 | } 74 | 75 | /** 76 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id 77 | */ 78 | public function withId(string $id): self 79 | { 80 | return $this->withAttribute('id', $id); 81 | } 82 | 83 | /** 84 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang 85 | */ 86 | public function withLang(string $lang): self 87 | { 88 | return $this->withAttribute('lang', $lang); 89 | } 90 | 91 | /** 92 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/style 93 | */ 94 | public function withStyle(string $css): self 95 | { 96 | return $this->withAttribute('style', $css); 97 | } 98 | 99 | /** 100 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex 101 | */ 102 | public function withTabIndex(int $tabIndex): self 103 | { 104 | return $this->withAttribute('tabindex', $tabIndex); 105 | } 106 | 107 | /** 108 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title 109 | */ 110 | public function withTitle(string $title): self 111 | { 112 | return $this->withAttribute('title', $title); 113 | } 114 | 115 | /** 116 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/translate 117 | */ 118 | public function withTranslate(string $translate = 'yes'): self 119 | { 120 | return $this->withAttribute('translate', $translate); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/Element/Address.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | 22 | $this->tag = new Standard('address', $attributes, $children); 23 | } 24 | 25 | public function withAttribute(string $name, string $value = null): Address 26 | { 27 | if ($value) { 28 | $attribute = new StandardAttribute($name, $value); 29 | } else { 30 | $attribute = new BooleanAttribute($name); 31 | } 32 | 33 | return new Address($this->attributes->add($attribute), $this->children); 34 | } 35 | 36 | public function withChild(ElementInterface $element): Address 37 | { 38 | return new Address($this->attributes, $this->children->add($element)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Element/Anchor.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('a', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Anchor 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Anchor($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Anchor 36 | { 37 | return new Anchor($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withHref($href): Anchor 41 | { 42 | return $this->withAttribute('href', $href); 43 | } 44 | 45 | public function withDownload($filename = null): Anchor 46 | { 47 | return $this->withAttribute('download', $filename); 48 | } 49 | 50 | public function withHrefLang($lang): Anchor 51 | { 52 | return $this->withAttribute('hreflang', $lang); 53 | } 54 | 55 | public function withPing($url): Anchor 56 | { 57 | return $this->withAttribute('ping', $url); 58 | } 59 | 60 | public function withRel($rel): Anchor 61 | { 62 | return $this->withAttribute('rel', $rel); 63 | } 64 | 65 | public function withTarget($target): Anchor 66 | { 67 | return $this->withAttribute('target', $target); 68 | } 69 | 70 | public function withType($type): Anchor 71 | { 72 | return $this->withAttribute('type', $type); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Element/Arbitrary.php: -------------------------------------------------------------------------------- 1 | tag = new Standard($name, $attributes, $children); 22 | $this->attributes = $attributes ?? new AttributeSet(); 23 | $this->children = $children ?? new ElementSet(); 24 | } 25 | 26 | public function withAttribute(string $name, string $value = null): Arbitrary 27 | { 28 | if ($value) { 29 | $attribute = new StandardAttribute($name, $value); 30 | } else { 31 | $attribute = new BooleanAttribute($name); 32 | } 33 | 34 | return new Arbitrary($this->name, $this->attributes->add($attribute), $this->children); 35 | } 36 | 37 | public function withChild(ElementInterface $element): Arbitrary 38 | { 39 | return new Arbitrary($this->name, $this->attributes, $this->children->add($element)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Element/ArbitraryEmpty.php: -------------------------------------------------------------------------------- 1 | name = $name; 21 | $this->attributes = $attributes ?? new AttributeSet(); 22 | $this->tag = new EmptyTag($name, $attributes); 23 | } 24 | 25 | public function withAttribute(string $name, string $value = null): ArbitraryEmpty 26 | { 27 | if ($value) { 28 | $attribute = new StandardAttribute($name, $value); 29 | } else { 30 | $attribute = new BooleanAttribute($name); 31 | } 32 | 33 | return new ArbitraryEmpty($this->name, $this->attributes->add($attribute)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Element/Area.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('area', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): Area 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new Area($this->attributes->add($attribute)); 31 | } 32 | 33 | public function withAlt($text): Area 34 | { 35 | return $this->withAttribute('alt', $text); 36 | } 37 | 38 | public function withCoords($coords): Area 39 | { 40 | return $this->withAttribute('coords', $coords); 41 | } 42 | 43 | public function withDownload($filename = null): Area 44 | { 45 | return $this->withAttribute('download', $filename); 46 | } 47 | 48 | public function withHref($href): Area 49 | { 50 | return $this->withAttribute('href', $href); 51 | } 52 | 53 | public function withHrefLang($lang): Area 54 | { 55 | return $this->withAttribute('hreflang', $lang); 56 | } 57 | 58 | public function withMedia($media): Area 59 | { 60 | return $this->withAttribute('media', $media); 61 | } 62 | 63 | public function withRel($rel): Area 64 | { 65 | return $this->withAttribute('rel', $rel); 66 | } 67 | 68 | public function withShape($shape): Area 69 | { 70 | return $this->withAttribute('shape', $shape); 71 | } 72 | 73 | public function withTarget($target): Area 74 | { 75 | return $this->withAttribute('target', $target); 76 | } 77 | 78 | public function withType($type): Anchor 79 | { 80 | return $this->withAttribute('type', $type); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Element/Article.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('article', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Article 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Article($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Article 36 | { 37 | return new Article($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Aside.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('aside', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Aside 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Aside($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Aside 36 | { 37 | return new Aside($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Audio.php: -------------------------------------------------------------------------------- 1 | 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 | -------------------------------------------------------------------------------- /src/Element/B.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('b', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): B 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new B($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): B 36 | { 37 | return new B($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Base.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('base', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): Base 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new Base($this->attributes->add($attribute)); 31 | } 32 | 33 | public function withHref($href): Base 34 | { 35 | return $this->withAttribute('href', $href); 36 | } 37 | 38 | public function withTarget($target): Base 39 | { 40 | return $this->withAttribute('target', $target); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Element/BiDirectionalIsolation.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('bdi', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): BiDirectionalIsolation 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new BiDirectionalIsolation($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): BiDirectionalIsolation 36 | { 37 | return new BiDirectionalIsolation($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/BiDirectionalOverride.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('bdo', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): BiDirectionalOverride 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new BiDirectionalOverride($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): BiDirectionalOverride 36 | { 37 | return new BiDirectionalOverride($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withDir(string $direction = 'auto'): BiDirectionalOverride 41 | { 42 | return $this->withAttribute('dir', $direction); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Element/BlockQuote.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('blockquote', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): BlockQuote 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new BlockQuote($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): BlockQuote 36 | { 37 | return new BlockQuote($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withCite(string $url): BlockQuote 41 | { 42 | return $this->withAttribute('cite', $url); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Element/Body.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('body', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Body 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Body($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Body 36 | { 37 | return new Body($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Br.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('br', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): Br 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new Br($this->attributes->add($attribute)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Element/Button.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('button', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Button 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Button($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Button 36 | { 37 | return new Button($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withAutoFocus($autoFocus): Button 41 | { 42 | return $this->withAttribute('autofocus', $autoFocus); 43 | } 44 | 45 | public function withDisabled(): Button 46 | { 47 | return $this->withAttribute('disabled'); 48 | } 49 | 50 | public function withForm($formId): Button 51 | { 52 | return $this->withAttribute('form', $formId); 53 | } 54 | 55 | public function withFormAction($url): Button 56 | { 57 | return $this->withAttribute('formaction', $url); 58 | } 59 | 60 | public function withFormEncType($encoding): Button 61 | { 62 | return $this->withAttribute('formenctype', $encoding); 63 | } 64 | 65 | public function withFormNoValidate(): Button 66 | { 67 | return $this->withAttribute('formnovalidate'); 68 | } 69 | 70 | public function withFormTarget($target): Button 71 | { 72 | return $this->withAttribute('formtarget', $target); 73 | } 74 | 75 | public function withName($name): Button 76 | { 77 | return $this->withAttribute('name', $name); 78 | } 79 | 80 | public function withType($type): Button 81 | { 82 | return $this->withAttribute('type', $type); 83 | } 84 | 85 | public function withValue($value): Button 86 | { 87 | return $this->withAttribute('value', $value); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Element/Canvas.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('canvas', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Canvas 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Canvas($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Canvas 36 | { 37 | return new Canvas($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withHeight($height): Canvas 41 | { 42 | return $this->withAttribute('height', $height); 43 | } 44 | 45 | public function withWidth($width): Canvas 46 | { 47 | return $this->withAttribute('width', $width); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Element/Caption.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('caption', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Caption 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Caption($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Caption 36 | { 37 | return new Caption($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Cite.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('cite', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Cite 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Cite($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Cite 36 | { 37 | return new Cite($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Code.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('code', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Code 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Code($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Code 36 | { 37 | return new Code($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Column.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('col', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): Column 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new Column($this->attributes->add($attribute)); 31 | } 32 | 33 | public function withSpan(int $span = 1): Column 34 | { 35 | return $this->withAttribute('span', $span); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Element/ColumnGroup.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('colgroup', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): ColumnGroup 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new ColumnGroup($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): ColumnGroup 36 | { 37 | return new ColumnGroup($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withSpan(int $span = 1): ColumnGroup 41 | { 42 | return $this->withAttribute('span', $span); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Element/Data.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('data', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Data 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Data($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Data 36 | { 37 | return new Data($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withValue(string $value): Data 41 | { 42 | return $this->withAttribute('value', $value); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Element/DataList.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('datalist', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): DataList 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new DataList($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): DataList 36 | { 37 | return new DataList($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Definition.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('dfn', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Definition 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Definition($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Definition 36 | { 37 | return new Definition($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Deleted.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('del', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Deleted 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Deleted($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Deleted 36 | { 37 | return new Deleted($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withCite(string $url): Deleted 41 | { 42 | return $this->withAttribute('cite', $url); 43 | } 44 | 45 | public function withDateTime(string $dateTime): Deleted 46 | { 47 | return $this->withAttribute('datetime', $dateTime); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Element/Description.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('dd', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Description 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Description($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Description 36 | { 37 | return new Description($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/DescriptionList.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('dl', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): DescriptionList 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new DescriptionList($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): DescriptionList 36 | { 37 | return new DescriptionList($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/DescriptionTerm.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('dt', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): DescriptionTerm 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new DescriptionTerm($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): DescriptionTerm 36 | { 37 | return new DescriptionTerm($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Details.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('details', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Details 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Details($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Details 36 | { 37 | return new Details($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withOpen(string $open = 'false'): Details 41 | { 42 | return $this->withAttribute('open', $open); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Element/Division.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('div', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Division 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Division($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Division 36 | { 37 | return new Division($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/ElementInterface.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('embed', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): Embed 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new Embed($this->attributes->add($attribute)); 31 | } 32 | 33 | public function withHeight(int $pixels): Embed 34 | { 35 | return $this->withAttribute('height', $pixels); 36 | } 37 | 38 | public function withWidth(int $pixels): Embed 39 | { 40 | return $this->withAttribute('width', $pixels); 41 | } 42 | 43 | public function withSrc(string $url): Embed 44 | { 45 | return $this->withAttribute('src', $url); 46 | } 47 | 48 | public function withType(string $mime): Embed 49 | { 50 | return $this->withAttribute('type', $mime); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Element/Emphasis.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('em', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Emphasis 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Emphasis($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Emphasis 36 | { 37 | return new Emphasis($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/FieldSet.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('fieldset', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): FieldSet 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new FieldSet($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): FieldSet 36 | { 37 | return new FieldSet($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withDisabled(): FieldSet 41 | { 42 | return $this->withAttribute('disabled'); 43 | } 44 | 45 | public function withForm(string $id): FieldSet 46 | { 47 | return $this->withAttribute('form', $id); 48 | } 49 | 50 | public function withName(string $name): FieldSet 51 | { 52 | return $this->withAttribute('name', $name); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Element/Figure.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('figure', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Figure 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Figure($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Figure 36 | { 37 | return new Figure($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/FigureCaption.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('figcaption', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): FigureCaption 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new FigureCaption($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): FigureCaption 36 | { 37 | return new FigureCaption($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Footer.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('footer', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Footer 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Footer($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Footer 36 | { 37 | return new Footer($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Form.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('form', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Form 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Form($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Form 36 | { 37 | return new Form($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withAcceptCharset(string $charset = 'UNKNOWN'): Form 41 | { 42 | return $this->withAttribute('accept-charset', $charset); 43 | } 44 | 45 | public function withAction(string $url): Form 46 | { 47 | return $this->withAttribute('action', $url); 48 | } 49 | 50 | public function withAutoComplete(string $autoComplete = 'On'): Form 51 | { 52 | return $this->withAttribute('autocomplete', $autoComplete); 53 | } 54 | 55 | public function withEncType(string $encType = 'application/x-www-form-urlencoded'):Form 56 | { 57 | return $this->withAttribute('enctype', $encType); 58 | } 59 | 60 | public function withMethod(string $method = 'get'): Form 61 | { 62 | return $this->withAttribute('method', $method); 63 | } 64 | 65 | public function withName(string $name): Form 66 | { 67 | return $this->withAttribute('name', $name); 68 | } 69 | 70 | public function withNoValidate(): Form 71 | { 72 | return $this->withAttribute('novalidate'); 73 | } 74 | 75 | public function withTarget(string $target = '_self'): Form 76 | { 77 | return $this->withAttribute('target', $target); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Element/Head.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('head', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Head 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Head($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Head 36 | { 37 | return new Head($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Header.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('header', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Header 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Header($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Header 36 | { 37 | return new Header($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Heading.php: -------------------------------------------------------------------------------- 1 | level = $level; 22 | $this->attributes = $attributes ?? new AttributeSet(); 23 | $this->children = $children ?? new ElementSet(); 24 | $this->tag = new Standard("h{$level}", $attributes, $children); 25 | } 26 | 27 | public function withAttribute(string $name, string $value = null): Heading 28 | { 29 | if ($value) { 30 | $attribute = new StandardAttribute($name, $value); 31 | } else { 32 | $attribute = new BooleanAttribute($name); 33 | } 34 | 35 | return new Heading($this->level, $this->attributes->add($attribute), $this->children); 36 | } 37 | 38 | public function withChild(ElementInterface $element): Heading 39 | { 40 | return new Heading($this->level, $this->attributes, $this->children->add($element)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Element/Hr.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('hr', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): Hr 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new Hr($this->attributes->add($attribute)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Element/Html.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('html', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Html 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Html($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Html 36 | { 37 | return new Html($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/I.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('i', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): I 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new I($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): I 36 | { 37 | return new I($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Iframe.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('iframe', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Iframe 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Iframe($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Iframe 36 | { 37 | return new Iframe($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withAllowFullScreen(string $allow = 'false'): Iframe 41 | { 42 | return $this->withAttribute('allowfullscreen', $allow); 43 | } 44 | 45 | public function withHeight(int $pixels): Iframe 46 | { 47 | return $this->withAttribute('height', $pixels); 48 | } 49 | 50 | public function withName(string $name): Iframe 51 | { 52 | return $this->withAttribute('name', $name); 53 | } 54 | 55 | public function withSandbox(string $policy = ''): Iframe 56 | { 57 | return $this->withAttribute('sandbox', $policy); 58 | } 59 | 60 | public function withSrc(string $url): Iframe 61 | { 62 | return $this->withAttribute('src', $url); 63 | } 64 | 65 | public function withSrcDoc(string $url): Iframe 66 | { 67 | return $this->withAttribute('srcdoc', $url); 68 | } 69 | 70 | public function withWidth(int $pixels): Iframe 71 | { 72 | return $this->withAttribute('width', $pixels); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Element/Image.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('image', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Image 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Image($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Image 36 | { 37 | return new Image($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withAlt(string $alt): Image 41 | { 42 | return $this->withAttribute('alt', $alt); 43 | } 44 | 45 | public function withCrossOrigin(string $policy = 'anonymous'): Image 46 | { 47 | return $this->withAttribute('crossorigin', $policy); 48 | } 49 | 50 | public function withHeight(int $pixels): Image 51 | { 52 | return $this->withAttribute('height', $pixels); 53 | } 54 | 55 | public function withIsMap(): Image 56 | { 57 | return $this->withAttribute('ismap'); 58 | } 59 | 60 | public function withLongDesc(string $urlOrId): Image 61 | { 62 | return $this->withAttribute('longdesc', $urlOrId); 63 | } 64 | 65 | public function withSizes(string $sizes): Image 66 | { 67 | return $this->withAttribute('sizes', $sizes); 68 | } 69 | 70 | public function withSrc(string $url): Image 71 | { 72 | return $this->withAttribute('src', $url); 73 | } 74 | 75 | public function withSrcSet(string $srcSet): Image 76 | { 77 | return $this->withAttribute('srcset', $srcSet); 78 | } 79 | 80 | public function withWidth(int $pixels): Image 81 | { 82 | return $this->withAttribute('width', $pixels); 83 | } 84 | 85 | public function withUseMap(string $id): Image 86 | { 87 | return $this->withAttribute('usemap', $id); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Element/Input.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('input', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): Input 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new Input($this->attributes->add($attribute)); 31 | } 32 | 33 | public function withType(string $type): Input 34 | { 35 | return $this->withAttribute('type', $type); 36 | } 37 | 38 | public function withAccept(string $fileTypes): Input 39 | { 40 | return $this->withAttribute('accept', $fileTypes); 41 | } 42 | 43 | public function withAutoComplete(string $mode = 'on'): Input 44 | { 45 | return $this->withAttribute('autocomplete', $mode); 46 | } 47 | 48 | public function withAutoFocus(): Input 49 | { 50 | return $this->withAttribute('autofocus'); 51 | } 52 | 53 | public function withCapture(string $capture): Input 54 | { 55 | return $this->withAttribute('capture', $capture); 56 | } 57 | 58 | public function withChecked(): Input 59 | { 60 | return $this->withAttribute('checked'); 61 | } 62 | 63 | public function withDisabled(): Input 64 | { 65 | return $this->withAttribute('disabled'); 66 | } 67 | 68 | public function withForm(string $id): Input 69 | { 70 | return $this->withAttribute('form', $id); 71 | } 72 | 73 | public function withFormAction(string $url): Input 74 | { 75 | return $this->withAttribute('formaction', $url); 76 | } 77 | 78 | public function withFormEncType(string $encoding = 'application/x-www-form-urlencoded'): Input 79 | { 80 | return $this->withAttribute('formenctype', $encoding); 81 | } 82 | 83 | public function withFormMethod(string $method): Input 84 | { 85 | return $this->withAttribute('formmethod', $method); 86 | } 87 | 88 | public function withFormNoValidate(): Input 89 | { 90 | return $this->withAttribute('formnovalidate'); 91 | } 92 | 93 | public function withFormTarget(string $target = '_self'): Input 94 | { 95 | return $this->withAttribute('formtarget', $target); 96 | } 97 | 98 | public function withHeight(int $pixels): Input 99 | { 100 | return $this->withAttribute('height', $pixels); 101 | } 102 | 103 | public function withInputMode(string $mode): Input 104 | { 105 | return $this->withAttribute('inputmode', $mode); 106 | } 107 | 108 | public function withList(string $dataListId): Input 109 | { 110 | return $this->withAttribute('list', $dataListId); 111 | } 112 | 113 | public function withMax(string $max): Input 114 | { 115 | return $this->withAttribute('max', $max); 116 | } 117 | 118 | public function withMaxLength(string $max): Input 119 | { 120 | return $this->withAttribute('maxlength', $max); 121 | } 122 | 123 | public function withMin(string $min): Input 124 | { 125 | return $this->withAttribute('min', $min); 126 | } 127 | 128 | public function withMinLength(string $min): Input 129 | { 130 | return $this->withAttribute('minlength', $min); 131 | } 132 | 133 | public function withMultiple(): Input 134 | { 135 | return $this->withAttribute('multiple'); 136 | } 137 | 138 | public function withName(string $name): Input 139 | { 140 | return $this->withAttribute('name', $name); 141 | } 142 | 143 | public function withPattern(string $regex): Input 144 | { 145 | return $this->withAttribute('pattern', $regex); 146 | } 147 | 148 | public function withPlaceholder(string $placeholder): Input 149 | { 150 | return $this->withAttribute('placeholder', $placeholder); 151 | } 152 | 153 | public function withReadOnly(): Input 154 | { 155 | return $this->withAttribute('readonly'); 156 | } 157 | 158 | public function withRequired(): Input 159 | { 160 | return $this->withAttribute('required'); 161 | } 162 | 163 | public function withSelectionDirection(string $direction = 'forward'): Input 164 | { 165 | return $this->withAttribute('selectionDirection', $direction); 166 | } 167 | 168 | public function withSelectionEnd(string $end): Input 169 | { 170 | return $this->withAttribute('selectionEnd', $end); 171 | } 172 | 173 | public function withSelectionStart(string $start): Input 174 | { 175 | return $this->withAttribute('selectionStart', $start); 176 | } 177 | 178 | public function withSize(int $size): Input 179 | { 180 | return $this->withAttribute('size', $size); 181 | } 182 | 183 | public function withSpellCheck(string $check = 'default'): Input 184 | { 185 | return $this->withAttribute('spellcheck', $check); 186 | } 187 | 188 | public function withSrc(string $url): Input 189 | { 190 | return $this->withAttribute('src', $url); 191 | } 192 | 193 | public function withStep(string $increment): Input 194 | { 195 | return $this->withAttribute('step', $increment); 196 | } 197 | 198 | public function withValue(string $value): Input 199 | { 200 | return $this->withAttribute('value', $value); 201 | } 202 | 203 | public function withWidth(int $width): Input 204 | { 205 | return $this->withAttribute('width', $width); 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /src/Element/Inserted.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('ins', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Inserted 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Inserted($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Inserted 36 | { 37 | return new Inserted($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withCite(string $url): Inserted 41 | { 42 | return $this->withAttribute('cite', $url); 43 | } 44 | 45 | public function withDateTime(string $dateTime): Inserted 46 | { 47 | return $this->withAttribute('datetime', $dateTime); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Element/Keyboard.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('kbd', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Keyboard 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Keyboard($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Keyboard 36 | { 37 | return new Keyboard($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Label.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('label', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Label 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Label($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Label 36 | { 37 | return new Label($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withFor(string $id): Label 41 | { 42 | return $this->withAttribute('for', $id); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Element/Legend.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('legend', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Legend 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Legend($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Legend 36 | { 37 | return new Legend($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Link.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('link', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): Link 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new Link($this->attributes->add($attribute)); 31 | } 32 | 33 | public function withCrossOrigin(string $policy): Link 34 | { 35 | return $this->withAttribute('crossorigin', $policy); 36 | } 37 | 38 | public function withHref(string $url): Link 39 | { 40 | return $this->withAttribute('href', $url); 41 | } 42 | 43 | public function withHrefLang(string $language): Link 44 | { 45 | return $this->withAttribute('hreflang', $language); 46 | } 47 | 48 | /** 49 | * @param string $mediaQuery 50 | * @return Link 51 | * @see https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries 52 | */ 53 | public function withMedia(string $mediaQuery): Link 54 | { 55 | return $this->withAttribute('media', $mediaQuery); 56 | } 57 | 58 | /** 59 | * @param string $linkType 60 | * @return Link 61 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types 62 | */ 63 | public function withRel(string $linkType): Link 64 | { 65 | return $this->withAttribute('rel', $linkType); 66 | } 67 | 68 | public function withSizes(string $sizes = 'any'): Link 69 | { 70 | return $this->withAttribute('sizes', $sizes); 71 | } 72 | 73 | public function withType(string $mime): Link 74 | { 75 | return $this->withAttribute('type', $mime); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Element/ListItem.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('li', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): ListItem 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new ListItem($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): ListItem 36 | { 37 | return new ListItem($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withValue(int $value): ListItem 41 | { 42 | return $this->withAttribute('value', $value); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Element/Main.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('main', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Main 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Main($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Main 36 | { 37 | return new Main($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Map.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('map', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Map 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Map($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Map 36 | { 37 | return new Map($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withName(string $name): Map 41 | { 42 | return $this->withAttribute('name', $name); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Element/Mark.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('mark', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Mark 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Mark($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Mark 36 | { 37 | return new Mark($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Meta.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('meta', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): Meta 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new Meta($this->attributes->add($attribute)); 31 | } 32 | 33 | /** 34 | * @param string $charset 35 | * @return Meta 36 | * @see http://www.iana.org/assignments/character-sets 37 | */ 38 | public function withCharset(string $charset): Meta 39 | { 40 | return $this->withAttribute('charset', $charset); 41 | } 42 | 43 | public function withContent(string $content): Meta 44 | { 45 | return $this->withAttribute('content', $content); 46 | } 47 | 48 | public function withHttpEquiv(string $httpEquiv): Meta 49 | { 50 | return $this->withAttribute('http-equiv', $httpEquiv); 51 | } 52 | 53 | /** 54 | * @param string $name 55 | * @return Meta 56 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#attr-name 57 | */ 58 | public function withName(string $name): Meta 59 | { 60 | return $this->withAttribute('name', $name); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Element/Meter.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('meter', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Meter 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Meter($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Meter 36 | { 37 | return new Meter($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withValue($number): Meter 41 | { 42 | return $this->withAttribute('value', $number); 43 | } 44 | 45 | public function withLow($number): Meter 46 | { 47 | return $this->withAttribute('low', $number); 48 | } 49 | 50 | public function withHigh($number): Meter 51 | { 52 | return $this->withAttribute('high', $number); 53 | } 54 | 55 | public function withMin($number): Meter 56 | { 57 | return $this->withAttribute('min', $number); 58 | } 59 | 60 | public function withMax($number): Meter 61 | { 62 | return $this->withAttribute('max', $number); 63 | } 64 | 65 | public function withOptimum($number): Meter 66 | { 67 | return $this->withAttribute('optimum', $number); 68 | } 69 | 70 | public function withForm(string $id): Meter 71 | { 72 | return $this->withAttribute('form', $id); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Element/Nav.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('nav', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Nav 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Nav($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Nav 36 | { 37 | return new Nav($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/NoScript.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('noscript', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): NoScript 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new NoScript($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): NoScript 36 | { 37 | return new NoScript($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/ObjectEmbed.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('object', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): ObjectEmbed 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new ObjectEmbed($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): ObjectEmbed 36 | { 37 | return new ObjectEmbed($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withData(string $url): ObjectEmbed 41 | { 42 | return $this->withAttribute('data', $url); 43 | } 44 | 45 | public function withForm(string $id): ObjectEmbed 46 | { 47 | return $this->withAttribute('form', $id); 48 | } 49 | 50 | public function withHeight(int $pixels): ObjectEmbed 51 | { 52 | return $this->withAttribute('height', $pixels); 53 | } 54 | 55 | public function withName(string $name): ObjectEmbed 56 | { 57 | return $this->withAttribute('name', $name); 58 | } 59 | 60 | /** 61 | * @param string $mime 62 | * @return ObjectEmbed 63 | * @see http://www.iana.org/assignments/media-types/media-types.xhtml 64 | */ 65 | public function withType(string $mime): ObjectEmbed 66 | { 67 | return $this->withAttribute('type', $mime); 68 | } 69 | 70 | public function withTypeMustMatch(): ObjectEmbed 71 | { 72 | return $this->withAttribute('typemustmatch'); 73 | } 74 | 75 | public function withUseMap(string $name): ObjectEmbed 76 | { 77 | return $this->withAttribute('usemap', $name); 78 | } 79 | 80 | public function withWidth(int $pixels): ObjectEmbed 81 | { 82 | return $this->withAttribute('width', $pixels); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Element/Option.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('option', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Option 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Option($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Option 36 | { 37 | return new Option($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withDisabled(): Option 41 | { 42 | return $this->withAttribute('disabled'); 43 | } 44 | 45 | public function withLabel(string $label): Option 46 | { 47 | return $this->withAttribute('label', $label); 48 | } 49 | 50 | public function withSelected(): Option 51 | { 52 | return $this->withAttribute('selected'); 53 | } 54 | 55 | public function withLValue(string $value): Option 56 | { 57 | return $this->withAttribute('value', $value); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Element/OptionGroup.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('optgroup', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): OptionGroup 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new OptionGroup($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): OptionGroup 36 | { 37 | return new OptionGroup($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withDisabled(): OptionGroup 41 | { 42 | return $this->withAttribute('disabled'); 43 | } 44 | 45 | public function withLabel(string $label): OptionGroup 46 | { 47 | return $this->withAttribute('label', $label); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Element/OrderedList.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('ol', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): OrderedList 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new OrderedList($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): OrderedList 36 | { 37 | return new OrderedList($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withReversed(): OrderedList 41 | { 42 | return $this->withAttribute('reversed'); 43 | } 44 | 45 | public function withStart(int $start): OrderedList 46 | { 47 | return $this->withAttribute('start', $start); 48 | } 49 | 50 | public function withType(string $type): OrderedList 51 | { 52 | return $this->withAttribute('type', $type); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Element/Output.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('output', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Output 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Output($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Output 36 | { 37 | return new Output($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withFor(string $ids): Output 41 | { 42 | return $this->withAttribute('for', $ids); 43 | } 44 | 45 | public function withForm(string $id): Output 46 | { 47 | return $this->withAttribute('form', $id); 48 | } 49 | 50 | public function withName(string $name): Output 51 | { 52 | return $this->withAttribute('name', $name); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Element/Paragraph.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('p', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Paragraph 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Paragraph($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Paragraph 36 | { 37 | return new Paragraph($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Parameter.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('param', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): Parameter 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new Parameter($this->attributes->add($attribute)); 31 | } 32 | 33 | public function withName(string $name): Parameter 34 | { 35 | return $this->withAttribute('name', $name); 36 | } 37 | 38 | public function withValue(string $value): Parameter 39 | { 40 | return $this->withAttribute('value', $value); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Element/ParentElementInterface.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('pre', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Pre 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Pre($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Pre 36 | { 37 | return new Pre($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Progress.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('progress', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Progress 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Progress($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Progress 36 | { 37 | return new Progress($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withMax($number): Progress 41 | { 42 | return $this->withAttribute('max', $number); 43 | } 44 | 45 | public function withValue($number): Progress 46 | { 47 | return $this->withAttribute('value', $number); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Element/Quote.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('q', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Quote 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Quote($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Quote 36 | { 37 | return new Quote($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withCite(string $url): Quote 41 | { 42 | return $this->withAttribute('cite', $url); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Element/Rp.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('rp', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Rp 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Rp($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Rp 36 | { 37 | return new Rp($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Rt.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('rt', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Rt 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Rt($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Rt 36 | { 37 | return new Rt($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Ruby.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('ruby', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Ruby 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Ruby($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Ruby 36 | { 37 | return new Ruby($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Sample.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('samp', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Sample 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Sample($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Sample 36 | { 37 | return new Sample($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Script.php: -------------------------------------------------------------------------------- 1 | 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 | -------------------------------------------------------------------------------- /src/Element/Section.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('section', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Section 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Section($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Section 36 | { 37 | return new Section($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Select.php: -------------------------------------------------------------------------------- 1 | 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 | -------------------------------------------------------------------------------- /src/Element/Shadow.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('shadow', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Shadow 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Shadow($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Shadow 36 | { 37 | return new Shadow($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Small.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('small', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Small 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Small($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Small 36 | { 37 | return new Small($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Source.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('source', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): Source 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new Source($this->attributes->add($attribute)); 31 | } 32 | 33 | public function withSrc(string $url): Source 34 | { 35 | return $this->withAttribute('src', $url); 36 | } 37 | 38 | public function withType(string $mime): Source 39 | { 40 | return $this->withAttribute('type', $mime); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Element/Span.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('span', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Span 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Span($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Span 36 | { 37 | return new Span($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Strike.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('s', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Strike 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Strike($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Strike 36 | { 37 | return new Strike($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Strong.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('strong', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Strong 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Strong($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Strong 36 | { 37 | return new Strong($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Style.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('style', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Style 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Style($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Style 36 | { 37 | return new Style($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withType(string $mime = 'text/css'): Style 41 | { 42 | return $this->withAttribute('type', $mime); 43 | } 44 | 45 | /** 46 | * @param string $query 47 | * @return Style 48 | * @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries 49 | */ 50 | public function withMedia(string $query = 'all'): Style 51 | { 52 | return $this->withAttribute('media', $query); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Element/Subscript.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('sub', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Subscript 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Subscript($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Subscript 36 | { 37 | return new Subscript($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Summary.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('summary', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Summary 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Summary($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Summary 36 | { 37 | return new Summary($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Superscript.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('sup', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Superscript 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Superscript($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Superscript 36 | { 37 | return new Superscript($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Table.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('table', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Table 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Table($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Table 36 | { 37 | return new Table($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/TableBody.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('tbody', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): TableBody 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new TableBody($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): TableBody 36 | { 37 | return new TableBody($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/TableCell.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('td', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): TableCell 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new TableCell($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): TableCell 36 | { 37 | return new TableCell($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withColSpan(int $span): TableCell 41 | { 42 | return $this->withAttribute('colspan', $span); 43 | } 44 | 45 | public function withRowSpan(int $span): TableCell 46 | { 47 | return $this->withAttribute('rowspan', $span); 48 | } 49 | 50 | public function withHeaders(string $ids): TableCell 51 | { 52 | return $this->withAttribute('headers', $ids); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Element/TableFoot.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('tfoot', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): TableFoot 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new TableFoot($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): TableFoot 36 | { 37 | return new TableFoot($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/TableHeader.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('thead', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): TableHeader 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new TableHeader($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): TableHeader 36 | { 37 | return new TableHeader($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/TableHeaderCell.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('th', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): TableHeaderCell 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new TableHeaderCell($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): TableHeaderCell 36 | { 37 | return new TableHeaderCell($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withColSpan(int $span): TableHeaderCell 41 | { 42 | return $this->withAttribute('colspan', $span); 43 | } 44 | 45 | public function withRowSpan(int $span): TableHeaderCell 46 | { 47 | return $this->withAttribute('rowspan', $span); 48 | } 49 | 50 | public function withHeaders(string $ids): TableHeaderCell 51 | { 52 | return $this->withAttribute('headers', $ids); 53 | } 54 | 55 | public function withScope(string $scope): TableHeaderCell 56 | { 57 | return $this->withAttribute('scope', $scope); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Element/TableRow.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('tr', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): TableRow 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new TableRow($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): TableRow 36 | { 37 | return new TableRow($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Template.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('template', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Template 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Template($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Template 36 | { 37 | return new Template($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Text.php: -------------------------------------------------------------------------------- 1 | text = $text; 12 | } 13 | 14 | public function render(): string 15 | { 16 | return $this->text; 17 | } 18 | 19 | /** 20 | * Does nothing. 21 | * @param string $key 22 | * @param string $value 23 | * @return Text 24 | * @throws \ErrorException 25 | */ 26 | public function withAttribute(string $key, string $value = null): Text 27 | { 28 | throw new \ErrorException('Element cannot have attributes.'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Element/TextArea.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('textarea', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): TextArea 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new TextArea($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): TextArea 36 | { 37 | return new TextArea($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withAutoComplete(string $offOn): TextArea 41 | { 42 | return $this->withAttribute('autocomplete', $offOn); 43 | } 44 | 45 | public function withAutoFocus(): TextArea 46 | { 47 | return $this->withAttribute('autofocus'); 48 | } 49 | 50 | public function withCols(int $charWidth = 20): TextArea 51 | { 52 | return $this->withAttribute('cols', $charWidth); 53 | } 54 | 55 | public function withDisabled(): TextArea 56 | { 57 | return $this->withAttribute('disabled'); 58 | } 59 | 60 | public function withForm(string $id): TextArea 61 | { 62 | return $this->withAttribute('form', $id); 63 | } 64 | 65 | public function withMaxLength(int $max): TextArea 66 | { 67 | return $this->withAttribute('maxlength', $max); 68 | } 69 | 70 | public function withMinLength(int $min): TextArea 71 | { 72 | return $this->withAttribute('minlength', $min); 73 | } 74 | 75 | public function withName(string $name): TextArea 76 | { 77 | return $this->withAttribute('name', $name); 78 | } 79 | 80 | public function withPlaceholder(string $placeholder): TextArea 81 | { 82 | return $this->withAttribute('placeholder', $placeholder); 83 | } 84 | 85 | public function withReadOnly(): TextArea 86 | { 87 | return $this->withAttribute('readonly'); 88 | } 89 | 90 | public function withRequired(): TextArea 91 | { 92 | return $this->withAttribute('required'); 93 | } 94 | 95 | public function withRows(int $rows): TextArea 96 | { 97 | return $this->withAttribute('rows', $rows); 98 | } 99 | 100 | public function withSelectionDirection(string $direction): TextArea 101 | { 102 | return $this->withAttribute('selectionDirection', $direction); 103 | } 104 | 105 | public function withSelectionEnd(int $index): TextArea 106 | { 107 | return $this->withAttribute('selectionEnd', $index); 108 | } 109 | 110 | public function withSelectionStart(int $index): TextArea 111 | { 112 | return $this->withAttribute('selectionStart', $index); 113 | } 114 | 115 | public function withSpellCheck(string $spellcheck): TextArea 116 | { 117 | return $this->withAttribute('spellcheck', $spellcheck); 118 | } 119 | 120 | public function withWrap(string $wrap = 'soft'): TextArea 121 | { 122 | return $this->withAttribute('wrap', $wrap); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/Element/Time.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('time', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Time 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Time($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Time 36 | { 37 | return new Time($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | /** 41 | * @see http://www.w3.org/TR/html-markup/datatypes.html#common.data.datetime 42 | */ 43 | public function withDateTime(string $dateTime): Time 44 | { 45 | return $this->withAttribute('datetime', $dateTime); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Element/Title.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('title', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Title 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Title($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Title 36 | { 37 | return new Title($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Track.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('track', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): Track 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new Track($this->attributes->add($attribute)); 31 | } 32 | 33 | public function withDefault(): Track 34 | { 35 | return $this->withAttribute('default'); 36 | } 37 | 38 | public function withKind(string $kind = 'subtitles'): Track 39 | { 40 | return $this->withAttribute('kind', $kind); 41 | } 42 | 43 | public function withLabel(string $label): Track 44 | { 45 | return $this->withAttribute('label', $label); 46 | } 47 | 48 | public function withSrc(string $url): Track 49 | { 50 | return $this->withAttribute('src', $url); 51 | } 52 | 53 | public function withSrcLang(string $lang): Track 54 | { 55 | return $this->withAttribute('srclang', $lang); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Element/Underline.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('u', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Underline 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Underline($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Underline 36 | { 37 | return new Underline($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/UnorderedList.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('ul', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): UnorderedList 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new UnorderedList($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): UnorderedList 36 | { 37 | return new UnorderedList($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Variable.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('var', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Variable 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Variable($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Variable 36 | { 37 | return new Variable($this->attributes, $this->children->add($element)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Element/Video.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 20 | $this->children = $children ?? new ElementSet(); 21 | $this->tag = new Standard('video', $attributes, $children); 22 | } 23 | 24 | public function withAttribute(string $name, string $value = null): Video 25 | { 26 | if ($value) { 27 | $attribute = new StandardAttribute($name, $value); 28 | } else { 29 | $attribute = new BooleanAttribute($name); 30 | } 31 | 32 | return new Video($this->attributes->add($attribute), $this->children); 33 | } 34 | 35 | public function withChild(ElementInterface $element): Video 36 | { 37 | return new Video($this->attributes, $this->children->add($element)); 38 | } 39 | 40 | public function withControls(): Video 41 | { 42 | return $this->withAttribute('controls'); 43 | } 44 | 45 | /** 46 | * @param string $policy 47 | * @return Video 48 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes 49 | */ 50 | public function withCrossOrigin(string $policy): Video 51 | { 52 | return $this->withAttribute('crossorigin', $policy); 53 | } 54 | 55 | public function withHeight($height): Video 56 | { 57 | return $this->withAttribute('height', $height); 58 | } 59 | 60 | public function withWidth($width): Video 61 | { 62 | return $this->withAttribute('width', $width); 63 | } 64 | 65 | public function withLoop(): Video 66 | { 67 | return $this->withAttribute('loop'); 68 | } 69 | 70 | public function withMuted(): Video 71 | { 72 | return $this->withAttribute('muted'); 73 | } 74 | 75 | public function withPreload(string $preload): Video 76 | { 77 | return $this->withAttribute('preload', $preload); 78 | } 79 | 80 | public function withPoster(string $url): Video 81 | { 82 | return $this->withAttribute('poster', $url); 83 | } 84 | 85 | public function withSrc(string $url): Video 86 | { 87 | return $this->withAttribute('src', $url); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Element/WordBreak.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 19 | $this->tag = new EmptyTag('wbr', $attributes); 20 | } 21 | 22 | public function withAttribute(string $name, string $value = null): WordBreak 23 | { 24 | if ($value) { 25 | $attribute = new StandardAttribute($name, $value); 26 | } else { 27 | $attribute = new BooleanAttribute($name); 28 | } 29 | 30 | return new WordBreak($this->attributes->add($attribute)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/RenderInterface.php: -------------------------------------------------------------------------------- 1 | attributes[] = $attribute; 15 | } 16 | } 17 | 18 | public function iterate(): \Generator 19 | { 20 | foreach ($this->attributes as $attribute) { 21 | yield $attribute; 22 | } 23 | } 24 | 25 | /** 26 | * @param AttributeInterface $attribute 27 | * @return AttributeSet 28 | */ 29 | public function add($attribute): AttributeSet 30 | { 31 | $this->attributes[] = $attribute; 32 | return $this; 33 | } 34 | 35 | /** 36 | * @param $set AttributeSet 37 | * @return AttributeSet 38 | */ 39 | public function merge($set): AttributeSet 40 | { 41 | foreach ($set->iterate() as $attribute) { 42 | $this->add($attribute); 43 | } 44 | 45 | return $this; 46 | } 47 | 48 | public function render(): string 49 | { 50 | $output = ''; 51 | 52 | foreach ($this->iterate() as $attribute) { 53 | $output .= ' ' . $attribute->render(); 54 | } 55 | 56 | return $output; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Set/ElementSet.php: -------------------------------------------------------------------------------- 1 | elements[] = $element; 15 | } 16 | } 17 | 18 | public function iterate(): \Generator 19 | { 20 | foreach ($this->elements as $element) { 21 | yield $element; 22 | } 23 | } 24 | 25 | /** 26 | * @param $element ElementInterface 27 | * @return ElementSet 28 | */ 29 | public function add($element): ElementSet 30 | { 31 | $this->elements[] = $element; 32 | return $this; 33 | } 34 | 35 | /** 36 | * @param $set ElementSet 37 | * @return ElementSet 38 | */ 39 | public function merge($set): ElementSet 40 | { 41 | foreach ($set->iterate() as $element) { 42 | $this->add($element); 43 | } 44 | 45 | return $this; 46 | } 47 | 48 | public function render(): string 49 | { 50 | $output = ''; 51 | 52 | foreach ($this->iterate() as $element) { 53 | $output .= $element->render() . "\n"; 54 | } 55 | 56 | return $output; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Set/SetInterface.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 14 | $this->name = $name; 15 | } 16 | 17 | public function render(): string 18 | { 19 | $attributes = $this->attributes->render(); 20 | 21 | return "<{$this->name}{$attributes}>\n"; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Tag/Standard.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes ?? new AttributeSet(); 17 | $this->children = $children ?? new ElementSet(); 18 | $this->name = $name; 19 | } 20 | 21 | public function render(): string 22 | { 23 | $attributes = $this->attributes->render(); 24 | $children = $this->renderChildren(); 25 | 26 | return "<{$this->name}{$attributes}>{$children}\nname}>\n"; 27 | } 28 | 29 | private function renderChildren(): string 30 | { 31 | $out = ''; 32 | 33 | foreach ($this->children->iterate() as $child) { 34 | $out .= "\n" . $child->render(); 35 | } 36 | 37 | return $out; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Tag/TagInterface.php: -------------------------------------------------------------------------------- 1 |