forked from laruence/yaf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yaf_view_simple.c
executable file
·703 lines (575 loc) · 19.1 KB
/
yaf_view_simple.c
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
/*
+----------------------------------------------------------------------+
| Yet Another Framework |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Xinchen Hui <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "main/php_output.h"
#include "Zend/zend_interfaces.h" /* for zend_class_serialize_deny */
#include "php_yaf.h"
#include "yaf_namespace.h"
#include "yaf_exception.h"
#include "yaf_loader.h"
#include "yaf_request.h"
#include "yaf_view.h"
#include "views/yaf_view_interface.h"
#include "views/yaf_view_simple.h"
zend_class_entry *yaf_view_simple_ce;
static zend_object_handlers yaf_view_simple_obj_handlers;
/** {{{ ARG_INFO */
ZEND_BEGIN_ARG_INFO_EX(yaf_view_simple_construct_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, template_dir)
ZEND_ARG_ARRAY_INFO(0, options, 1)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO_EX(yaf_view_simple_get_arginfo, 0, 0, 0)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(yaf_view_simple_isset_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO_EX(yaf_view_simple_assign_by_ref_arginfo, 0, 0, 2)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(1, value)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO_EX(yaf_view_simple_eval_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, tpl_str)
ZEND_ARG_INFO(0, vars)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO_EX(yaf_view_simple_clear_arginfo, 0, 0, 0)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO();
/* }}} */
static HashTable *yaf_view_simple_get_properties(yaf_object *obj) /* {{{ */ {
zval rv;
HashTable *ht;
yaf_view_object *view = php_yaf_view_fetch_object(yaf_strip_obj(obj));
if (!view->properties) {
ALLOC_HASHTABLE(view->properties);
zend_hash_init(view->properties, 2, NULL, ZVAL_PTR_DTOR, 0);
YAF_ALLOW_VIOLATION(view->properties);
}
ht = view->properties;
if (view->tpl_dir) {
ZVAL_STR_COPY(&rv, view->tpl_dir);
} else {
ZVAL_NULL(&rv);
}
zend_hash_str_update(ht, "tpl_dir:protected", sizeof("tpl_dir:protected") - 1, &rv);
ZVAL_ARR(&rv, zend_array_dup(&view->tpl_vars));
zend_hash_str_update(ht, "tpl_vars:protected", sizeof("tpl_vars:protected") - 1, &rv);
return ht;
}
/* }}} */
static zval* yaf_view_simple_read_property(yaf_object *obj, void *name, int type, void **cache_slot, zval *rv) /* {{{ */ {
zval *var;
zend_string *member;
yaf_view_object *view = php_yaf_view_fetch_object(yaf_strip_obj(obj));
#if PHP_VERSION_ID < 80000
if (UNEXPECTED(Z_TYPE_P((zval*)name) != IS_STRING)) {
return &EG(uninitialized_zval);
}
member = Z_STR_P((zval*)name);
#else
member = (zend_string*)name;
#endif
if ((var = zend_hash_find(&view->tpl_vars, member))) {
return var;
}
return &EG(uninitialized_zval);
}
/* }}} */
static YAF_WRITE_HANDLER yaf_view_simple_write_property(yaf_object *obj, void *name, zval *value, void **cache_slot) /* {{{ */ {
zend_string *member;
yaf_view_object *view = php_yaf_view_fetch_object(yaf_strip_obj(obj));
#if PHP_VERSION_ID < 80000
if (UNEXPECTED(Z_TYPE_P((zval*)name) != IS_STRING)) {
YAF_WHANDLER_RET(value);
}
member = Z_STR_P((zval*)name);
#else
member = (zend_string*)name;
#endif
zend_hash_update(&view->tpl_vars, member, value);
Z_TRY_ADDREF_P(value);
YAF_WHANDLER_RET(value);
}
/* }}} */
static zend_object *yaf_view_simple_new(zend_class_entry *ce) /* {{{ */ {
yaf_view_object *view = emalloc(sizeof(yaf_view_object) + zend_object_properties_size(ce));
zend_object_std_init(&view->std, ce);
view->std.handlers = &yaf_view_simple_obj_handlers;
view->tpl_dir = NULL;
zend_hash_init(&view->tpl_vars, 8, NULL, ZVAL_PTR_DTOR, 0);
view->properties = NULL;
return &view->std;
}
/* }}} */
static void yaf_view_object_free(zend_object *object) /* {{{ */ {
yaf_view_object *view = php_yaf_view_fetch_object(object);
if (view->tpl_dir) {
zend_string_release(view->tpl_dir);
}
zend_hash_destroy(&view->tpl_vars);
if (view->properties) {
if (GC_DELREF(view->properties) == 0) {
GC_REMOVE_FROM_BUFFER(view->properties);
zend_array_destroy(view->properties);
}
}
zend_object_std_dtor(object);
}
/* }}} */
int yaf_view_simple_init(yaf_view_object *view, zend_string *tpl_dir, zend_array *options) /* {{{ */ {
if (!IS_ABSOLUTE_PATH(ZSTR_VAL(tpl_dir), ZSTR_LEN(tpl_dir))) {
yaf_trigger_error(YAF_ERR_TYPE_ERROR, "Expects an absolute path for templates directory");
return 0;
}
view->tpl_dir = zend_string_copy(tpl_dir);
return 1;
}
/* }}} */
void yaf_view_simple_instance(yaf_view_t *view, zend_string *tpl_dir) /* {{{ */ {
zend_object *v = yaf_view_simple_new(yaf_view_simple_ce);
ZVAL_OBJ(view, v);
}
/* }}} */
static int yaf_view_simple_valid_var_name(zend_string *var_name) /* {{{ */ {
int i, ch;
if (UNEXPECTED(zend_string_equals_literal(var_name, "GLOBALS"))) {
return 0;
}
if (UNEXPECTED(zend_string_equals_literal(var_name, "this"))) {
return 0;
}
/* These are allowed as first char: [a-zA-Z_\x7f-\xff] */
ch = (int)((unsigned char *)ZSTR_VAL(var_name))[0];
if (ch != '_' &&
(ch < 65 /* A */ || /* Z */ ch > 90) &&
(ch < 97 /* a */ || /* z */ ch > 122) &&
(ch < 127 /* 0x7f */ || /* 0xff */ ch > 255)
) {
return 0;
}
/* And these as the rest: [a-zA-Z0-9_\x7f-\xff] */
if (ZSTR_LEN(var_name) > 1) {
for (i = 1; i < ZSTR_LEN(var_name); i++) {
ch = (int)((unsigned char *)ZSTR_VAL(var_name))[i];
if (ch != '_' &&
(ch < 48 /* 0 */ || /* 9 */ ch > 57) &&
(ch < 65 /* A */ || /* Z */ ch > 90) &&
(ch < 97 /* a */ || /* z */ ch > 122) &&
(ch < 127 /* 0x7f */ || /* 0xff */ ch > 255)
) {
return 0;
}
}
}
return 1;
}
/* }}} */
static void yaf_view_build_symtable(zend_array *symbol_table, zend_array *tpl_vars, zval *vars) /* {{{ */ {
zval *entry;
zend_string *var_name;
zend_hash_init(symbol_table, 8, NULL, ZVAL_PTR_DTOR, 0);
if (EXPECTED(tpl_vars)) {
ZEND_HASH_FOREACH_STR_KEY_VAL(tpl_vars, var_name, entry) {
if (var_name == NULL) {
continue;
}
if (yaf_view_simple_valid_var_name(var_name)) {
if (EXPECTED(zend_hash_add_new(symbol_table, var_name, entry))) {
Z_TRY_ADDREF_P(entry);
}
}
} ZEND_HASH_FOREACH_END();
}
if (vars && Z_TYPE_P(vars) == IS_ARRAY) {
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(vars), var_name, entry) {
if (var_name == NULL) {
continue;
}
if (yaf_view_simple_valid_var_name(var_name)) {
if (EXPECTED(zend_hash_update(symbol_table, var_name, entry))) {
Z_TRY_ADDREF_P(entry);
}
}
} ZEND_HASH_FOREACH_END();
}
}
/* }}} */
static int yaf_view_exec_tpl(yaf_view_t *view, zend_op_array *op_array, zend_array *symbol_table, zval* ret) /* {{{ */ {
zend_execute_data *call;
zval result;
uint32_t call_info;
ZVAL_UNDEF(&result);
op_array->scope = Z_OBJCE_P(view);
zend_function *func = (zend_function *)op_array;
#if PHP_VERSION_ID >= 70400
call_info = ZEND_CALL_HAS_THIS | ZEND_CALL_NESTED_CODE | ZEND_CALL_HAS_SYMBOL_TABLE;
#elif PHP_VERSION_ID >= 70100
call_info = ZEND_CALL_NESTED_CODE | ZEND_CALL_HAS_SYMBOL_TABLE;
#else
call_info = ZEND_CALL_NESTED_CODE;
#endif
#if PHP_VERSION_ID < 70400
call = zend_vm_stack_push_call_frame(call_info, func, 0, op_array->scope, Z_OBJ_P(view));
#else
call = zend_vm_stack_push_call_frame(call_info, func, 0, Z_OBJ_P(view));
#endif
call->symbol_table = symbol_table;
if (ret && php_output_start_user(NULL, 0, PHP_OUTPUT_HANDLER_STDFLAGS) == FAILURE) {
php_error_docref("ref.outcontrol", E_WARNING, "failed to create buffer");
return 0;
}
zend_init_execute_data(call, op_array, &result);
ZEND_ADD_CALL_FLAG(call, ZEND_CALL_TOP);
zend_execute_ex(call);
zend_vm_stack_free_call_frame(call);
zval_ptr_dtor(&result);
if (UNEXPECTED(EG(exception) != NULL)) {
if (ret) {
php_output_discard();
}
return 0;
}
if (ret) {
if (php_output_get_contents(ret) == FAILURE) {
php_output_end();
php_error_docref(NULL, E_WARNING, "Unable to fetch ob content");
return 0;
}
if (php_output_discard() != SUCCESS ) {
return 0;
}
}
return 1;
}
/* }}} */
static int yaf_view_render_tpl(yaf_view_t *view, const char *tpl, uint32_t tpl_len, zend_array *symbol_table, zval *ret) /* {{{ */ {
int status = 0;
zend_stat_t sb;
zend_file_handle file_handle;
zend_op_array *op_array;
if (UNEXPECTED(VCWD_STAT(tpl, &sb) == -1)) {
yaf_trigger_error(YAF_ERR_NOTFOUND_VIEW, "Failed opening template %s: %s", tpl, strerror(errno));
return 0;
}
#if PHP_VERSION_ID < 70400
file_handle.filename = tpl;
file_handle.type = ZEND_HANDLE_FILENAME;
file_handle.free_filename = 0;
file_handle.opened_path = NULL;
file_handle.handle.fp = NULL;
#else
/* setup file-handle */
zend_stream_init_filename(&file_handle, tpl);
#endif
op_array = zend_compile_file(&file_handle, ZEND_INCLUDE);
if (op_array) {
if (file_handle.handle.stream.handle) {
if (!file_handle.opened_path) {
file_handle.opened_path = zend_string_init(tpl, tpl_len, 0);
}
zend_hash_add_empty_element(&EG(included_files), file_handle.opened_path);
}
status = yaf_view_exec_tpl(view, op_array, symbol_table, ret);
destroy_op_array(op_array);
efree_size(op_array, sizeof(zend_op_array));
}
zend_destroy_file_handle(&file_handle);
return status;
}
/* }}} */
int yaf_view_simple_render(yaf_view_t *view, zend_string *tpl, zval *vars, zval *ret) /* {{{ */ {
zend_array symbol_table;
char directory[MAXPATHLEN];
char *tpl_dir;
uint32_t tpl_len;
yaf_view_object *v = Z_YAFVIEWOBJ_P(view);
yaf_view_build_symtable(&symbol_table, &v->tpl_vars, vars);
tpl_dir = ZSTR_VAL(tpl);
tpl_len = ZSTR_LEN(tpl);
if (!IS_ABSOLUTE_PATH(tpl_dir, tpl_len)) {
if (UNEXPECTED(v->tpl_dir == NULL)) {
zend_hash_destroy(&symbol_table);
yaf_trigger_error(YAF_ERR_NOTFOUND_VIEW,
"Could not determine the view script path, you should call %s::setScriptPath to specific it",
ZSTR_VAL(yaf_view_simple_ce->name));
return 0;
} else {
zend_string *v_tpl = v->tpl_dir;
tpl_len = yaf_compose_2_pathes(directory, v_tpl, tpl_dir, tpl_len);
directory[tpl_len] = '\0';
tpl_dir = directory;
}
}
if (EXPECTED(yaf_view_render_tpl(view, tpl_dir, tpl_len, &symbol_table, ret))) {
zend_hash_destroy(&symbol_table);
return 1;
}
zend_hash_destroy(&symbol_table);
return 0;
}
/* }}} */
static int yaf_view_simple_eval(yaf_view_t *view, zend_string *tpl, zval * vars, zval *ret) /* {{{ */ {
zend_array symbol_table;
if (ZSTR_LEN(tpl)) {
zval phtml;
zend_op_array *op_array;
char *eval_desc = zend_make_compiled_string_description("template code");
/* eval require code mustn't be wrapped in opening and closing PHP tags */
ZVAL_STR(&phtml, strpprintf(0, "?>%s", ZSTR_VAL(tpl)));
#if PHP_VERSION_ID < 80000
op_array = zend_compile_string(&phtml, eval_desc);
#else
op_array = zend_compile_string(Z_STR(phtml), eval_desc);
#endif
zval_dtor(&phtml);
efree(eval_desc);
if (op_array) {
yaf_view_build_symtable(&symbol_table, &(Z_YAFVIEWOBJ_P(view))->tpl_vars, vars);
yaf_view_exec_tpl(view, op_array, &symbol_table, ret);
destroy_op_array(op_array);
efree_size(op_array, sizeof(zend_op_array));
}
}
zend_hash_destroy(&symbol_table);
return 1;
}
/* }}} */
static zend_always_inline void yaf_view_simple_assign_single(yaf_view_object *view, zend_string *name, zval *value) /* {{{ */ {
zend_hash_update(&view->tpl_vars, name, value);
Z_TRY_ADDREF_P(value);
}
/* }}} */
static void yaf_view_simple_assign_multi(yaf_view_object *view, zval *value) /* {{{ */ {
zend_hash_copy(&view->tpl_vars, Z_ARRVAL_P(value), (copy_ctor_func_t) zval_add_ref);
}
/* }}} */
static void yaf_view_simple_clear_assign(yaf_view_object *view, zend_string *name) /* {{{ */ {
if (name) {
zend_hash_del(&view->tpl_vars, name);
} else {
zend_hash_clean(&view->tpl_vars);
}
}
/* }}} */
/** {{{ proto public Yaf_View_Simple::__construct(string $tpl_dir, array $options = NULL)
*/
PHP_METHOD(yaf_view_simple, __construct) {
zend_string *tpl_dir;
zval *options = NULL;
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "S|a!", &tpl_dir, &options) == FAILURE) {
return;
}
yaf_view_simple_init(Z_YAFVIEWOBJ_P(getThis()), tpl_dir, options? Z_ARRVAL_P(options) : NULL);
}
/* }}} */
/** {{{ proto public Yaf_View_Simple::setScriptPath(string $tpl_dir)
*/
PHP_METHOD(yaf_view_simple, setScriptPath) {
zend_string *tpl_dir;
yaf_view_object *view = Z_YAFVIEWOBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &tpl_dir) == FAILURE) {
return;
}
if (IS_ABSOLUTE_PATH(ZSTR_VAL(tpl_dir), ZSTR_LEN(tpl_dir))) {
if (view->tpl_dir) {
zend_string_release(view->tpl_dir);
}
view->tpl_dir = zend_string_copy(tpl_dir);
RETURN_ZVAL(getThis(), 1, 0);
}
RETURN_FALSE;
}
/* }}} */
/** {{{ proto public Yaf_View_Simple::getScriptPath(Yaf_Request_Abstarct $request = NULL)
*/
PHP_METHOD(yaf_view_simple, getScriptPath) {
yaf_request_t *request = NULL;
yaf_view_object *view = Z_YAFVIEWOBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|O!", &request, yaf_request_ce) == FAILURE) {
return;
}
if (view->tpl_dir) {
RETURN_STR_COPY(view->tpl_dir);
}
RETURN_NULL();
}
/* }}} */
/** {{{ proto public Yaf_View_Simple::assign(mixed $value, mixed $value = null)
*/
PHP_METHOD(yaf_view_simple, assign) {
yaf_view_object *view = Z_YAFVIEWOBJ_P(getThis());
if (ZEND_NUM_ARGS() == 2) {
zval *value;
zend_string *name;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &name, &value) == FAILURE) {
return;
}
yaf_view_simple_assign_single(view, name, value);
RETURN_ZVAL(getThis(), 1, 0);
} else if (ZEND_NUM_ARGS() == 1) {
zval *value;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &value) == FAILURE) {
return;
}
yaf_view_simple_assign_multi(view, value);
RETURN_ZVAL(getThis(), 1, 0);
} else {
WRONG_PARAM_COUNT;
RETURN_FALSE;
}
}
/* }}} */
/** {{{ proto public Yaf_View_Simple::assignRef(mixed $value, mixed &$value)
*/
PHP_METHOD(yaf_view_simple, assignRef) {
zend_string *name;
zval *value;
yaf_view_object *view = Z_YAFVIEWOBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &name, &value) == FAILURE) {
return;
}
yaf_view_simple_assign_single(view, name, value);
RETURN_ZVAL(getThis(), 1, 0);
}
/* }}} */
/** {{{ proto public Yaf_View_Simple::get($name)
*/
PHP_METHOD(yaf_view_simple, get) {
zend_string *name = NULL;
yaf_view_object *view = Z_YAFVIEWOBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!", &name) == FAILURE) {
return;
}
if (name && ZSTR_LEN(name)) {
zval *val = zend_hash_find(&view->tpl_vars, name);
if (val) {
RETURN_ZVAL(val, 1, 0);
} else {
RETURN_NULL();
}
} else {
RETURN_ARR(zend_array_dup(&view->tpl_vars));
}
}
/* }}} */
/** {{{ proto public Yaf_View_Simple::render(string $tpl, array $vars = NULL)
*/
PHP_METHOD(yaf_view_simple, render) {
zval *tpl;
zval *vars = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|a!", &tpl, &vars) == FAILURE) {
return;
}
if (UNEXPECTED(Z_TYPE_P(tpl) != IS_STRING || Z_STRLEN_P(tpl) == 0)) {
RETURN_FALSE;
}
if (!yaf_view_simple_render(getThis(), Z_STR_P(tpl), vars, return_value)) {
RETURN_FALSE;
}
}
/* }}} */
/** {{{ proto public Yaf_View_Simple::eval(string $tpl_content, array $vars = NULL)
*/
PHP_METHOD(yaf_view_simple, eval) {
zend_string *tpl;
zval *vars = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|a!", &tpl, &vars) == FAILURE) {
return;
}
if (!yaf_view_simple_eval(getThis(), tpl, vars, return_value)) {
RETURN_FALSE;
}
}
/* }}} */
/** {{{ proto public Yaf_View_Simple::display(string $tpl, array $vars = NULL)
*/
PHP_METHOD(yaf_view_simple, display) {
zval *tpl;
zval *vars = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|a!", &tpl, &vars) == FAILURE) {
return;
}
if (UNEXPECTED(Z_TYPE_P(tpl) != IS_STRING || Z_STRLEN_P(tpl) == 0)) {
RETURN_FALSE;
}
if (!yaf_view_simple_render(getThis(), Z_STR_P(tpl), vars, NULL)) {
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
/** {{{ proto public Yaf_View_Simple::clear(string $name)
*/
PHP_METHOD(yaf_view_simple, clear) {
zend_string *name = NULL;
yaf_view_object *view = Z_YAFVIEWOBJ_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!", &name) == FAILURE) {
return;
}
yaf_view_simple_clear_assign(view, name);
RETURN_ZVAL(getThis(), 1, 0);
}
/* }}} */
/** {{{ yaf_view_simple_methods
*/
zend_function_entry yaf_view_simple_methods[] = {
PHP_ME(yaf_view_simple, __construct, yaf_view_simple_construct_arginfo, ZEND_ACC_CTOR|ZEND_ACC_FINAL|ZEND_ACC_PUBLIC)
PHP_ME(yaf_view_simple, get, yaf_view_simple_get_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_view_simple, assign, yaf_view_assign_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_view_simple, render, yaf_view_render_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_view_simple, eval, yaf_view_simple_eval_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_view_simple, display, yaf_view_display_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_view_simple, assignRef, yaf_view_simple_assign_by_ref_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_view_simple, clear, yaf_view_simple_clear_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_view_simple, setScriptPath, yaf_view_setpath_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_view_simple, getScriptPath, yaf_view_getpath_arginfo, ZEND_ACC_PUBLIC)
PHP_MALIAS(yaf_view_simple, __get, get, yaf_view_simple_get_arginfo, ZEND_ACC_PUBLIC)
PHP_MALIAS(yaf_view_simple, __set, assign, yaf_view_assign_arginfo, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
/* }}} */
/** {{{ YAF_STARTUP_FUNCTION
*/
YAF_STARTUP_FUNCTION(view_simple) {
zend_class_entry ce;
YAF_INIT_CLASS_ENTRY(ce, "Yaf_View_Simple", "Yaf\\View\\Simple", yaf_view_simple_methods);
yaf_view_simple_ce = zend_register_internal_class_ex(&ce, NULL);
yaf_view_simple_ce->create_object = yaf_view_simple_new;
yaf_view_simple_ce->serialize = zend_class_serialize_deny;
yaf_view_simple_ce->unserialize = zend_class_unserialize_deny;
zend_class_implements(yaf_view_simple_ce, 1, yaf_view_interface_ce);
memcpy(&yaf_view_simple_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
yaf_view_simple_obj_handlers.offset = XtOffsetOf(yaf_view_object, std);
yaf_view_simple_obj_handlers.free_obj = yaf_view_object_free;
yaf_view_simple_obj_handlers.get_properties = yaf_view_simple_get_properties;
yaf_view_simple_obj_handlers.read_property = (zend_object_read_property_t)yaf_view_simple_read_property;
yaf_view_simple_obj_handlers.write_property = (zend_object_write_property_t)yaf_view_simple_write_property;
yaf_view_simple_obj_handlers.clone_obj = NULL;
yaf_view_simple_obj_handlers.get_gc = yaf_fake_get_gc;
return SUCCESS;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/