@@ -101,20 +101,22 @@ static zval *php_token_get_text(zval *obj) {
101
101
}
102
102
103
103
static zend_bool tokenize_common (
104
- zval * return_value , zend_string * source , zend_long flags , zend_bool as_object );
104
+ zval * return_value , zend_string * source , zend_long flags , zend_class_entry * token_class );
105
105
106
106
PHP_METHOD (PhpToken , getAll )
107
107
{
108
108
zend_string * source ;
109
109
zend_long flags = 0 ;
110
+ zend_class_entry * token_class ;
110
111
111
112
ZEND_PARSE_PARAMETERS_START (1 , 2 )
112
113
Z_PARAM_STR (source )
113
114
Z_PARAM_OPTIONAL
114
115
Z_PARAM_LONG (flags )
115
116
ZEND_PARSE_PARAMETERS_END ();
116
117
117
- if (tokenize_common (return_value , source , flags , /* as_object */ 1 ) == FAILURE ) {
118
+ token_class = zend_get_called_scope (execute_data );
119
+ if (tokenize_common (return_value , source , flags , token_class ) == FAILURE ) {
118
120
RETURN_THROWS ();
119
121
}
120
122
}
@@ -231,7 +233,7 @@ PHP_METHOD(PhpToken, getTokenName)
231
233
232
234
static const zend_function_entry php_token_methods [] = {
233
235
PHP_ME (PhpToken , getAll , arginfo_class_PhpToken_getAll , ZEND_ACC_PUBLIC |ZEND_ACC_STATIC )
234
- PHP_ME (PhpToken , __construct , arginfo_class_PhpToken___construct , ZEND_ACC_PUBLIC )
236
+ PHP_ME (PhpToken , __construct , arginfo_class_PhpToken___construct , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
235
237
PHP_ME (PhpToken , is , arginfo_class_PhpToken_is , ZEND_ACC_PUBLIC )
236
238
PHP_ME (PhpToken , isIgnorable , arginfo_class_PhpToken_isIgnorable , ZEND_ACC_PUBLIC )
237
239
PHP_ME (PhpToken , getTokenName , arginfo_class_PhpToken_getTokenName , ZEND_ACC_PUBLIC )
@@ -296,10 +298,10 @@ static inline zend_string *make_str(unsigned char *text, size_t leng) {
296
298
}
297
299
298
300
static void add_token (zval * return_value , int token_type ,
299
- unsigned char * text , size_t leng , int lineno , zend_bool as_object ) {
301
+ unsigned char * text , size_t leng , int lineno , zend_class_entry * token_class ) {
300
302
zval token ;
301
- if (as_object ) {
302
- zend_object * obj = zend_objects_new (php_token_ce );
303
+ if (token_class ) {
304
+ zend_object * obj = zend_objects_new (token_class );
303
305
ZVAL_OBJ (& token , obj );
304
306
ZVAL_LONG (OBJ_PROP_NUM (obj , 0 ), token_type );
305
307
ZVAL_STR (OBJ_PROP_NUM (obj , 1 ), make_str (text , leng ));
@@ -316,7 +318,7 @@ static void add_token(zval *return_value, int token_type,
316
318
zend_hash_next_index_insert_new (Z_ARRVAL_P (return_value ), & token );
317
319
}
318
320
319
- static zend_bool tokenize (zval * return_value , zend_string * source , zend_bool as_object )
321
+ static zend_bool tokenize (zval * return_value , zend_string * source , zend_class_entry * token_class )
320
322
{
321
323
zval source_zval ;
322
324
zend_lex_state original_lex_state ;
@@ -337,7 +339,7 @@ static zend_bool tokenize(zval *return_value, zend_string *source, zend_bool as_
337
339
array_init (return_value );
338
340
339
341
while ((token_type = lex_scan (& token , NULL ))) {
340
- add_token (return_value , token_type , zendtext , zendleng , token_line , as_object );
342
+ add_token (return_value , token_type , zendtext , zendleng , token_line , token_class );
341
343
342
344
if (Z_TYPE (token ) != IS_UNDEF ) {
343
345
zval_ptr_dtor_nogc (& token );
@@ -353,7 +355,7 @@ static zend_bool tokenize(zval *return_value, zend_string *source, zend_bool as_
353
355
/* fetch the rest into a T_INLINE_HTML */
354
356
if (zendcursor != zendlimit ) {
355
357
add_token (return_value , T_INLINE_HTML ,
356
- zendcursor , zendlimit - zendcursor , token_line , as_object );
358
+ zendcursor , zendlimit - zendcursor , token_line , token_class );
357
359
}
358
360
break ;
359
361
}
@@ -377,7 +379,7 @@ static zend_bool tokenize(zval *return_value, zend_string *source, zend_bool as_
377
379
378
380
struct event_context {
379
381
zval * tokens ;
380
- zend_bool as_object ;
382
+ zend_class_entry * token_class ;
381
383
};
382
384
383
385
void on_event (zend_php_scanner_event event , int token , int line , void * context )
@@ -396,7 +398,7 @@ void on_event(zend_php_scanner_event event, int token, int line, void *context)
396
398
token = T_OPEN_TAG_WITH_ECHO ;
397
399
}
398
400
add_token (ctx -> tokens , token ,
399
- LANG_SCNG (yy_text ), LANG_SCNG (yy_leng ), line , ctx -> as_object );
401
+ LANG_SCNG (yy_text ), LANG_SCNG (yy_leng ), line , ctx -> token_class );
400
402
break ;
401
403
case ON_FEEDBACK :
402
404
tokens_ht = Z_ARRVAL_P (ctx -> tokens );
@@ -411,13 +413,14 @@ void on_event(zend_php_scanner_event event, int token, int line, void *context)
411
413
case ON_STOP :
412
414
if (LANG_SCNG (yy_cursor ) != LANG_SCNG (yy_limit )) {
413
415
add_token (ctx -> tokens , T_INLINE_HTML , LANG_SCNG (yy_cursor ),
414
- LANG_SCNG (yy_limit ) - LANG_SCNG (yy_cursor ), CG (zend_lineno ), ctx -> as_object );
416
+ LANG_SCNG (yy_limit ) - LANG_SCNG (yy_cursor ), CG (zend_lineno ), ctx -> token_class );
415
417
}
416
418
break ;
417
419
}
418
420
}
419
421
420
- static zend_bool tokenize_parse (zval * return_value , zend_string * source , zend_bool as_object )
422
+ static zend_bool tokenize_parse (
423
+ zval * return_value , zend_string * source , zend_class_entry * token_class )
421
424
{
422
425
zval source_zval ;
423
426
zend_lex_state original_lex_state ;
@@ -436,7 +439,7 @@ static zend_bool tokenize_parse(zval *return_value, zend_string *source, zend_bo
436
439
array_init (& token_stream );
437
440
438
441
ctx .tokens = & token_stream ;
439
- ctx .as_object = as_object ;
442
+ ctx .token_class = token_class ;
440
443
441
444
CG (ast ) = NULL ;
442
445
CG (ast_arena ) = zend_arena_create (1024 * 32 );
@@ -464,12 +467,12 @@ static zend_bool tokenize_parse(zval *return_value, zend_string *source, zend_bo
464
467
}
465
468
466
469
static zend_bool tokenize_common (
467
- zval * return_value , zend_string * source , zend_long flags , zend_bool as_object )
470
+ zval * return_value , zend_string * source , zend_long flags , zend_class_entry * token_class )
468
471
{
469
472
if (flags & TOKEN_PARSE ) {
470
- return tokenize_parse (return_value , source , as_object );
473
+ return tokenize_parse (return_value , source , token_class );
471
474
} else {
472
- int success = tokenize (return_value , source , as_object );
475
+ int success = tokenize (return_value , source , token_class );
473
476
/* Normal token_get_all() should not throw. */
474
477
zend_clear_exception ();
475
478
return success ;
@@ -491,7 +494,7 @@ PHP_FUNCTION(token_get_all)
491
494
Z_PARAM_LONG (flags )
492
495
ZEND_PARSE_PARAMETERS_END ();
493
496
494
- if (tokenize_common (return_value , source , flags , /* as_object */ 0 ) == FAILURE ) {
497
+ if (tokenize_common (return_value , source , flags , /* token_class */ NULL ) == FAILURE ) {
495
498
RETURN_THROWS ();
496
499
}
497
500
}
0 commit comments