Esempio n. 1
0
zval * yee_exception_to_array_recursive(zval *self, zval *exception) {
	zend_object *object        = (zend_object *)zend_object_store_get_object(self TSRMLS_CC);
	zend_object *except_object = (zend_object *)zend_object_store_get_object(exception TSRMLS_CC);
	zval *array;
	zval *name = NULL, *message = NULL, *code = NULL, *previous = NULL, *previous2 = NULL;
	
	MAKE_STD_ZVAL(array);
	array_init_size(array, 5);
	
	if (instanceof_function(except_object->ce, yee_ce_Exception)) {
		zend_call_method(&exception, except_object->ce, NULL, ZEND_STRL("getname"), &name, 0, NULL, NULL);
	}else {
		MAKE_STD_ZVAL(name);
		ZVAL_STRING(name, "Exception", 1);
	}
	
	zend_call_method(&exception, except_object->ce, NULL, ZEND_STRL("getmessage"), &message, 0, NULL, NULL);
	zend_call_method(&exception, except_object->ce, NULL, ZEND_STRL("getcode"), &code, 0, NULL, NULL);
	zend_call_method(&exception, except_object->ce, NULL, ZEND_STRL("getprevious"), &previous, 0, NULL, NULL);
	
	add_assoc_string_ex(array, ZEND_STRS("type"), (char *)except_object->ce->name, 1);
	add_assoc_zval_ex(array, ZEND_STRS("name"), name);
	add_assoc_zval_ex(array, ZEND_STRS("message"), message);
	add_assoc_zval_ex(array, ZEND_STRS("code"), code);
	
	if (previous && previous->type == IS_OBJECT) {
		previous2 = yee_exception_to_array_recursive(self, previous);
		add_assoc_zval_ex(array, ZEND_STRS("previous"), previous2);
	}
	zval_dtor(previous);
	efree(previous);
	
	return array;
}
Esempio n. 2
0
static int add_associate_array( const char * pKey, int keyLen, const char * pValue, int valLen,
                         void * arg )
{
    add_assoc_string_ex( (zval *)arg, (char *)pKey, keyLen+1, (char *)pValue
#if PHP_MAJOR_VERSION < 7
            , 1
#endif
    );
    return 1;
}
Esempio n. 3
0
/* {{{ apc_iterator_item */
static apc_iterator_item_t* apc_iterator_item_ctor(apc_iterator_t *iterator, apc_cache_slot_t **slot_pp) {
    zval zvalue;
    apc_cache_slot_t *slot = *slot_pp;
    apc_context_t ctxt = {0, };
    apc_iterator_item_t *item = ecalloc(1, sizeof(apc_iterator_item_t));

    array_init(&item->value);

	item->key = slot->key.str;

    if (APC_ITER_TYPE & iterator->format) {
		add_assoc_string_ex(&item->value, "type", sizeof("type")-1, "user");
	}

	if (APC_ITER_KEY & iterator->format) {
		add_assoc_str(&item->value, "key", zend_string_copy(item->key));
	}

    if (APC_ITER_VALUE & iterator->format) {
    	apc_cache_make_context(
    		apc_user_cache, &ctxt, APC_CONTEXT_NOSHARE, APC_UNPOOL, APC_COPY_OUT, 0);
    	ZVAL_UNDEF(&zvalue);
        apc_cache_fetch_zval(&ctxt, &zvalue, &slot->value->val);
        add_assoc_zval(&item->value, "value", &zvalue);
        apc_pool_destroy(ctxt.pool);
    }

    if (APC_ITER_NUM_HITS & iterator->format) {
        add_assoc_long(&item->value, "num_hits", slot->nhits);
    }
    if (APC_ITER_MTIME & iterator->format) {
        add_assoc_long(&item->value, "mtime", slot->key.mtime);
    }
    if (APC_ITER_CTIME & iterator->format) {
        add_assoc_long(&item->value, "creation_time", slot->ctime);
    }
    if (APC_ITER_DTIME & iterator->format) {
        add_assoc_long(&item->value, "deletion_time", slot->dtime);
    }
    if (APC_ITER_ATIME & iterator->format) {
        add_assoc_long(&item->value, "access_time", slot->atime);
    }
    if (APC_ITER_REFCOUNT & iterator->format) {
        add_assoc_long(&item->value, "ref_count", slot->value->ref_count);
    }
    if (APC_ITER_MEM_SIZE & iterator->format) {
        add_assoc_long(&item->value, "mem_size", slot->value->mem_size);
    }
    if (APC_ITER_TTL & iterator->format) {
        add_assoc_long(&item->value, "ttl", slot->value->ttl);
    }

    return item;
}
Esempio n. 4
0
/* {{{ Helpers */
void retval_point_from_coordinates(zval *return_value, double lon, double lat)
{
	zval *coordinates;

	array_init(return_value);
	MAKE_STD_ZVAL(coordinates);
	array_init(coordinates);
	add_assoc_string_ex(return_value, "type", sizeof("type"), "Point", 1);
	add_next_index_double(coordinates, lon);
	add_next_index_double(coordinates, lat);
	add_assoc_zval_ex(return_value, "coordinates", sizeof("coordinates"), coordinates);
}
Esempio n. 5
0
/* {{{ property link_error_list_read */
static zval *link_error_list_read(mysqli_object *obj, zval *retval)
{
	MY_MYSQL *mysql;

	CHECK_STATUS(MYSQLI_STATUS_VALID);

 	mysql = (MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;

	array_init(retval);
	if (mysql) {
#if defined(MYSQLI_USE_MYSQLND)
		if (mysql->mysql->data->error_info->error_list) {
			MYSQLND_ERROR_LIST_ELEMENT * message;
			zend_llist_position pos;
			for (message = (MYSQLND_ERROR_LIST_ELEMENT *) zend_llist_get_first_ex(mysql->mysql->data->error_info->error_list, &pos);
				 message;
				 message = (MYSQLND_ERROR_LIST_ELEMENT *) zend_llist_get_next_ex(mysql->mysql->data->error_info->error_list, &pos)) 
			{
				zval single_error;
				array_init(&single_error);
				add_assoc_long_ex(&single_error, "errno", sizeof("errno") - 1, message->error_no);
				add_assoc_string_ex(&single_error, "sqlstate", sizeof("sqlstate") - 1, message->sqlstate);
				add_assoc_string_ex(&single_error, "error", sizeof("error") - 1, message->error);
				add_next_index_zval(retval, &single_error);
			}
		}
#else
		if (mysql_errno(mysql->mysql)) {
			zval single_error;
			array_init(&single_error);
			add_assoc_long_ex(&single_error, "errno", sizeof("errno") - 1, mysql_errno(mysql->mysql));
			add_assoc_string_ex(&single_error, "sqlstate", sizeof("sqlstate") - 1, mysql_sqlstate(mysql->mysql));
			add_assoc_string_ex(&single_error, "error", sizeof("error") - 1, mysql_error(mysql->mysql));
			add_next_index_zval(retval, &single_error);
		}
#endif
	}

	return retval;
}
Esempio n. 6
0
static int add_associate_array( const char * pKey, int keyLen, const char * pValue, int valLen,
                         void * arg )
{
    add_assoc_string_ex((zval *)arg, (char *)pKey, keyLen, (char *)pValue);
    return 1;
}
Esempio n. 7
0
static zval *get_trace_detail(const jsonlite_decoder *self) {

    HashTable *array = NULL;
    HashPosition *pointer = NULL;

    zval *traces = NULL;
    zval *trace = NULL;
    zval **val = NULL;
    zval **msg = NULL;
    zval **range_start = NULL;
    zval **range_end = NULL;
    zval *range = NULL;
    char *str = NULL;
    zval *chars = NULL;
    zval **detail = NULL;
    int start = 0;
    int end = 0;

    array = Z_ARRVAL_P(self->trace);

    ALLOC_INIT_ZVAL(traces);
    array_init(traces);

    zend_hash_internal_pointer_reset_ex(array, pointer);
    while (zend_hash_has_more_elements_ex(array, pointer) == SUCCESS) {
        if (zend_hash_get_current_data_ex(array, (void **) &val, pointer) == SUCCESS) {

            if (val && Z_TYPE_PP(val) == IS_ARRAY) {

                zend_hash_index_find(Z_ARRVAL_PP(val), 0, (void **) &msg);
                zend_hash_index_find(Z_ARRVAL_PP(val), 1, (void **) &range_start);
                zend_hash_index_find(Z_ARRVAL_PP(val), 2, (void **) &range_end);

                if (zend_hash_index_exists(Z_ARRVAL_PP(val), 3) == 1) {
                    zend_hash_index_find(Z_ARRVAL_PP(val), 3, (void **) &detail);
                }

                ALLOC_INIT_ZVAL(trace);
                array_init(trace);

                zval_add_ref(msg);
                add_assoc_zval_ex(trace, ZEND_STRS("msg"), *msg);

                ALLOC_INIT_ZVAL(range);
                array_init(range);

                zval_add_ref(range_start);
                add_next_index_zval(range, *range_start);

                zval_add_ref(range_end);
                add_next_index_zval(range, *range_end);

                add_assoc_zval_ex(trace, ZEND_STRS("range"), range);
                start = Z_LVAL_PP(range_start);
                if (start > 0) {
                    start--;
                }
                end = Z_LVAL_PP(range_end);
                if (end < self->length) {
                    end++;
                }

                str = zend_strndup((self->jsonlite + start), end - start);
                add_assoc_string_ex(trace, ZEND_STRS("chars"), str, 1);
                free(str);

                if (detail != NULL) {
                    zval_add_ref(detail);
                    add_assoc_zval_ex(trace, ZEND_STRS("detail"), *detail);
                }

                add_next_index_zval(traces, trace);
                detail = NULL;
                trace = NULL;
            }
        }
        if (zend_hash_move_forward_ex(array, pointer) == FAILURE) {
            break;
        }
    }
    return traces;
}