/*
+----------------------------------------------------------------------+
| Twig Extension |
+----------------------------------------------------------------------+
| Copyright (c) 2011 Derick Rethans |
+----------------------------------------------------------------------+
| Redistribution and use in source and binary forms, with or without |
| modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met (BSD-3-Clause). |
+----------------------------------------------------------------------+
| Author: Derick Rethans <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_twig.h"
#include "ext/standard/php_var.h"
#include "ext/standard/php_string.h"
#include "ext/standard/php_smart_str.h"
#include "ext/spl/spl_exceptions.h"
#include "Zend/zend_object_handlers.h"
#include "Zend/zend_interfaces.h"
#include "Zend/zend_exceptions.h"
#ifndef Z_ADDREF_P
#define Z_ADDREF_P(pz) (pz)->refcount++
#endif
#ifndef E_USER_DEPRECATED
#define E_USER_DEPRECATED (1<<14L)
#endif
#define FREE_DTOR(z) \
zval_dtor(z); \
efree(z);
#if PHP_VERSION_ID >= 50300
#define APPLY_TSRMLS_DC TSRMLS_DC
#define APPLY_TSRMLS_CC TSRMLS_CC
#define APPLY_TSRMLS_FETCH()
#else
#define APPLY_TSRMLS_DC
#define APPLY_TSRMLS_CC
#define APPLY_TSRMLS_FETCH() TSRMLS_FETCH()
#endif
ZEND_BEGIN_ARG_INFO_EX(twig_template_get_attribute_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 6)
ZEND_ARG_INFO(0, template)
ZEND_ARG_INFO(0, object)
ZEND_ARG_INFO(0, item)
ZEND_ARG_INFO(0, arguments)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, isDefinedTest)
ZEND_END_ARG_INFO()
#ifndef PHP_FE_END
#define PHP_FE_END { NULL, NULL, NULL}
#endif
static const zend_function_entry twig_functions[] = {
PHP_FE(twig_template_get_attributes, twig_template_get_attribute_args)
PHP_FE_END
};
PHP_RSHUTDOWN_FUNCTION(twig)
{
#if ZEND_DEBUG
CG(unclean_shutdown) = 0; /* get rid of PHPUnit's exit() and report memleaks */
#endif
return SUCCESS;
}
zend_module_entry twig_module_entry = {
STANDARD_MODULE_HEADER,
"twig",
twig_functions,
NULL,
NULL,
NULL,
PHP_RSHUTDOWN(twig),
NULL,
PHP_TWIG_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_TWIG
ZEND_GET_MODULE(twig)
#endif
static int TWIG_ARRAY_KEY_EXISTS(zval *array, zval *key)
{
if (Z_TYPE_P(array) != IS_ARRAY) {
return 0;
}
switch (Z_TYPE_P(key)) {
case IS_NULL:
return zend_hash_exists(Z_ARRVAL_P(array), "", 1);
case IS_BOOL:
case IS_DOUBLE:
convert_to_long(key);
case IS_LONG:
return zend_hash_index_exists(Z_ARRVAL_P(array), Z_LVAL_P(key));
default:
convert_to_string(key);
return zend_symtable_exists(Z_ARRVAL_P(array), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1);
}
}
static int TWIG_INSTANCE_OF(zval *object, zend_class_entry *interface TSRMLS_DC)
{
if (Z_TYPE_P(object) != IS_OBJECT) {
return 0;
}
return instanceof_function(Z_OBJCE_P(object), interface TSRMLS_CC);
}
static int TWIG_INSTANCE_OF_USERLAND(zval *object, char *interface TSRMLS_DC)
{
zend_class_entry **pce;
if (Z_TYPE_P(object) != IS_OBJECT) {
return 0;
}
if (zend_lookup_class(interface, strlen(interface), &pce TSRMLS_CC) == FAILURE) {
return 0;
}
return instanceof_function(Z_OBJCE_P(object), *pce TSRMLS_CC);
}
static zval *TWIG_GET_ARRAYOBJECT_ELEMENT(zval *object, zval *offset TSRMLS_DC)
{
zend_class_entry *ce = Z_OBJCE_P(object);
zval *retval;
if (Z_TYPE_P(object) == IS_OBJECT) {
SEPARATE_ARG_IF_REF(offset);
zend_call_method_with_1_params(&object, ce, NULL, "offsetget", &retval, offset);
zval_ptr_dtor(&offset);
if (!retval) {
if (!EG(exception)) {
zend_error(E_ERROR, "Undefined offset for object of type %s used as array.", ce->name);
}
return NULL;
}
return retval;
}
return NULL;
}
static int TWIG_ISSET_ARRAYOBJECT_ELEMENT(zval *object, zval *offset TSRMLS_DC)
{
zend_class_entry *ce = Z_OBJCE_P(object);
zval *retval;
if (Z_TYPE_P(object) == IS_OBJECT) {
SEPARATE_ARG_IF_REF(offset);
zend_call_method_with_1_params(&object, ce, NULL, "offsetexists", &retval, offset);
zval_ptr_dtor(&offset);
if (!retval) {
if (!EG(exception)) {
zend_error(E_ERROR, "Undefined offset for object of type %s used as array.", ce->name);
}
return 0;
}
return (retval && Z_TYPE_P(retval) == IS_BOOL && Z_LVAL_P(retval));
}
return 0;
}
static char *TWIG_STRTOLOWER(const char *str, int str_len)
{
char *item_dup;
item_dup = estrndup(str, str_len);
php_strtolower(item_dup, str_len);
return item_dup;
}
static zval *TWIG_CALL_USER_FUNC_ARRAY(zval *object, char *function, zval *arguments TSRMLS_DC)
{
zend_fcall_info fci;
zval ***args = NULL;
int arg_count = 0;
HashTable *table;
HashPosition pos;
int i = 0;
zval *retval_ptr;
zval *zfunction;
if (arguments) {
table = HASH_OF(arguments);
args = safe_emalloc(sizeof(zval **), table->nNumOfElements, 0);
zend_hash_internal_pointer_reset_ex(table, &pos);
while (zend_hash_get_current_data_ex(table, (void **)&args[i], &pos) == SUCCESS) {
i++;
zend_hash_move_forward_ex(table, &pos);
}
arg_count = table->nNumOfElements;
}
MAKE_STD_ZVAL(zfunction);
ZVAL_STRING(zfunction, function, 1);
fci.size = sizeof(fci);
fci.function_table = EG(function_table);
fci.function_name = zfunction;
fci.symbol_table = NULL;
#if PHP_VERSION_ID >= 50300
fci.object_ptr = object;
#else
fci.object_pp = &object;
#endif
fci.retval_ptr_ptr = &retval_ptr;
fci.param_count = arg_count;
fci.params = args;
fci.no_separation = 0;
if (zend_call_function(&fci, NULL TSRMLS_CC) == FAILURE) {
ALLOC_INIT_ZVAL(retval_ptr);
ZVAL_BOOL(retval_ptr, 0);
}
if (args) {
efree(fci.params);
}
FREE_DTOR(zfunction);
return retval_ptr;
}
static int TWIG_CALL_BOOLEAN(zval *object, char *functionName TSRMLS_DC)
{
zval *ret;
int res;
ret = TWIG_CALL_USER_FUNC_ARRAY(object, functionName, NULL TSRMLS_CC);
res = Z_LVAL_P(ret);
zval_ptr_dtor(&ret);
return res;
}
static zval *TWIG_GET_STATIC_PROPERTY(zval *class, char *prop_name TSRMLS_DC)
{
zval **tmp_zval;
zend_class_entry *ce;
if (class == NULL || Z_TYPE_P(class) != IS_OBJECT) {
return NULL;
}
ce = zend_get_class_entry(class TSRMLS_CC);
#if PHP_VERSION_ID >= 50400
tmp_zval = zend_std_get_static_property(ce, prop_name, strlen(prop_name), 0, NULL TSRMLS_CC);
#else
tmp_zval = zend_std_get_static_property(ce, prop_name, strlen(prop_name), 0 TSRMLS_CC);
#endif
return *tmp_zval;
}
static zval *TWIG_GET_ARRAY_ELEMENT_ZVAL(zval *class, zval *prop_name TSRMLS_DC)
{
zval **tmp_zval;
if (class == NULL || Z_TYPE_P(class) != IS_ARRAY) {
if (class != NULL && Z_TYPE_P(class) == IS_OBJECT && TWIG_INSTANCE_OF(class, zend_ce_arrayaccess TSRMLS_CC)) {
// array access object
return TWIG_GET_ARRAYOBJECT_ELEMENT(class, prop_name TSRMLS_CC);
}
return NULL;
}
switch(Z_TYPE_P(prop_name)) {
case IS_NULL:
zend_hash_find(HASH_OF(class), "", 1, (void**) &tmp_zval);
return *tmp_zval;
case IS_BOOL:
case IS_DOUBLE:
convert_to_long(prop_name);
case IS_LONG:
zend_hash_index_find(HASH_OF(class), Z_LVAL_P(prop_name), (void **) &tmp_zval);
return *tmp_zval;
case IS_STRING:
zend_symtable_find(HASH_OF(class), Z_STRVAL_P(prop_name), Z_STRLEN_P(prop_name) + 1, (void**) &tmp_zval);
return *tmp_zval;
}
return NULL;
}
static zval *TWIG_GET_ARRAY_ELEMENT(zval *class, char *prop_name, int prop_name_length TSRMLS_DC)
{
zval **tmp_zval;
if (class == NULL/* || Z_TYPE_P(class) != IS_ARRAY*/) {
return NULL;
}
if (class != NULL && Z_TYPE_P(class) == IS_OBJECT && TWIG_INSTANCE_OF(class, zend_ce_arrayaccess TSRMLS_CC)) {
// array access object
zval *tmp_name_zval;
zval *tmp_ret_zval;
ALLOC_INIT_ZVAL(tmp_name_zval);
ZVAL
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
最新微信小程序源码商城全开源v3.28.12源码全开源移动电商小程序 (2000个子文件)
twig.c 35KB
iconfont.css 165KB
foundation.min.css 161KB
style.css 150KB
v2.css 133KB
bootstrap.min.css 120KB
bootstrap.min.css 118KB
we7.common172.css 113KB
bootstrap.min.css 111KB
bootstrap.min.css 111KB
bootstrap.min.css 97KB
diy.min.css 95KB
diy.min.css 91KB
foxui.min.css 90KB
farm.css 81KB
animate.min.css 74KB
layui.css 71KB
animate.min.css 71KB
iconfont.css 66KB
animate.css 64KB
animate.css 60KB
v3.css 56KB
room.css 50KB
common_v3.css 42KB
goodshelper.css 39KB
global.css 38KB
video.css 36KB
foxui.diy.css 31KB
we7.common169.css 30KB
we7.common.css 26KB
font-awesome.min.css 26KB
font-awesome.min.css 26KB
verifyorder.css 26KB
foxui.diy.css 25KB
quick.css 24KB
style.css 24KB
style.css 23KB
style.css 23KB
sweetalert.css 22KB
index.css 21KB
common.css 21KB
goods-detail.css 20KB
iconfont.css 20KB
common.css 19KB
common.css 18KB
storedetail.css 18KB
console.css 18KB
coupon.css 18KB
loading.css 18KB
swiper-3.4.2.min.css 17KB
swiper.min.css 17KB
swiper-3.4.2.min.css 17KB
style.css 17KB
style.css 16KB
orderdetail.css 16KB
bargain.css 15KB
styles.css 15KB
common.css 15KB
foxui.extends.css 15KB
coupon-new.css 14KB
layer.css 14KB
plugingrant.css 14KB
web.css 14KB
select2.css 13KB
input.css 13KB
web.css 13KB
jquery-confirm.css 13KB
web.css 13KB
task.css 13KB
detail.css 12KB
common.css 12KB
web.base.css 11KB
css.css 11KB
common.css 11KB
common.css 10KB
web.css 10KB
layui.mobile.css 10KB
index.css 9KB
right.css 9KB
diy.css 9KB
aYMTI3LjAuMC4x.css 9KB
aYMTI3LjAuMC4x.css 9KB
diy.css 9KB
common.css 9KB
common.css 9KB
chicken.css 8KB
style.css 8KB
index.css 8KB
style.css 8KB
poster.css 8KB
mobilepan.css 8KB
taskplugin.css 8KB
common.css 7KB
laydate.css 7KB
web.css 7KB
sign.css 7KB
index.css 7KB
common.css 6KB
index.css 6KB
index.css 6KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
乱世英熊
- 粉丝: 0
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功