Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit 88dc507

Browse files
committed
Move RegExpObject\Flags constants under RegExpObject, closes #64
1 parent 371b354 commit 88dc507

7 files changed

+48
-79
lines changed

src/php_v8_regexp.cc

+7-18
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "php_v8.h"
2323

2424
zend_class_entry *php_v8_regexp_class_entry;
25-
zend_class_entry *php_v8_regexp_flags_class_entry;
2625

2726
#define this_ce php_v8_regexp_class_entry
2827

@@ -103,29 +102,19 @@ static const zend_function_entry php_v8_regexp_methods[] = {
103102
PHP_FE_END
104103
};
105104

106-
static const zend_function_entry php_v8_regexp_flags_methods[] = {
107-
PHP_FE_END
108-
};
109105

110106
PHP_MINIT_FUNCTION(php_v8_regexp) {
111107
zend_class_entry ce;
112108
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "RegExpObject", php_v8_regexp_methods);
113109
this_ce = zend_register_internal_class_ex(&ce, php_v8_object_class_entry);
114110

115-
#undef this_ce
116-
#define this_ce php_v8_regexp_flags_class_entry
117-
118-
INIT_NS_CLASS_ENTRY(ce, "V8\\RegExpObject", "Flags", php_v8_regexp_flags_methods);
119-
this_ce = zend_register_internal_class(&ce);
120-
this_ce->ce_flags |= ZEND_ACC_FINAL;
121-
122-
zend_declare_class_constant_long(this_ce, ZEND_STRL("NONE"), v8::RegExp::Flags::kNone);
123-
zend_declare_class_constant_long(this_ce, ZEND_STRL("GLOBAL"), v8::RegExp::Flags::kGlobal);
124-
zend_declare_class_constant_long(this_ce, ZEND_STRL("IGNORE_CASE"), v8::RegExp::Flags::kIgnoreCase);
125-
zend_declare_class_constant_long(this_ce, ZEND_STRL("MULTILINE"), v8::RegExp::Flags::kMultiline);
126-
zend_declare_class_constant_long(this_ce, ZEND_STRL("STICKY"), v8::RegExp::Flags::kSticky);
127-
zend_declare_class_constant_long(this_ce, ZEND_STRL("UNICODE"), v8::RegExp::Flags::kUnicode);
128-
zend_declare_class_constant_long(this_ce, ZEND_STRL("DOTALL"), v8::RegExp::Flags::kDotAll);
111+
zend_declare_class_constant_long(this_ce, ZEND_STRL("FLAG_NONE"), v8::RegExp::Flags::kNone);
112+
zend_declare_class_constant_long(this_ce, ZEND_STRL("FLAG_GLOBAL"), v8::RegExp::Flags::kGlobal);
113+
zend_declare_class_constant_long(this_ce, ZEND_STRL("FLAG_IGNORE_CASE"), v8::RegExp::Flags::kIgnoreCase);
114+
zend_declare_class_constant_long(this_ce, ZEND_STRL("FLAG_MULTILINE"), v8::RegExp::Flags::kMultiline);
115+
zend_declare_class_constant_long(this_ce, ZEND_STRL("FLAG_STICKY"), v8::RegExp::Flags::kSticky);
116+
zend_declare_class_constant_long(this_ce, ZEND_STRL("FLAG_UNICODE"), v8::RegExp::Flags::kUnicode);
117+
zend_declare_class_constant_long(this_ce, ZEND_STRL("FLAG_DOTALL"), v8::RegExp::Flags::kDotAll);
129118

130119
return SUCCESS;
131120
}

src/php_v8_regexp.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@ extern "C" {
2525
}
2626

2727
extern zend_class_entry* php_v8_regexp_class_entry;
28-
extern zend_class_entry* php_v8_regexp_flags_class_entry;
2928

3029

31-
#define PHP_V8_REGEXP_FLAGS (v8::RegExp::Flags::kNone | v8::RegExp::Flags::kGlobal | v8::RegExp::Flags::kIgnoreCase | v8::RegExp::Flags::kMultiline | v8::RegExp::Flags::kSticky | v8::RegExp::Flags::kUnicode)
30+
#define PHP_V8_REGEXP_FLAGS ( 0 \
31+
| v8::RegExp::Flags::kNone \
32+
| v8::RegExp::Flags::kGlobal \
33+
| v8::RegExp::Flags::kIgnoreCase \
34+
| v8::RegExp::Flags::kMultiline \
35+
| v8::RegExp::Flags::kSticky \
36+
| v8::RegExp::Flags::kUnicode \
37+
| v8::RegExp::Flags::kDotAll \
38+
)
3239

3340

3441
PHP_MINIT_FUNCTION(php_v8_regexp);

stubs/src/RegExp/Flags.php

-28
This file was deleted.

stubs/src/RegExpObject.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@
1818

1919
class RegExpObject extends ObjectValue
2020
{
21+
const FLAG_NONE = 0;
22+
const FLAG_GLOBAL = 1;
23+
const FLAG_IGNORE_CASE = 2;
24+
const FLAG_MULTILINE = 4;
25+
const FLAG_STICKY = 8;
26+
const FLAG_UNICODE = 16;
27+
const FLAG_DOTALL = 32;
2128

2229
/**
2330
* @param \V8\Context $context
2431
* @param StringValue $pattern
2532
* @param int $flags
2633
*/
27-
public function __construct(Context $context, StringValue $pattern, int $flags = RegExpObject\Flags::NONE)
34+
public function __construct(Context $context, StringValue $pattern, int $flags = RegExpObject::FLAG_NONE)
2835
{
2936
parent::__construct($context);
3037
}

tests/001-verify_extension_entities.phpt

+7-9
Original file line numberDiff line numberDiff line change
@@ -759,19 +759,17 @@ class V8\DateObject
759759
class V8\RegExpObject
760760
extends V8\ObjectValue
761761
implements V8\AdjustableExternalMemoryInterface
762+
const FLAG_NONE = 0
763+
const FLAG_GLOBAL = 1
764+
const FLAG_IGNORE_CASE = 2
765+
const FLAG_MULTILINE = 4
766+
const FLAG_STICKY = 8
767+
const FLAG_UNICODE = 16
768+
const FLAG_DOTALL = 32
762769
public function __construct(V8\Context $context, V8\StringValue $context, ?int $flags)
763770
public function getSource(): V8\StringValue
764771
public function getFlags(): int
765772

766-
final class V8\RegExpObject\Flags
767-
const NONE = 0
768-
const GLOBAL = 1
769-
const IGNORE_CASE = 2
770-
const MULTILINE = 4
771-
const STICKY = 8
772-
const UNICODE = 16
773-
const DOTALL = 32
774-
775773
class V8\PromiseObject
776774
extends V8\ObjectValue
777775
implements V8\AdjustableExternalMemoryInterface

tests/002-enums.phpt

+1-20
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ $enums = [
1919
new V8\PropertyFilter(),
2020
new V8\KeyCollectionMode(),
2121
new V8\IndexFilter(),
22-
new V8\RegExpObject\Flags(),
2322
new V8\ScriptCompiler\CompileOptions(),
2423
];
2524

@@ -155,25 +154,7 @@ V8\IndexFilter::SKIP_INDICES = 1
155154
Object representation:
156155
----------------------
157156
Class is final: ok
158-
object(V8\RegExpObject\Flags)#10 (0) {
159-
}
160-
161-
162-
Class constants:
163-
----------------
164-
V8\RegExpObject\Flags::NONE = 0
165-
V8\RegExpObject\Flags::GLOBAL = 1
166-
V8\RegExpObject\Flags::IGNORE_CASE = 2
167-
V8\RegExpObject\Flags::MULTILINE = 4
168-
V8\RegExpObject\Flags::STICKY = 8
169-
V8\RegExpObject\Flags::UNICODE = 16
170-
V8\RegExpObject\Flags::DOTALL = 32
171-
172-
173-
Object representation:
174-
----------------------
175-
Class is final: ok
176-
object(V8\ScriptCompiler\CompileOptions)#11 (0) {
157+
object(V8\ScriptCompiler\CompileOptions)#10 (0) {
177158
}
178159

179160

tests/RegExpObject.phpt

+16-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $isolate = new \V8\Isolate();
1919
$context = new V8\Context($isolate);
2020
$v8_helper->injectConsoleLog($context);
2121

22-
$value = new V8\RegExpObject($context, new \V8\StringValue($isolate, '([a-z]{1,4})-([0-9]+)'), \V8\RegExpObject\Flags::IGNORE_CASE);
22+
$value = new V8\RegExpObject($context, new \V8\StringValue($isolate, '([a-z]{1,4})-([0-9]+)'), \V8\RegExpObject::FLAG_IGNORE_CASE);
2323

2424
$helper->header('Object representation');
2525
$helper->dump($value);
@@ -28,6 +28,10 @@ $helper->space();
2828
$helper->assert('RegExpObject extends ObjectValue', $value instanceof \V8\ObjectValue);
2929
$helper->line();
3030

31+
$helper->header('Getters');
32+
$helper->dump_object_constants($value);
33+
$helper->space();
34+
3135
$helper->header('Getters');
3236
$helper->pretty_dump(get_class($value) . '->getSource()->value()', $value->getSource()->value());
3337
$helper->method_export($value, 'getFlags');
@@ -75,6 +79,17 @@ object(V8\RegExpObject)#6 (2) {
7579

7680
RegExpObject extends ObjectValue: ok
7781

82+
Getters:
83+
--------
84+
V8\RegExpObject::FLAG_NONE = 0
85+
V8\RegExpObject::FLAG_GLOBAL = 1
86+
V8\RegExpObject::FLAG_IGNORE_CASE = 2
87+
V8\RegExpObject::FLAG_MULTILINE = 4
88+
V8\RegExpObject::FLAG_STICKY = 8
89+
V8\RegExpObject::FLAG_UNICODE = 16
90+
V8\RegExpObject::FLAG_DOTALL = 32
91+
92+
7893
Getters:
7994
--------
8095
V8\RegExpObject->getSource()->value(): string(21) "([a-z]{1,4})-([0-9]+)"

0 commit comments

Comments
 (0)