-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathHTMLElement.php
4524 lines (4069 loc) · 167 KB
/
HTMLElement.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace Gt\Dom;
use DateTimeImmutable;
use DateTimeInterface;
use Exception;
use Gt\Dom\ClientSide\AudioTrackList;
use Gt\Dom\ClientSide\CSSStyleDeclaration;
use Gt\Dom\ClientSide\FileList;
use Gt\Dom\ClientSide\MediaController;
use Gt\Dom\ClientSide\MediaError;
use Gt\Dom\ClientSide\MediaStream;
use Gt\Dom\ClientSide\StyleSheet;
use Gt\Dom\ClientSide\TextTrack;
use Gt\Dom\ClientSide\TextTrackList;
use Gt\Dom\ClientSide\TimeRanges;
use Gt\Dom\ClientSide\ValidityState;
use Gt\Dom\ClientSide\VideoTrackList;
use Gt\Dom\Exception\ArrayAccessReadOnlyException;
use Gt\Dom\Exception\ClientSideOnlyFunctionalityException;
use Gt\Dom\Exception\EnumeratedValueException;
use Gt\Dom\Exception\HierarchyRequestError;
use Gt\Dom\Exception\IncorrectHTMLElementUsageException;
use Gt\Dom\Exception\IndexSizeException;
use TypeError;
/**
* The DOM object model is a strange design, made even stranger by the libxml
* implementation used by PHP. In order for this library to take advantage of
* the highly optimised speed of libxml, the classes registered as "node
* classes" from Document::registerNodeClasses all have to extend the base
* DOMNode classes, but cannot extend each other. Therefore, even though a
* DOMElement extends a DOMNode, and a Gt\Dom\Element extends DOMElement and a
* Gt\Dom\Node extends a DOMNode, it is in fact impossible for a Gt\Dom\Element
* to extend a Gt\Dom\Node.
*
* This is all handled by the underlying implementation, so there is not really
* any downside, apart from the hierarchy being confusing. What is limited
* however is the lack of HTMLElement classes that specify the individual
* functionality of each type of HTML Element - for example, a HTMLSelectElement
* has a property "options" which contains a list of HTMLOptionElements - this
* property doesn't make sense to be available to all Elements, so this trait
* works as a compromise.
*
* The intention is to provide IDEs with well-typed autocompletion, but without
* straying too far from the official specification. This trait contains all
* functionality introduced by all HTMLElement subtypes, but before each
* property or method is called, a list of "allowed" Elements is checked,
* throwing a IncorrectHTMLElementUsageException if incorrectly used.
*
* @property string $hreflang Is a DOMString that reflects the hreflang HTML attribute, indicating the language of the linked resource.
* @property string $text Is a DOMString being a synonym for the Node.textContent property.
* @property string $type Is a DOMString that reflects the type HTML attribute, indicating the MIME type of the linked resource.
* @property string $name Is a DOMString representing the name of the object when submitted with a form. If specified, it must not be the empty string.
* @property bool $checked Returns / Sets the current state of the element when type is checkbox or radio.
* @property string $href Is a USVString that is the result of parsing the href HTML attribute relative to the document, containing a valid URL of a linked resource.
* @property string $download Is a DOMString indicating that the linked resource is intended to be downloaded rather than displayed in the browser. The value represent the proposed name of the file. If the name is not a valid filename of the underlying OS, browser will adapt it.
* @property string $hash Is a USVString representing the fragment identifier, including the leading hash mark ('#'), if any, in the referenced URL.
* @property string $host Is a USVString representing the hostname and port (if it's not the default port) in the referenced URL.
* @property string $hostname Is a USVString representing the hostname in the referenced URL.
* @property-read string $origin Returns a USVString containing the origin of the URL, that is its scheme, its domain and its port.
* @property string $password Is a USVString containing the password specified before the domain name.
* @property string $pathname Is a USVString containing an initial '/' followed by the path of the URL, not including the query string or fragment.
* @property string $port Is a USVString representing the port component, if any, of the referenced URL.
* @property string $protocol Is a USVString representing the protocol component, including trailing colon (':'), of the referenced URL.
* @property string $referrerPolicy Is a DOMString that reflects the referrerpolicy HTML attribute indicating which referrer to use.
* @property string $rel Is a DOMString that reflects the rel HTML attribute, specifying the relationship of the target object to the linked object.
* @property-read DOMTokenList $relList Returns a DOMTokenList that reflects the rel HTML attribute, as a list of tokens.
* @property string $search Is a USVString representing the search element, including leading question mark ('?'), if any, of the referenced URL.
* @property string $target Is a DOMString that reflects the target HTML attribute, indicating where to display the linked resource.
* @property string $username Is a USVString containing the username specified before the domain name.
* @property string $alt Is a DOMString that reflects the alt HTML attribute, containing alternative text for the element.
* @property string $coords Is a DOMString that reflects the coords HTML attribute, containing coordinates to define the hot-spot region.
* @property string $shape Is a DOMString that reflects the shape HTML attribute, indicating the shape of the hot-spot, limited to known values.
* @property-read AudioTrackList $audioTracks A AudioTrackList that lists the AudioTrack objects contained in the element.
* @property bool $autoplay A Boolean that reflects the autoplay HTML attribute, indicating whether playback should automatically begin as soon as enough media is available to do so without interruption.
* @property-read TimeRanges $buffered Returns a TimeRanges object that indicates the ranges of the media source that the browser has buffered (if any) at the moment the buffered property is accessed.
* @property-read ?MediaController $controller Is a MediaController object that represents the media controller assigned to the element, or null if none is assigned.
* @property bool $controls Is a Boolean that reflects the controls HTML attribute, indicating whether user interface items for controlling the resource should be displayed.
* @property-read DOMTokenList $controlsList Returns a DOMTokenList that helps the user agent select what controls to show on the media element whenever the user agent shows its own set of controls. The DOMTokenList takes one or more of three possible values: nodownload, nofullscreen, and noremoteplayback.
* @property string $crossOrigin A DOMString indicating the CORS setting for this media element.
* @property-read string $currentSrc Returns a DOMString with the absolute URL of the chosen media resource.
* @property float $currentTime A double-precision floating-point value indicating the current playback time in seconds; if the media has not started to play and has not been seeked, this value is the media's initial playback time. Setting this value seeks the media to the new time. The time is specified relative to the media's timeline.
* @property bool $defaultMuted A Boolean that reflects the muted HTML attribute, which indicates whether the media element's audio output should be muted by default.
* @property float $defaultPlaybackRate A double indicating the default playback rate for the media.
* @property bool $disableRemotePlayback A Boolean that sets or returns the remote playback state, indicating whether the media element is allowed to have a remote playback UI.
* @property-read ?float $duration A read-only double-precision floating-point value indicating the total duration of the media in seconds. If no media data is available, the returned value is NaN. If the media is of indefinite length (such as streamed live media, a WebRTC call's media, or similar), the value is +Infinity.
* @property-read bool $ended Returns a Boolean that indicates whether the media element has finished playing.
* @property-read ?MediaError $error Returns a MediaError object for the most recent error, or null if there has not been an error.
* @property bool $loop A Boolean that reflects the loop HTML attribute, which indicates whether the media element should start over when it reaches the end.
* @property string $mediaGroup A DOMString that reflects the mediagroup HTML attribute, which indicates the name of the group of elements it belongs to. A group of media elements shares a common MediaController.
* @property bool $muted Is a Boolean that determines whether audio is muted. true if the audio is muted and false otherwise.
* @property-read int $networkState Returns an unsigned short (enumeration) indicating the current state of fetching the media over the network.
* @property-read bool $paused Returns a Boolean that indicates whether the media element is paused.
* @property float $playbackRate Is a double that indicates the rate at which the media is being played back.
* @property-read TimeRanges $played Returns a TimeRanges object that contains the ranges of the media source that the browser has played, if any.
* @property string $preload Is a DOMString that reflects the preload HTML attribute, indicating what data should be preloaded, if any. Possible values are: none, metadata, auto.
* @property-read int $readyState Returns an unsigned short (enumeration) indicating the readiness state of the media.
* @property-read TimeRanges $seekable Returns a TimeRanges object that contains the time ranges that the user is able to seek to, if any.
* @property-read bool $seeking Returns a Boolean that indicates whether the media is in the process of seeking to a new position.
* @property-read string $sinkId Returns a DOMString that is the unique ID of the audio device delivering output, or an empty string if it is using the user agent default. This ID should be one of the MediaDeviceInfo.deviceid values returned from MediaDevices.enumerateDevices(), id-multimedia, or id-communications.
* @property string $src Is a DOMString that reflects the src HTML attribute, which contains the URL of a media resource to use.
* @property ?MediaStream $srcObject Is a MediaStream representing the media to play or that has played in the current HTMLMediaElement, or null if not assigned.
* @property-read TextTrackList $textTracks Returns the list of TextTrack objects contained in the element.
* @property-read VideoTrackList $videoTracks Returns the list of VideoTrack objects contained in the element.
* @property float $volume Is a double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest).
* @property bool $autofocus Is a Boolean indicating whether the control should have input focus when the page loads, unless the user overrides it, for example by typing in a different control. Only one form-associated element in a document can have this attribute specified.
* @property bool $disabled Is a Boolean indicating whether the control is disabled, meaning that it does not accept any clicks.
* @property-read ?Element $form Is a HTMLFormElement reflecting the form that this element is associated with. If the element is a <legend>, if the legend has a fieldset element as its parent, then this attribute returns the same value as the form attribute on the parent fieldset element. Otherwise, it returns null.
* @property-read NodeList $labels Is a NodeList that represents a list of <label> elements that are labels for this HTMLUIElement.
* @property bool $readOnly Returns / Sets the element's readonly attribute, indicating that the user cannot modify the value of the control.
* @property bool $required Returns / Sets the element's required attribute, indicating that the user must fill in a value before submitting a form.
* @property-read bool $willValidate Is a Boolean indicating whether the button is a candidate for constraint validation. It is false if any conditions bar it from constraint validation, including: its type property is reset or button; it has a <datalist> ancestor; or the disabled property is set to true.
* @property-read string $validationMessage Is a DOMString representing the localized message that describes the validation constraints that the control does not satisfy (if any). This attribute is the empty string if the control is not a candidate for constraint validation (willValidate is false), or it satisfies its constraints.
* @property-read ValidityState $validity Is a ValidityState representing the validity states that this button is in.
* @property string $value Is a DOMString representing the current form control value of the HTMLUIElement.
* @property-read ?Element $control Is a HTMLElement representing the control with which the label is associated.
* @property string|DOMTokenList $htmlFor Is a string containing the ID of the labeled control. This reflects the for attribute.
* @property int $height The height HTML attribute of the <canvas> element is a positive integer reflecting the number of logical pixels (or RGBA values) going down one column of the canvas. When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of 150 is used. If no [separate] CSS height is assigned to the <canvas>, then this value will also be used as the height of the canvas in the length-unit CSS Pixel.
* @property int $width The width HTML attribute of the <canvas> element is a positive integer reflecting the number of logical pixels (or RGBA values) going across one row of the canvas. When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of 300 is used. If no [separate] CSS width is assigned to the <canvas>, then this value will also be used as the width of the canvas in the length-unit CSS Pixel.
* @property-read HTMLCollection $options Is a HTMLCollection representing a collection of the contained option elements.
* @property bool $open Is a boolean reflecting the open HTML attribute, indicating whether the element’s contents (not counting the <summary>) is to be shown to the user.
* @property string $returnValue A DOMString that sets or returns the return value for the dialog.
* @property string $accessKey Is a DOMString representing the access key assigned to the element.
* @property-read string $accessKeyLabel Returns a DOMString containing the element's assigned access key.
* @property string $contentEditable Is a DOMString, where a value of true means the element is editable and a value of false means it isn't.
* @property-read bool $isContentEditable Returns a Boolean that indicates whether the content of the element can be edited.
* @property string $dir Is a DOMString, reflecting the dir global attribute, representing the directionality of the element. Possible values are "ltr", "rtl", and "auto".
* @property bool $draggable Is a Boolean indicating if the element can be dragged.
* @property string $enterKeyHint Is a DOMString defining what action label (or icon) to present for the enter key on virtual keyboards.
* @property bool $hidden Is a Boolean indicating if the element is hidden or not.
* @property bool $inert Is a Boolean indicating whether the user agent must act as though the given node is absent for the purposes of user interaction events, in-page text searches ("find in page"), and text selection.
* @property string $innerText Represents the "rendered" text content of a node and its descendants. As a getter, it approximates the text the user would get if they highlighted the contents of the element with the cursor and then copied it to the clipboard.
* @property string $lang Is a DOMString representing the language of an element's attributes, text, and element contents.
* @property int $tabIndex Is a long that represents this element's position in the tabbing order.
* @property string $title Is a DOMString containing the text that appears in a popup box when mouse is over the element.
* @property CSSStyleDeclaration $style Is a CSSStyleDeclaration, an object representing the declarations of an element's style attributes.
* @property-read HTMLCollection|HTMLFormControlsCollection $elements The elements belonging to this parent.
* @property-read int $length A long reflecting the number of controls in the form.
* @property string $method A DOMString reflecting the value of the form's method HTML attribute, indicating the HTTP method used to submit the form. Only specified values can be set.
* @property string $action A DOMString reflecting the value of the form's action HTML attribute, containing the URI of a program that processes the information submitted by the form.
* @property string $encoding A DOMString reflecting the value of the form's enctype HTML attribute, indicating the type of content that is used to transmit the form to the server. Only specified values can be set. The two properties are synonyms.
* @property string $enctype A DOMString reflecting the value of the form's enctype HTML attribute, indicating the type of content that is used to transmit the form to the server. Only specified values can be set. The two properties are synonyms.
* @property string $acceptCharset A DOMString reflecting the value of the form's accept-charset HTML attribute, representing the character encoding that the server accepts.
* @property string $autocomplete A DOMString reflecting the value of the form's autocomplete HTML attribute, indicating whether the controls in this form can have their values automatically populated by the browser.
* @property bool $noValidate A Boolean reflecting the value of the form's novalidate HTML attribute, indicating whether the form should not be validated.
* @property string $autocapitalize Returns / Sets the element's capitalization behavior for user input. Valid values are: none, off, characters, words, sentences.
* @property int $cols Returns / Sets the element's cols attribute, indicating the visible width of the text area.
* @property string $defaultValue Returns / Sets the control's default value, which behaves like the Node.textContent property.
* @property int $maxLength Returns / Sets the element's maxlength attribute, indicating the maximum number of characters the user can enter. This constraint is evaluated only when the value changes.
* @property int $minLength Returns / Sets the element's minlength attribute, indicating the minimum number of characters the user can enter. This constraint is evaluated only when the value changes.
* @property int|HTMLCollection $rows Returns / Sets the element's rows attribute, indicating the number of visible text lines for the control, or if a table, returns an HTMLCollection of all <tr> elements.
* @property string $wrap Returns / Sets the wrap HTML attribute, indicating how the control wraps text.
* @property-read Document $contentDocument Returns a Document, the active document in the inline frame's nested browsing context.
* @property-read Node $contentWindow Returns a WindowProxy, the window proxy for the nested browsing context.
* @property string $srcdoc Is a DOMString that represents the content to display in the frame.
* @property-read bool $complete Returns a Boolean that is true if the browser has finished fetching the image, whether successful or not. That means this value is also true if the image has no src value indicating an image to load.
* @property string $decoding An optional DOMString representing a hint given to the browser on how it should decode the image. If this value is provided, it must be one of the possible permitted values: sync to decode the image synchronously, async to decode it asynchronously, or auto to indicate no preference (which is the default). Read the decoding page for details on the implications of this property's values.
* @property bool $isMap A Boolean that reflects the ismap HTML attribute, indicating that the image is part of a server-side image map. This is different from a client-side image map, specified using an <img> element and a corresponding <map> which contains <area> elements indicating the clickable areas in the image. The image must be contained within an <a> element; see the ismap page for details.
* @property string $loading A DOMString providing a hint to the browser used to optimize loading the document by determining whether to load the image immediately (eager) or on an as-needed basis (lazy).
* @property-read int $naturalHeight Returns an integer value representing the intrinsic height of the image in CSS pixels, if it is available; else, it shows 0. This is the height the image would be if it were rendered at its natural full size.
* @property-read int $naturalWidth An integer value representing the intrinsic width of the image in CSS pixels, if it is available; otherwise, it will show 0. This is the width the image would be if it were rendered at its natural full size.
* @property string $sizes A DOMString reflecting the sizes HTML attribute. This string specifies a list of comma-separated conditional sizes for the image; that is, for a given viewport size, a particular image size is to be used. Read the documentation on the sizes page for details on the format of this string.
* @property string $srcset A USVString reflecting the srcset HTML attribute. This specifies a list of candidate images, separated by commas (',', U+002C COMMA). Each candidate image is a URL followed by a space, followed by a specially-formatted string indicating the size of the image. The size may be specified either the width or a size multiple. Read the srcset page for specifics on the format of the size substring.
* @property string $useMap A DOMString reflecting the usemap HTML attribute, containing the page-local URL of the <map> element describing the image map to use. The page-local URL is a pound (hash) symbol (#) followed by the ID of the <map> element, such as #my-map-element. The <map> in turn contains <area> elements indicating the clickable areas in the image.
* @property-read int $x An integer indicating the horizontal offset of the left border edge of the image's CSS layout box relative to the origin of the <html> element's containing block.
* @property-read int $y The integer vertical offset of the top border edge of the image's CSS layout box relative to the origin of the <html> element's containing block.
* @property bool $defaultChecked Returns / Sets the default state of a radio button or checkbox as originally specified in HTML that created this object.
* @property bool $indeterminate Returns whether the checkbox or radio button is in indeterminate state. For checkboxes, the effect is that the appearance of the checkbox is obscured/greyed in some way as to indicate its state is indeterminate (not checked but not unchecked). Does not affect the value of the checked attribute, and clicking the checkbox will set the value to false.
* Properties that apply only to elements of type `file`:
* @property string $accept Returns / Sets the element's accept attribute, containing comma-separated list of file types accepted by the server when type is file.
* @property FileList $files Returns/accepts a FileList object, which contains a list of File objects representing the files selected for upload.
* @property string $formAction Is a DOMString reflecting the URI of a resource that processes information submitted by the HTMLUIElement. If specified, this attribute overrides the action attribute of the <form> element that owns this element.
* @property string $formEncType Is a DOMString reflecting the type of content that is used to submit the form to the server. If specified, this attribute overrides the enctype attribute of the <form> element that owns this element.
* @property string $formMethod Is a DOMString reflecting the HTTP method that the browser uses to submit the form. If specified, this attribute overrides the method attribute of the <form> element that owns this element.
* @property bool $formNoValidate Is a Boolean indicating that the form is not to be validated when it is submitted. If specified, this attribute overrides the novalidate attribute of the <form> element that owns this element.
* @property string $formTarget Is a DOMString reflecting a name or keyword indicating where to display the response that is received after submitting the form. If specified, this attribute overrides the target attribute of the <form> element that owns this element.
* @property string $max Returns / Sets the element's max attribute, containing the maximum (numeric or date-time) value for this item, which must not be less than its minimum (min attribute) value.
* @property string $min Returns / Sets the element's min attribute, containing the minimum (numeric or date-time) value for this item, which must not be greater than its maximum (max attribute) value.
* @property string $pattern Returns / Sets the element's pattern attribute, containing a regular expression that the control's value is checked against. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is text, search, tel, url or email; otherwise it is ignored.
* @property string $placeholder Returns / Sets the element's placeholder attribute, containing a hint to the user of what can be entered in the control. The placeholder text must not contain carriage returns or line-feeds. This attribute applies when the value of the type attribute is text, search, tel, url or email; otherwise it is ignored.
* @property ?int $size Returns / Sets the element's size attribute, containing visual size of the control. This value is in pixels unless the value of type is text or password, in which case, it is an integer number of characters. Applies only when type is set to text, search, tel, url, email, or password; otherwise it is ignored.
* @property bool $multiple Returns / Sets the element's multiple attribute, indicating whether more than one value is possible (e.g., multiple files).
* @property string $step Returns / Sets the element's step attribute, which works with min and max to limit the increments at which a numeric or date-time value can be set. It can be the string any or a positive floating point number. If this is not set to any, the control accepts only values at multiples of the step value greater than the minimum.
* @property ?DateTimeInterface $valueAsDate Returns / Sets the value of the element, interpreted as a date, or null if conversion is not possible.
* @property int|float|null $valueAsNumber Returns the value of the element, interpreted as one of the following, in order: A time value, A number, NaN if conversion is impossible.
* @property string $inputMode Provides a hint to browsers as to the type of virtual keyboard configuration to use when editing this element or its contents.
* @property string $as Is a DOMString representing the type of content being loaded by the HTML link.
* @property string $media Is a DOMString representing a list of one or more media formats to which the resource applies.
* @property-read StyleSheet $sheet Returns the StyleSheet object associated with the given element, or null if there is none.
* @property-read HTMLCollection $areas Is a live HTMLCollection representing the <area> elements associated to this <map>.
* @property string|DocumentFragment $content Gets or sets the value of meta-data property, or returns the content of a <template> in a DocumentFragment.
* @property string $httpEquiv Gets or sets the name of an HTTP response header to define for a document.
* @property ?float $high A double representing the value of the high boundary, reflecting the high attribute.
* @property ?float $low A double representing the value of the low boundary, reflecting the lowattribute.
* @property ?float $optimum A double representing the optimum, reflecting the optimum attribute.
* @property string $cite Is a DOMString reflecting the cite HTML attribute, containing a URI of a resource explaining the change.
* @property string $dateTime Is a DOMString reflecting the datetime HTML attribute, containing a date-and-time string representing a timestamp for the change.
* @property string $data Returns a DOMString that reflects the data HTML attribute, specifying the address of a resource's data.
* @property bool $typeMustMatch Is a Boolean that reflects the typemustmatch HTML attribute, indicating if the resource specified by data must only be played if it matches the type attribute.
* @property bool $reversed Is a Boolean value reflecting the reversed and defining if the numbering is descending, that is its value is true, or ascending (false).
* @property int $start Is a long value reflecting the start and defining the value of the first number of the first element of the list.
* @property string $label Is a DOMString representing the label for the group.
* @property bool $defaultSelected Is a Boolean that contains the initial value of the selected HTML attribute, indicating whether the option is selected by default or not.
* @property-read int $index Is a long representing the position of the option within the list of options it belongs to, in tree-order. If the option is not part of a list of options, like when it is part of the <datalist> element, the value is 0.
* @property bool $selected Is a Boolean that indicates whether the option is currently selected.
* @property-read DOMStringMap $dataset The dataset read-only property of the HTMLOrForeignElement mixin provides read/write access to custom data attributes (data-*) on elements.
* @property-read float $position Returns a double value returning the result of dividing the current value (value) by the maximum value (max); if the progress bar is an indeterminate progress bar, it returns -1.
* @property bool $async The async and defer attributes are Boolean attributes that control how the script should be executed. The defer and async attributes must not be specified if the src attribute is absent.
* @property bool $defer The async and defer attributes are Boolean attributes that control how the script should be executed. The defer and async attributes must not be specified if the src attribute is absent.
* @property bool $noModule Is a Boolean that if true, stops the script's execution in browsers that support ES2015 modules — used to run fallback scripts in older browsers that do not support JavaScript modules.
* @property int $selectedIndex A long reflecting the index of the first selected <option> element. The value -1 indicates no element is selected.
* @property-read HTMLCollection $selectedOptions An HTMLCollection representing the set of <option> elements that are selected.
* @property string $abbr A DOMString which can be used on <th> elements (not on <td>), specifying an alternative label for the header cell. This alternate label can be used in other contexts, such as when describing the headers that apply to a data cell. This is used to offer a shorter term for use by screen readers in particular, and is a valuable accessibility tool. Usually the value of abbr is an abbreviation or acronym, but can be any text that's appropriate contextually.
* @property-read int $cellIndex A long integer representing the cell's position in the cells collection of the <tr> the cell is contained within. If the cell doesn't belong to a <tr>, it returns -1.
* @property int $colSpan An unsigned long integer indicating the number of columns this cell must span; this lets the cell occupy space across multiple columns of the table. It reflects the colspan attribute.
* @property string $headers Is a DOMSettableTokenList describing a list of id of <th> elements that represents headers associated with the cell. It reflects the headers attribute.
* @property int $rowSpan An unsigned long integer indicating the number of rows this cell must span; this lets a cell occupy space across multiple rows of the table. It reflects the rowspan attribute.
* @property string $scope A DOMString indicating the scope of a <th> cell. Header cells can be configured, using the scope property, the apply to a specified row or column, or to the not-yet-scoped cells within the current row group (that is, the same ancestor <thead>, <tbody>, or <tfoot> element). If no value is specified for scope, the header is not associated directly with cells in this way.
* @property int $span Is an unsigned long that reflects the span HTML attribute, indicating the number of columns to apply this object's attributes to. Must be a positive integer.
* @property ?Element $caption Is a HTMLTableCaptionElement representing the first <caption> that is a child of the element, or null if none is found. When set, if the object doesn't represent a <caption>, a DOMException with the HierarchyRequestError name is thrown. If a correct object is given, it is inserted in the tree as the first child of this element and the first <caption> that is a child of this element is removed from the tree, if any.
* @property ?Element $tHead Is a HTMLTableSectionElement representing the first <thead> that is a child of the element, or null if none is found. When set, if the object doesn't represent a <thead>, a DOMException with the HierarchyRequestError name is thrown. If a correct object is given, it is inserted in the tree immediately before the first element that is neither a <caption>, nor a <colgroup>, or as the last child if there is no such element, and the first <thead> that is a child of this element is removed from the tree, if any.
* @property ?Element $tFoot Is a HTMLTableSectionElement representing the first <tfoot> that is a child of the element, or null if none is found. When set, if the object doesn't represent a <tfoot>, a DOMException with the HierarchyRequestError name is thrown. If a correct object is given, it is inserted in the tree immediately before the first element that is neither a <caption>, a <colgroup>, nor a <thead>, or as the last child if there is no such element, and the first <tfoot> that is a child of this element is removed from the tree, if any.
* @property-read HTMLCollection $tBodies Returns a live HTMLCollection containing all the <tbody> of the element. The HTMLCollection is live and is automatically updated when the HTMLTableElement changes.
* @property-read HTMLCollection $cells Returns a live HTMLCollection containing the cells in the row. The HTMLCollection is live and is automatically updated when cells are added or removed.
* @property-read int $rowIndex Returns a long value which gives the logical position of the row within the entire table. If the row is not part of a table, returns -1.
* @property-read int $sectionRowIndex Returns a long value which gives the logical position of the row within the table section it belongs to. If the row is not part of a section, returns -1.
* @property string $kind Is a DOMString that reflects the kind HTML attribute, indicating how the text track is meant to be used. Possible values are: subtitles, captions, descriptions, chapters, or metadata.
* @property string $srclang Is a DOMString that reflects the srclang HTML attribute, indicating the language of the text track data.
* @property bool $default A Boolean reflecting the default attribute, indicating that the track is to be enabled if the user's preferences do not indicate that another track would be more appropriate.
* @property-read TextTrack $track Returns TextTrack is the track element's text track data.
* @property string $poster Is a DOMString that reflects the poster HTML attribute, which specifies an image to show while no video data is available.
* @property-read int $videoHeight Returns an unsigned integer value indicating the intrinsic height of the resource in CSS pixels, or 0 if no media is available yet.
* @property-read int $videoWidth Returns an unsigned integer value indicating the intrinsic width of the resource in CSS pixels, or 0 if no media is available yet.
*/
trait HTMLElement {
private function allowTypes(ElementType...$typeList):void {
if(!in_array($this->elementType, $typeList)) {
$debug = debug_backtrace(limit: 2);
$function = $debug[1]["function"];
$propName = substr($function, strlen("__prop_get_"));
/** @var Element $object */
$object = $debug[1]["object"];
$actualType = $object->elementType->name;
throw new IncorrectHTMLElementUsageException("Property '$propName' is not available on '$actualType'");
}
}
public function __toString():string {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLAreaElement,
ElementType::HTMLUnknownElement,
);
if($this->elementType === ElementType::HTMLAnchorElement
|| $this->elementType === ElementType::HTMLAreaElement) {
return $this->href;
}
else {
return "";
}
}
// ArrayAccess functions:
public function offsetExists(mixed $offset):bool {
$this->allowTypes(ElementType::HTMLFormElement);
$match = $this->elements->namedItem($offset);
return !is_null($match);
}
public function offsetGet(mixed $offset):null|Element|RadioNodeList {
$this->allowTypes(ElementType::HTMLFormElement);
return $this->elements->namedItem($offset);
}
public function offsetSet(mixed $offset, mixed $value):void {
$this->allowTypes(ElementType::HTMLFormElement);
throw new ArrayAccessReadOnlyException();
}
public function offsetUnset(mixed $offset):void {
$this->allowTypes(ElementType::HTMLFormElement);
throw new ArrayAccessReadOnlyException();
}
// End ArrayAccess functions.
// Countable functions:
public function count():int {
return $this->length;
}
// End Countable functions.
/**
* Builds and returns a URL string from the existing href attribute
* value with the newly supplied overrides.
*/
// phpcs:ignore Generic.Metrics.CyclomaticComplexity
private function buildUrl(
?string $scheme = null,
?string $user = null,
?string $pass = null,
?string $host = null,
?int $port = null,
?string $path = null,
?string $query = null,
?string $fragment = null,
):string {
$existing = parse_url($this->href);
$new = [
"scheme" => $scheme,
"user" => $user,
"pass" => $pass,
"host" => $host,
"port" => $port,
"path" => $path,
"query" => $query,
"fragment" => $fragment,
];
// Remove null new parts.
$new = array_filter($new);
if(isset($new["query"])) {
$new["query"] = ltrim($new["query"], "?");
}
if(isset($new["fragment"])) {
$new["fragment"] = ltrim($new["fragment"], "#");
}
$url = "";
if($addScheme = $new["scheme"] ?? $existing["scheme"] ?? null) {
$url .= "$addScheme://";
}
if($addUser = $new["user"] ?? $existing["user"] ?? null) {
$url .= $addUser;
if($addPass = $new["pass"] ?? $existing["pass"] ?? null) {
$url .= ":$addPass";
}
$url .= "@";
}
if($addHost = $new["host"] ?? $existing["host"] ?? null) {
$url .= $addHost;
}
if($addPort = $new["port"] ?? $existing["port"] ?? null) {
$url .= ":$addPort";
}
if($addPath = $new["path"] ?? $existing["path"] ?? null) {
$url .= $addPath;
}
if($addQuery = $new["query"] ?? $existing["query"] ?? null) {
$url .= "?$addQuery";
}
if($addFrag = $new["fragment"] ?? $existing["fragment"] ?? null) {
$url .= "#$addFrag";
}
return $url;
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/accessKey */
protected function __prop_get_accessKey():string {
return $this->getAttribute("accesskey") ?? "";
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/accessKey */
protected function __prop_set_accessKey(string $value):void {
$this->setAttribute("accesskey", $value);
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/accessKeyLabel */
protected function __prop_get_accessKeyLabel():string {
throw new ClientSideOnlyFunctionalityException();
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/contentEditable */
protected function __prop_get_contentEditable():string {
$attr = $this->getAttribute("contenteditable");
return $attr ?: "inherit";
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/contentEditable */
protected function __prop_set_contentEditable(string $value):void {
switch($value) {
case "true":
case "false":
case "inherit":
$this->setAttribute("contenteditable", $value);
break;
default:
throw new EnumeratedValueException($value);
}
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/dataset */
protected function __prop_get_dataset():DOMStringMap {
return DOMStringMapFactory::createDataset($this);
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/isContentEditable */
protected function __prop_get_isContentEditable():bool {
$attr = $this->getAttribute("contenteditable");
if(!$attr || $attr === "false") {
return false;
}
if($attr === "true") {
return true;
}
$context = $this;
while($parent = $context->parentElement) {
$parentAttr = $parent->getAttribute("contenteditable");
if($parentAttr === "true") {
return true;
}
if($parentAttr === "false") {
return false;
}
$context = $parent;
}
return false;
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dir */
protected function __prop_get_dir():string {
return $this->getAttribute("dir") ?? "";
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dir */
protected function __prop_set_dir(string $value):void {
$this->setAttribute("dir", $value);
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/draggable */
protected function __prop_get_draggable():bool {
$attr = $this->getAttribute("draggable");
return !is_null($attr) && $attr !== "false";
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/draggable */
protected function __prop_set_draggable(bool $value):void {
$strValue = $value ? "true" : "false";
$this->setAttribute("draggable", $strValue);
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/enterKeyHint */
protected function __prop_get_enterKeyHint():string {
return $this->getAttribute("enterkeyhint") ?? "";
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/enterKeyHint */
protected function __prop_set_enterKeyHint(string $value):void {
switch($value) {
case "enter":
case "done":
case "go":
case "next":
case "previous":
case "search":
case "send":
$this->setAttribute("enterkeyhint", $value);
break;
default:
throw new EnumeratedValueException($value);
}
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/hidden */
protected function __prop_get_hidden():bool {
return $this->hasAttribute("hidden");
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/hidden */
protected function __prop_set_hidden(bool $value):void {
if($value) {
$this->setAttribute("hidden", "");
}
else {
$this->removeAttribute("hidden");
}
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert */
protected function __prop_get_inert():bool {
return $this->hasAttribute("inert");
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert */
protected function __prop_set_inert(bool $value):void {
if($value) {
$this->setAttribute("inert", "");
}
else {
$this->removeAttribute("inert");
}
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText */
protected function __prop_get_innerText():string {
$treeWalker = $this->ownerDocument->createTreeWalker(
$this,
NodeFilter::SHOW_TEXT
);
$textArray = [];
foreach($treeWalker as $i => $node) {
if($i === 0) {
// Skip the root node.
continue;
}
/** @var null|Element $parentElement */
$parentElement = $node->parentNode;
$closestHidden = $parentElement?->closest("[hidden]");
if($parentElement
&& $closestHidden) {
continue;
}
array_push($textArray, $node->textContent);
}
return implode("", $textArray);
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText */
protected function __prop_set_innerText(string $value):void {
$this->textContent = $value;
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/lang */
protected function __prop_get_lang():string {
return $this->getAttribute("lang") ?? "";
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/lang */
protected function __prop_set_lang(string $value):void {
$this->setAttribute("lang", $value);
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/title */
protected function __prop_get_title():string {
return $this->getAttribute("title") ?? "";
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/title */
protected function __prop_set_title(string $value):void {
$this->setAttribute("title", $value);
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/tabIndex */
protected function __prop_get_tabIndex():int {
if($this->hasAttribute("tabindex")) {
return (int)$this->getAttribute("tabindex");
}
return -1;
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/tabIndex */
protected function __prop_set_tabIndex(int $tabIndex):void {
$this->setAttribute("tabindex", (string)$tabIndex);
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style */
protected function __prop_get_style():CSSStyleDeclaration {
return new CSSStyleDeclaration();
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style */
protected function __prop_set_style(CSSStyleDeclaration $value):void {
throw new ClientSideOnlyFunctionalityException();
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/hreflang
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/hreflang
*/
protected function __prop_get_hreflang():string {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLLinkElement,
);
return $this->getAttribute("hreflang") ?? "";
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/hreflang
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/hreflang
*/
protected function __prop_set_hreflang(string $value):void {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLLinkElement,
);
$this->setAttribute("hreflang", $value);
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/text
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/text
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/text
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLTitleElement/text
*/
protected function __prop_get_text():string {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLOptionElement,
ElementType::HTMLScriptElement,
ElementType::HTMLTitleElement,
);
return $this->textContent;
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/text
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/text
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/text
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLTitleElement/text
*/
protected function __prop_set_text(string $value):void {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLOptionElement,
ElementType::HTMLScriptElement,
ElementType::HTMLTitleElement,
);
$this->textContent = $value;
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLEmbedElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLFieldSetElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLOListElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLSourceElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement/type
*/
protected function __prop_get_type():string {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLInputElement,
ElementType::HTMLButtonElement,
ElementType::HTMLEmbedElement,
ElementType::HTMLFieldSetElement,
ElementType::HTMLLinkElement,
ElementType::HTMLObjectElement,
ElementType::HTMLOListElement,
ElementType::HTMLScriptElement,
ElementType::HTMLSourceElement,
ElementType::HTMLStyleElement,
);
if($this->elementType === ElementType::HTMLFieldSetElement) {
return "fieldset";
}
return $this->getAttribute("type") ?? "";
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLEmbedElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLFieldSetElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLOListElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLSourceElement/type
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement/type
*/
protected function __prop_set_type(string $value):void {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLInputElement,
ElementType::HTMLButtonElement,
ElementType::HTMLEmbedElement,
ElementType::HTMLFieldSetElement,
ElementType::HTMLLinkElement,
ElementType::HTMLObjectElement,
ElementType::HTMLOListElement,
ElementType::HTMLScriptElement,
ElementType::HTMLSourceElement,
ElementType::HTMLStyleElement,
);
$this->setAttribute("type", $value);
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLMapElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLMetaElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLParamElement/name
*/
protected function __prop_get_name():string {
$this->allowTypes(
ElementType::HTMLInputElement,
ElementType::HTMLSelectElement,
ElementType::HTMLOptionElement,
ElementType::HTMLButtonElement,
ElementType::HTMLFormElement,
ElementType::HTMLTextAreaElement,
ElementType::HTMLIFrameElement,
ElementType::HTMLMapElement,
ElementType::HTMLMetaElement,
ElementType::HTMLObjectElement,
ElementType::HTMLParamElement,
);
return $this->getAttribute("name") ?? "";
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLMapElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLMetaElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/name
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLParamElement/name
*/
protected function __prop_set_name(string $value):void {
$this->allowTypes(
ElementType::HTMLInputElement,
ElementType::HTMLSelectElement,
ElementType::HTMLOptionElement,
ElementType::HTMLButtonElement,
ElementType::HTMLFormElement,
ElementType::HTMLTextAreaElement,
ElementType::HTMLIFrameElement,
ElementType::HTMLMapElement,
ElementType::HTMLMetaElement,
ElementType::HTMLObjectElement,
ElementType::HTMLParamElement,
);
$this->setAttribute("name", $value);
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLDataElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLLiElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLMeterElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLParamElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLProgressElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/value
*/
protected function __prop_get_value():string {
$this->allowTypes(
ElementType::HTMLInputElement,
ElementType::HTMLButtonElement,
ElementType::HTMLDataElement,
ElementType::HTMLOptionElement,
ElementType::HTMLTextAreaElement,
ElementType::HTMLLiElement,
ElementType::HTMLMeterElement,
ElementType::HTMLOutputElement,
ElementType::HTMLParamElement,
ElementType::HTMLProgressElement,
ElementType::HTMLSelectElement,
);
$value = $this->getAttribute("value");
if(!is_null($value)) {
return $value;
}
if($this->elementType === ElementType::HTMLSelectElement) {
if($this->selectedIndex === -1) {
return "";
}
return $this->options[$this->selectedIndex]->value;
}
elseif($this->elementType === ElementType::HTMLTextAreaElement) {
return $this->nodeValue;
}
return $this->textContent;
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLDataElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLLiElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLMeterElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLParamElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLProgressElement/value
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/value
*/
protected function __prop_set_value(string $value):void {
$this->allowTypes(
ElementType::HTMLInputElement,
ElementType::HTMLButtonElement,
ElementType::HTMLDataElement,
ElementType::HTMLOptionElement,
ElementType::HTMLTextAreaElement,
ElementType::HTMLLiElement,
ElementType::HTMLMeterElement,
ElementType::HTMLOutputElement,
ElementType::HTMLParamElement,
ElementType::HTMLProgressElement,
ElementType::HTMLSelectElement,
);
if($this->elementType === ElementType::HTMLSelectElement) {
foreach($this->options as $option) {
if($option->value === $value) {
$option->selected = true;
}
else {
$option->selected = false;
}
}
}
elseif($this->elementType === ElementType::HTMLTextAreaElement) {
$this->nodeValue = $value;
}
else {
$this->setAttribute("value", $value);
}
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#checked */
protected function __prop_get_checked():bool {
$this->allowTypes(ElementType::HTMLInputElement);
return $this->hasAttribute("checked");
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#checked */
protected function __prop_set_checked(bool $value):void {
$this->allowTypes(ElementType::HTMLInputElement);
if($value) {
$this->setAttribute("checked", "");
}
else {
$this->removeAttribute("checked");
}
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/href
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAreaElement/href
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLBaseElement/href
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/href
*/
protected function __prop_get_href():string {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLAreaElement,
ElementType::HTMLBaseElement,
ElementType::HTMLLinkElement,
);
return $this->getAttribute("href") ?? "";
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/href
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAreaElement/href
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLBaseElement/href
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/href
*/
protected function __prop_set_href(string $value):void {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLAreaElement,
ElementType::HTMLBaseElement,
ElementType::HTMLLinkElement,
);
$this->setAttribute("href", $value);
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/download
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAreaElement/download
*/
protected function __prop_get_download():string {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLAreaElement,
);
return $this->getAttribute("download") ?? "";
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/download
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAreaElement/download
*/
protected function __prop_set_download(string $value):void {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLAreaElement,
);
$this->setAttribute("download", $value);
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/hash
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAreaElement/hash
*/
protected function __prop_get_hash():string {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLAreaElement,
);
if($hash = parse_url($this->href, PHP_URL_FRAGMENT)) {
return "#$hash";
}
return "";
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/hash
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAreaElement/hash
*/
protected function __prop_set_hash(string $value):void {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLAreaElement,
);
$this->href = $this->buildUrl(
fragment: $value
);
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/host
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAreaElement/host
*/
protected function __prop_get_host():string {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLAreaElement,
);
if($host = parse_url($this->href, PHP_URL_HOST)) {
$port = parse_url($this->href, PHP_URL_PORT);
if($port) {
return "$host:$port";
}
return $host;
}
return "";
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/host
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAreaElement/host
*/
protected function __prop_set_host(string $value):void {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLAreaElement,
);
$newHost = strtok($value, ":");
$newPort = parse_url($value, PHP_URL_PORT);
$this->href = $this->buildUrl(
host: $newHost,
port: $newPort
);
}
/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/hostname
* @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAreaElement/hostname
* @noinspection PhpArrayShapeAttributeCanBeAddedInspection
*/
protected function __prop_get_hostname():string {
$this->allowTypes(
ElementType::HTMLAnchorElement,
ElementType::HTMLAreaElement,
);
return parse_url($this->href, PHP_URL_HOST);
}
/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/hostname */