Skip to content

Commit 0719766

Browse files
committed
Use interfaces (instead of classes) for enumerations
Also update WebIDL.md to describe enumeration types better. Change-Id: I2bb0d4da076a8aaf9260150ec35c349a45429c8a
1 parent 2ae975a commit 0719766

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# IDLeDOM x.x.x (not yet released)
2+
* Use interface (instead of class) for enumerations. This allows
3+
DOM implementations to easily define a class implementing the interface
4+
to bring the constants into the implementation's namespace.
25

36
# IDLeDOM 0.2.0 (2021-02-12)
47
* Strip explicit PHP type hints for DOM interface types, in order to

WebIDL.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ type])(https://www.php.net/manual/en/language.types.object.php).
228228

229229
The IDL [`symbol`] type is not supported.
230230

231+
### Enumerations
232+
233+
IDL [enumeration](https://heycam.github.io/webidl/#idl-enums) types
234+
correspond to the PHP `int` type. (There is a PHP interface created
235+
to hold the enumeration values as class constants, but enumeration
236+
values are `int`s, not objects implementing this interface.)
237+
231238
## Objects implementing interfaces
232239

233240
A PHP object that implements an IDL [interface] must be of a PHP class

src/ShadowRootMode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @phan-forbid-undeclared-magic-properties
1414
*/
15-
class ShadowRootMode {
15+
interface ShadowRootMode {
1616
public const open = 0;
1717
public const closed = 1;
1818
}

tools/InterfaceBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ protected function emitCallback( string $topName, array $def ): void {
258258

259259
/** @inheritDoc */
260260
protected function emitEnum( string $topName, array $def ): void {
261-
$this->firstLine( 'class', $topName, $def );
261+
$this->firstLine( 'interface', $topName, $def );
262262
// Treat enumerations like interfaces with const members
263263
$val = 0;
264264
foreach ( $def['values'] as $m ) {

0 commit comments

Comments
 (0)