35
35
#define zendcursor LANG_SCNG(yy_cursor)
36
36
#define zendlimit LANG_SCNG(yy_limit)
37
37
38
- #define TOKEN_PARSE (1 << 0)
39
- #define TOKEN_AS_OBJECT (1 << 1)
38
+ #define TOKEN_PARSE (1 << 0)
40
39
41
40
zend_class_entry * php_token_ce ;
42
41
43
42
void tokenizer_token_get_all_register_constants (INIT_FUNC_ARGS ) {
44
43
REGISTER_LONG_CONSTANT ("TOKEN_PARSE" , TOKEN_PARSE , CONST_CS |CONST_PERSISTENT );
45
- REGISTER_LONG_CONSTANT ("TOKEN_AS_OBJECT" , TOKEN_AS_OBJECT , CONST_CS |CONST_PERSISTENT );
46
44
}
47
45
48
46
/* {{{ tokenizer_functions[]
@@ -102,6 +100,25 @@ static zval *php_token_get_text(zval *obj) {
102
100
return text ;
103
101
}
104
102
103
+ static zend_bool tokenize_common (
104
+ zval * return_value , zend_string * source , zend_long flags , zend_bool as_object );
105
+
106
+ PHP_METHOD (PhpToken , getAll )
107
+ {
108
+ zend_string * source ;
109
+ zend_long flags = 0 ;
110
+
111
+ ZEND_PARSE_PARAMETERS_START (1 , 2 )
112
+ Z_PARAM_STR (source )
113
+ Z_PARAM_OPTIONAL
114
+ Z_PARAM_LONG (flags )
115
+ ZEND_PARSE_PARAMETERS_END ();
116
+
117
+ if (tokenize_common (return_value , source , flags , /* as_object */ 1 ) == FAILURE ) {
118
+ RETURN_THROWS ();
119
+ }
120
+ }
121
+
105
122
PHP_METHOD (PhpToken , is )
106
123
{
107
124
zval * kind ;
@@ -190,6 +207,7 @@ PHP_METHOD(PhpToken, getTokenName)
190
207
}
191
208
192
209
static const zend_function_entry php_token_methods [] = {
210
+ PHP_ME (PhpToken , getAll , arginfo_class_PhpToken_getAll , ZEND_ACC_PUBLIC |ZEND_ACC_STATIC )
193
211
PHP_ME (PhpToken , is , arginfo_class_PhpToken_is , ZEND_ACC_PUBLIC )
194
212
PHP_ME (PhpToken , isIgnorable , arginfo_class_PhpToken_isIgnorable , ZEND_ACC_PUBLIC )
195
213
PHP_ME (PhpToken , getTokenName , arginfo_class_PhpToken_getTokenName , ZEND_ACC_PUBLIC )
@@ -421,6 +439,19 @@ static zend_bool tokenize_parse(zval *return_value, zend_string *source, zend_bo
421
439
return success ;
422
440
}
423
441
442
+ static zend_bool tokenize_common (
443
+ zval * return_value , zend_string * source , zend_long flags , zend_bool as_object )
444
+ {
445
+ if (flags & TOKEN_PARSE ) {
446
+ return tokenize_parse (return_value , source , as_object );
447
+ } else {
448
+ int success = tokenize (return_value , source , as_object );
449
+ /* Normal token_get_all() should not throw. */
450
+ zend_clear_exception ();
451
+ return success ;
452
+ }
453
+ }
454
+
424
455
/* }}} */
425
456
426
457
/* {{{ proto array token_get_all(string source [, int flags])
@@ -429,23 +460,14 @@ PHP_FUNCTION(token_get_all)
429
460
{
430
461
zend_string * source ;
431
462
zend_long flags = 0 ;
432
- zend_bool success ;
433
463
434
464
ZEND_PARSE_PARAMETERS_START (1 , 2 )
435
465
Z_PARAM_STR (source )
436
466
Z_PARAM_OPTIONAL
437
467
Z_PARAM_LONG (flags )
438
468
ZEND_PARSE_PARAMETERS_END ();
439
469
440
- if (flags & TOKEN_PARSE ) {
441
- success = tokenize_parse (return_value , source , (flags & TOKEN_AS_OBJECT ) != 0 );
442
- } else {
443
- success = tokenize (return_value , source , (flags & TOKEN_AS_OBJECT ) != 0 );
444
- /* Normal token_get_all() should not throw. */
445
- zend_clear_exception ();
446
- }
447
-
448
- if (!success ) {
470
+ if (tokenize_common (return_value , source , flags , /* as_object */ 0 ) == FAILURE ) {
449
471
RETURN_THROWS ();
450
472
}
451
473
}
0 commit comments