Beispiel #1
0
/* {{{ proto array WriteResult::getUpsertedIds()
   Returns the identifiers generated by the server for upsert operations. */
PHP_METHOD(WriteResult, getUpsertedIds)
{
	bson_iter_t iter, child;
	php_phongo_writeresult_t *intern;
	SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used)


	intern = Z_WRITERESULT_OBJ_P(getThis());

	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}


	array_init(return_value);

	if (bson_iter_init_find(&iter, intern->reply, "upserted") && BSON_ITER_HOLDS_ARRAY(&iter) && bson_iter_recurse(&iter, &child)) {
		while (bson_iter_next(&child)) {
			int32_t index;
			bson_iter_t outer;

			if (!BSON_ITER_HOLDS_DOCUMENT(&child) || !bson_iter_recurse(&child, &outer)) {
				continue;
			}
			if (!bson_iter_find(&outer, "index") || !BSON_ITER_HOLDS_INT32(&outer)) {
				continue;
			}

			index = bson_iter_int32(&outer);

			if (!bson_iter_find(&outer, "_id")) {
				continue;
			}

			if (BSON_ITER_HOLDS_OID(&outer)) {
#if PHP_VERSION_ID >= 70000
				zval zid;

				php_phongo_objectid_new_from_oid(&zid, bson_iter_oid(&outer) TSRMLS_CC);
				add_index_zval(return_value, index, &zid);
#else
				zval *zid = NULL;
				MAKE_STD_ZVAL(zid);

				php_phongo_objectid_new_from_oid(zid, bson_iter_oid(&outer) TSRMLS_CC);
				add_index_zval(return_value, index, zid);
#endif
			} else if (BSON_ITER_HOLDS_INT32(&outer)) {
				int32_t val = bson_iter_int32(&outer);

				add_index_long(return_value, index, val);
			} else if (BSON_ITER_HOLDS_INT64(&outer)) {
				int64_t val = bson_iter_int64(&outer);

				ADD_INDEX_INT64(return_value, index, val);
			}
		}
	}
}
Beispiel #2
0
static void
glib_source_callback_helper(zval *retval, zval *source_zval, const char *name, zval *params, uint32_t param_count)
{
	zend_fcall_info fci;
	zend_fcall_info_cache fci_cache;
	zval caller;

	array_init(&caller);
	add_index_zval(&caller, 0, source_zval);
	add_index_string(&caller, 1, name);

	char * callback_error;
	if(FAILURE == zend_fcall_info_init(&caller, IS_CALLABLE_STRICT, &fci, &fci_cache, NULL, &callback_error))
	{
		zend_throw_exception_ex(spl_ce_BadMethodCallException, 0,
			"Could not call %s source handler, %s", name, callback_error);
		zval_dtor(&caller);
		return;
	}

	/* Handle arguments if necessary */
	fci.param_count = param_count;
	if(param_count > 0) {
		fci.params = params;
	}

	fci.retval = retval;
	if(FAILURE == zend_call_function(&fci, &fci_cache)) {
		zend_throw_exception_ex(spl_ce_BadFunctionCallException, 0,
			"Could not call %s source handler", name);
	}
	zval_dtor(&caller);
}
Beispiel #3
0
zval * util_array_map_deep(zval* arr, zend_fcall_info* fci, zend_fcall_info_cache* fci_cache, zend_bool on_nonscalar) {
	zval *result, **zvalue;
	char *key;
	uint keylen;
	ulong idx;
	int type, value_type;
	HashTable* arr_hash;
	HashPosition pointer;
	zval **args[1];
	zval **arr_value;
	MAKE_STD_ZVAL(result);
	array_init(result);
	TSRMLS_FETCH();

	// Copy a temp array
	zval temp;
	temp = *arr;
	zval_copy_ctor(&temp);

	arr_hash = Z_ARRVAL_P(&temp);
	zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
	while (zend_hash_get_current_data_ex(arr_hash, (void**) &zvalue, &pointer) == SUCCESS) {
		type = zend_hash_get_current_key_ex(arr_hash, &key, &keylen, &idx, 0, &pointer);
		value_type = Z_TYPE_P(*zvalue);
		if (value_type == IS_ARRAY) {
			if (type == HASH_KEY_IS_LONG) {
				add_index_zval(result, idx, util_array_map_deep(*zvalue, fci, fci_cache, on_nonscalar));
			} else {
				add_assoc_zval(result, key, util_array_map_deep(*zvalue, fci, fci_cache, on_nonscalar));
			}
		} else if (value_type == IS_BOOL || value_type == IS_LONG || value_type == IS_DOUBLE || value_type == IS_STRING || on_nonscalar) {
			zval *retval_ptr = NULL;
			args[0] = zvalue;
			(*fci).retval_ptr_ptr = &retval_ptr;
			(*fci).params = args;
			if (zend_call_function(fci, fci_cache TSRMLS_CC) == SUCCESS && retval_ptr) {
				if (type == HASH_KEY_IS_LONG) {
					add_index_zval(result, idx, retval_ptr);
				} else {
					add_assoc_zval(result, key, retval_ptr);
				}
			}
		}
		zend_hash_move_forward_ex(arr_hash, &pointer);
	}
	return result;
}
Beispiel #4
0
SKYRAY_METHOD(stream_client, createPipe)
{
    zend_bool duplex = 0;
    zval stream1, stream2;
    int fds[2];
    int sockret;

    if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &duplex) == FAILURE) {
        return;
    }

    if (duplex) {
        sockret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
    } else {
        sockret = pipe(fds);
    }

    if (sockret == -1) {
        RETURN_FALSE;
    }

    array_init(return_value);

    object_init_ex(&stream1, skyray_ce_Stream);
    object_init_ex(&stream2, skyray_ce_Stream);

    skyray_stream_t * intern1 = skyray_stream_from_obj(Z_OBJ_P(&stream1));
    skyray_stream_t * intern2 = skyray_stream_from_obj(Z_OBJ_P(&stream2));

    skyray_stream_init_blocking(intern1, SR_PIPE, fds[0], NULL);
    skyray_stream_init_blocking(intern2, SR_PIPE, fds[1], NULL);

    if (duplex) {
        skyray_stream_on_opened(intern1, SR_READABLE | SR_WRITABLE);
        skyray_stream_on_opened(intern2, SR_READABLE | SR_WRITABLE);
    } else {
        skyray_stream_on_opened(intern1, SR_READABLE);
        skyray_stream_on_opened(intern2, SR_WRITABLE);
    }

    add_index_zval(return_value, 0, &stream1);
    add_index_zval(return_value, 1, &stream2);

    zval_add_ref(&stream1);
    zval_add_ref(&stream2);
}
Beispiel #5
0
PHP_METHOD(air_mysql_waiter, step_2) {
	AIR_INIT_THIS;
	zval *services = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_services"), 0 TSRMLS_CC);
	zval *responses = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_responses"), 0 TSRMLS_CC);
	zval *context = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_context"), 0 TSRMLS_CC);
	zval *m2s = air_arr_find(context, ZEND_STRS("m2s"));
	zval *reads = air_arr_find(context, ZEND_STRS("reads"));
	zval *waited = air_arr_find(context, ZEND_STRS("waited"));
	zval *processed = air_arr_find(context, ZEND_STRS("processed"));
	zval *step = air_arr_find(context, ZEND_STRS("step"));
	zend_class_entry *mysqli_ce = air_get_ce(ZEND_STRL("mysqli") TSRMLS_CC);

	ulong idx;
	char *key;
	int key_len;
	zval *mysqli;
	AIR_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(reads), idx, key, key_len, mysqli){
		zval *service_id = air_arr_idx_find(m2s, air_mysqli_get_id(mysqli TSRMLS_CC));
		zval *service = air_arr_idx_find(services, Z_LVAL_P(service_id));
		zval *mysql = zend_read_property(air_async_service_ce, service, ZEND_STRL("_request"), 0 TSRMLS_CC);
		zval **trigger_params[2];
		zval *event;
		MAKE_STD_ZVAL(event);
		zval *event_params;
		MAKE_STD_ZVAL(event_params);
		array_init(event_params);
		Z_ADDREF_P(mysqli);
		add_next_index_zval(event_params, mysqli);
		zval *mysqli_result = NULL;
		if(air_mysqli_get_errno(mysqli TSRMLS_CC)){
			ZVAL_STRING(event, "error", 1);
		}else{
			ZVAL_STRING(event, "success", 1);
			air_call_method(&mysqli, mysqli_ce, NULL, ZEND_STRL("reap_async_query"), &mysqli_result, 0, NULL TSRMLS_CC);
			Z_ADDREF_P(mysqli_result);
			add_next_index_zval(event_params, mysqli_result);
		}
		trigger_params[0] = &event;
		trigger_params[1] = &event_params;
		zval *results = NULL;
		air_call_method(&mysql, air_mysql_ce, NULL, ZEND_STRL("trigger"), &results, 2, trigger_params TSRMLS_CC);
		if(results){
			add_index_zval(responses, Z_LVAL_P(service_id), results);
		}else{
			php_error(E_WARNING, "error on trigger event %s with no results", Z_STRVAL_P(event));
		}
		zend_hash_index_del(Z_ARRVAL_P(services), Z_LVAL_P(service_id));
		zval_ptr_dtor(&event);
		zval_ptr_dtor(&event_params);
		if(mysqli_result){
			zval_ptr_dtor(&mysqli_result);
		}
		zval *mysql_config = zend_read_property(air_mysql_ce, mysql, ZEND_STRL("_config"), 0 TSRMLS_CC);
		zval *mode = zend_read_property(air_mysql_ce, mysql, ZEND_STRL("_mode"), 0 TSRMLS_CC);
		zval **release_params[3] = {&mysqli, &mysql_config, &mode};
		air_call_static_method(air_mysql_keeper_ce, "release", NULL, 3, release_params);
	}AIR_HASH_FOREACH_END();
static void
populate_result_for_get_exists_many(as_key *key_p, zval *outer_container_p,
        zval *inner_container_p, as_error *error_p, bool null_flag TSRMLS_DC)
{
    if (!(as_val*)(key_p->valuep)) {
        if (!null_flag) {
            if (0 != add_assoc_zval(outer_container_p, (char *) key_p->digest.value, inner_container_p)) {
                PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                        "Unable to get key of a record");
                DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
            }
        } else {
            if (0 != add_assoc_null(outer_container_p, (char *) key_p->digest.value)) {
                PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                        "Unable to get key of a record");
                DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
            }
        }
    } else {
        switch (((as_val*)(key_p->valuep))->type) {
            case AS_STRING:
                if (!null_flag) {
                    if (0 != add_assoc_zval(outer_container_p, key_p->value.string.value, inner_container_p)) {
                        PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                                "Unable to get key of a record");
                        DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
                    }
                } else {
                    if (0 != add_assoc_null(outer_container_p, key_p->value.string.value)) {
                        PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                                "Unable to get key of a record");
                        DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
                    }
                }
                break;
            case AS_INTEGER:
                if (!null_flag) {
                    if (FAILURE == add_index_zval(outer_container_p, key_p->value.integer.value,
                                inner_container_p)) {
                        PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                                "Unable to get key of a record");
                        DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
                    }
                } else {
                    if (0 != add_index_null(outer_container_p, key_p->value.integer.value)) {
                        PHP_EXT_SET_AS_ERR(error_p, AEROSPIKE_ERR,
                                "Unable to get key of a record");
                        DEBUG_PHP_EXT_DEBUG("Unable to get key of a record");
                    }
                }
                break;
            default:
                break;
        }
    }
}
Beispiel #7
0
static HashTable* spl_dllist_object_get_debug_info(zval *obj, int *is_temp) /* {{{{ */
{
	spl_dllist_object     *intern  = Z_SPLDLLIST_P(obj);
	spl_ptr_llist_element *current = intern->llist->head, *next;
	zval tmp, dllist_array;
	zend_string *pnstr;
	int  i = 0;

	*is_temp = 0;

	if (intern->debug_info == NULL) {
		ALLOC_HASHTABLE(intern->debug_info);
		zend_hash_init(intern->debug_info, 1, NULL, ZVAL_PTR_DTOR, 0);
	}

	if (intern->debug_info->u.v.nApplyCount == 0) {

		if (!intern->std.properties) {
			rebuild_object_properties(&intern->std);
		}
		zend_hash_copy(intern->debug_info, intern->std.properties, (copy_ctor_func_t) zval_add_ref);

		pnstr = spl_gen_private_prop_name(spl_ce_SplDoublyLinkedList, "flags", sizeof("flags")-1);
		ZVAL_LONG(&tmp, intern->flags);
		zend_hash_add(intern->debug_info, pnstr, &tmp);
		zend_string_release(pnstr);

		array_init(&dllist_array);

		while (current) {
			next = current->next;

			add_index_zval(&dllist_array, i, &current->data);
			if (Z_REFCOUNTED(current->data)) {
				Z_ADDREF(current->data);
			}
			i++;

			current = next;
		}

		pnstr = spl_gen_private_prop_name(spl_ce_SplDoublyLinkedList, "dllist", sizeof("dllist")-1);
		zend_hash_add(intern->debug_info, pnstr, &dllist_array);
		zend_string_release(pnstr);
	}

	return intern->debug_info;
}
Beispiel #8
0
PHP_METHOD(air_async_waiter, serve) {
	AIR_INIT_THIS;
	zval *request = NULL;
	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &request) == FAILURE){
		AIR_NEW_EXCEPTION(1, "invalid serve param");
	}

	zval *service = NULL;
	MAKE_STD_ZVAL(service);
	object_init_ex(service, air_async_service_ce);
	zend_call_method_with_2_params(&service, air_async_service_ce, NULL, "__construct", NULL, self, request);
	zval *services = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_services"), 0 TSRMLS_CC);
	zval *service_id = zend_read_property(Z_OBJCE_P(service), service, ZEND_STRL("_id"), 1 TSRMLS_CC);
	add_index_zval(services, Z_LVAL_P(service_id), service);
	RETURN_ZVAL(service, 1, 0);
}
Beispiel #9
0
static HashTable* spl_heap_object_get_debug_info_helper(zend_class_entry *ce, zval *obj, int *is_temp) { /* {{{ */
	spl_heap_object *intern  = Z_SPLHEAP_P(obj);
	zval tmp, heap_array;
	zend_string *pnstr;
	int  i;

	*is_temp = 0;

	if (!intern->std.properties) {
		rebuild_object_properties(&intern->std);
	}

	if (intern->debug_info == NULL) {
		ALLOC_HASHTABLE(intern->debug_info);
		ZEND_INIT_SYMTABLE_EX(intern->debug_info, zend_hash_num_elements(intern->std.properties) + 1, 0);
	}

	if (intern->debug_info->u.v.nApplyCount == 0) {

		zend_hash_copy(intern->debug_info, intern->std.properties, (copy_ctor_func_t) zval_add_ref);

		pnstr = spl_gen_private_prop_name(ce, "flags", sizeof("flags")-1);
		ZVAL_LONG(&tmp, intern->flags);
		zend_hash_update(intern->debug_info, pnstr, &tmp);
		zend_string_release(pnstr);

		pnstr = spl_gen_private_prop_name(ce, "isCorrupted", sizeof("isCorrupted")-1);
		ZVAL_BOOL(&tmp, intern->heap->flags&SPL_HEAP_CORRUPTED);
		zend_hash_update(intern->debug_info, pnstr, &tmp);
		zend_string_release(pnstr);

		array_init(&heap_array);

		for (i = 0; i < intern->heap->count; ++i) {
			add_index_zval(&heap_array, i, &intern->heap->elements[i]);
			if (Z_REFCOUNTED(intern->heap->elements[i])) {
				Z_ADDREF(intern->heap->elements[i]);
			}
		}

		pnstr = spl_gen_private_prop_name(ce, "heap", sizeof("heap")-1);
		zend_hash_update(intern->debug_info, pnstr, &heap_array);
		zend_string_release(pnstr);
	}

	return intern->debug_info;
}
    void KPHPArrayObject::AddKrollValueToPHPArray(KValueRef value, zval *phpArray, unsigned int index)
    {
        if (value->IsNull() || value->IsUndefined())
        {
            add_index_null(phpArray, (unsigned long) index);
        }
        else if (value->IsBool())
        {
            if (value->ToBool())
                add_index_bool(phpArray, (unsigned long) index, 1);
            else
                add_index_bool(phpArray, (unsigned long) index, 0);
        }
        else if (value->IsNumber())
        {
            /* No way to check whether the number is an
               integer or a double here. All Kroll numbers
               are doubles, so return a double. This could
               cause some PHP to function incorrectly if it's
               doing strict type checking. */
            add_index_double(phpArray, (unsigned long) index, value->ToNumber());
        }
        else if (value->IsString())
        {
            add_index_stringl(phpArray, (unsigned long) index, (char *) value->ToString(), strlen(value->ToString()), 1);
        }
        else if (value->IsObject())
        {
            /*TODO: Implement*/
        }
        else if (value->IsMethod())
        {
            /*TODO: Implement*/
        }
        else if (value->IsList())
        {
            zval *phpValue;
            AutoPtr<KPHPArrayObject> pl = value->ToList().cast<KPHPArrayObject>();
            if (!pl.isNull())
                phpValue = pl->ToPHP();
            else
                phpValue = PHPUtils::ToPHPValue(value);

            add_index_zval(phpArray, (unsigned long) index, phpValue);
        }
    }
Beispiel #11
0
    FOREACH_KEYVAL(pos, param, key, entry) {
        if (key.type == HASH_KEY_IS_STRING) {
            if (PHP_ICONV_ERR_SUCCESS != php_iconv_string(key.str, key.len-1, &xkey, &xlen, oe, ie)) {
                http_error_ex(HE_WARNING, HTTP_E_QUERYSTRING, "Failed to convert '%.*s' from '%s' to '%s'", key.len-1, key.str, ie, oe);
                return FAILURE;
            }
        }

        if (Z_TYPE_PP(entry) == IS_STRING) {
            if (PHP_ICONV_ERR_SUCCESS != php_iconv_string(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry), &xlate_str, &xlate_len, oe, ie)) {
                if (key.type == HASH_KEY_IS_STRING) {
                    efree(xkey);
                }
                http_error_ex(HE_WARNING, HTTP_E_QUERYSTRING, "Failed to convert '%.*s' from '%s' to '%s'", Z_STRLEN_PP(entry), Z_STRVAL_PP(entry), ie, oe);
                return FAILURE;
            }
            if (key.type == HASH_KEY_IS_STRING) {
                add_assoc_stringl_ex(array, xkey, xlen+1, xlate_str, xlate_len, 0);
            } else {
                add_index_stringl(array, key.num, xlate_str, xlate_len, 0);
            }
        } else if (Z_TYPE_PP(entry) == IS_ARRAY) {
            zval *subarray;

            MAKE_STD_ZVAL(subarray);
            array_init(subarray);
            if (key.type == HASH_KEY_IS_STRING) {
                add_assoc_zval_ex(array, xkey, xlen+1, subarray);
            } else {
                add_index_zval(array, key.num, subarray);
            }
            if (SUCCESS != http_querystring_xlate(subarray, *entry, ie, oe)) {
                if (key.type == HASH_KEY_IS_STRING) {
                    efree(xkey);
                }
                return FAILURE;
            }
        }

        if (key.type == HASH_KEY_IS_STRING) {
            efree(xkey);
        }
    }
Beispiel #12
0
static HashTable* spl_dllist_object_get_debug_info(zend_object *obj, int *is_temp) /* {{{{ */
{
	spl_dllist_object     *intern  = spl_dllist_from_obj(obj);
	spl_ptr_llist_element *current = intern->llist->head, *next;
	zval tmp, dllist_array;
	zend_string *pnstr;
	int  i = 0;
	HashTable *debug_info;
	*is_temp = 1;

	if (!intern->std.properties) {
		rebuild_object_properties(&intern->std);
	}

	debug_info = zend_new_array(1);
	zend_hash_copy(debug_info, intern->std.properties, (copy_ctor_func_t) zval_add_ref);

	pnstr = spl_gen_private_prop_name(spl_ce_SplDoublyLinkedList, "flags", sizeof("flags")-1);
	ZVAL_LONG(&tmp, intern->flags);
	zend_hash_add(debug_info, pnstr, &tmp);
	zend_string_release_ex(pnstr, 0);

	array_init(&dllist_array);

	while (current) {
		next = current->next;

		add_index_zval(&dllist_array, i, &current->data);
		if (Z_REFCOUNTED(current->data)) {
			Z_ADDREF(current->data);
		}
		i++;

		current = next;
	}

	pnstr = spl_gen_private_prop_name(spl_ce_SplDoublyLinkedList, "dllist", sizeof("dllist")-1);
	zend_hash_add(debug_info, pnstr, &dllist_array);
	zend_string_release_ex(pnstr, 0);

	return debug_info;
}
static PHP_METHOD(midgard_query_row, get_values)
{
	if (zend_parse_parameters_none() == FAILURE)
		                return;

	MidgardQueryRow *row = MIDGARD_QUERY_ROW(__php_gobject_ptr(getThis()));
	GValueArray *varray = midgard_query_row_get_values(row, NULL); 
	array_init (return_value);
	if (varray == NULL)
		return;

	guint i;
	for (i = 0; i < varray->n_values; i++) {
		GValue *val = g_value_array_get_nth(varray, i);
		zval *z_val;
		MAKE_STD_ZVAL(z_val);
		php_midgard_gvalue2zval(val, z_val TSRMLS_CC);
		add_index_zval(return_value, i, z_val);
	}

	g_value_array_free (varray);
}
Beispiel #14
0
/* {{{ php_parsekit_parse_op_array */
static void php_parsekit_parse_op_array(zval *return_value, zend_op_array *ops, long options TSRMLS_DC)
{
	zend_op *op;
	zval *tmpzval;
	int i = 0;

	/* TODO: Reorder / Organize */

	array_init(return_value);

	add_assoc_long(return_value, "type", (long)(ops->type));
	add_assoc_string(return_value, "type_name", php_parsekit_define_name(ops->type, php_parsekit_function_types, PHP_PARSEKIT_FUNCTYPE_UNKNOWN), 1);
	if (ops->function_name) {
		add_assoc_string(return_value, "function_name", ops->function_name, 1);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "function_name");
	}

#ifdef ZEND_ENGINE_2
/* ZE2 op_array members */
	if (ops->scope && ops->scope->name) {
		add_assoc_stringl(return_value, "scope", ops->scope->name, ops->scope->name_length, 1);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "scope");
	}
	add_assoc_long(return_value, "fn_flags", ops->fn_flags);
	if (ops->function_name && ops->prototype) {
		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		add_assoc_long(tmpzval, "type", ops->prototype->type);
		add_assoc_string(return_value, "type_name", php_parsekit_define_name(ops->prototype->type, php_parsekit_function_types, PHP_PARSEKIT_FUNCTYPE_UNKNOWN), 1);
		if (ops->prototype->common.function_name) {
			add_assoc_string(tmpzval, "function_name", ops->prototype->common.function_name, 1);
		} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
			add_assoc_null(tmpzval, "function_name");
		}
		if (ops->prototype->common.scope && ops->prototype->common.scope->name) {
			add_assoc_stringl(tmpzval, "scope", ops->prototype->common.scope->name, ops->prototype->common.scope->name_length, 1);
		} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
			add_assoc_null(tmpzval, "scope");
		}
		add_assoc_zval(return_value, "prototype", tmpzval);		
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "prototype");
	}
	add_assoc_long(return_value, "num_args", ops->num_args);
	add_assoc_long(return_value, "required_num_args", ops->required_num_args);
	add_assoc_bool(return_value, "pass_rest_by_reference", ops->pass_rest_by_reference);

	if (ops->num_args && ops->arg_info) {
		MAKE_STD_ZVAL(tmpzval);
		php_parsekit_parse_arginfo(tmpzval, ops->num_args, ops->arg_info, options TSRMLS_CC);
		add_assoc_zval(return_value, "arg_info", tmpzval);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "arg_info");
	}

	if (ops->last_try_catch > 0) {
		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		for(i = 0; i < ops->last_try_catch; i++) {
			zval *tmp_zval;

			MAKE_STD_ZVAL(tmp_zval);
			array_init(tmp_zval);
			add_assoc_long(tmp_zval, "try_op", ops->try_catch_array[i].try_op);
			add_assoc_long(tmp_zval, "catch_op", ops->try_catch_array[i].catch_op);
			add_index_zval(tmpzval, i, tmp_zval);
		}
		add_assoc_zval(return_value, "try_catch_array", tmpzval);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "try_catch_array");
	}

#ifndef ZEND_ACC_CLOSURE
/* PHP<5.3 */
	add_assoc_bool(return_value, "uses_this", ops->uses_this);
#endif
	add_assoc_long(return_value, "line_start", ops->line_start);
	add_assoc_long(return_value, "line_end", ops->line_end);

	if (ops->doc_comment && ops->doc_comment_len) {
		add_assoc_stringl(return_value, "doc_comment", ops->doc_comment, ops->doc_comment_len, 1);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "doc_comment");
	}

#else
/* ZE1 op_array members */

	if (ops->arg_types) {
		zend_uchar *arg_types = ops->arg_types;
		int numargs = *(ops->arg_types);

		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		add_assoc_long(tmpzval, "arg_count", numargs);

		for(i = 0; i < numargs; i++) {
			add_next_index_long(tmpzval, arg_types[i+1]);
		}

		add_assoc_zval(return_value, "arg_types", tmpzval);

		/* Emulated arg_info */
		MAKE_STD_ZVAL(tmpzval);
		php_parsekit_derive_arginfo(tmpzval, ops, options TSRMLS_CC);
		add_assoc_zval(return_value, "arg_info", tmpzval);
	} else {
		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		add_assoc_long(tmpzval, "arg_count", 0);

		add_assoc_zval(return_value, "arg_types", tmpzval);
		add_assoc_null(return_value, "arg_info");
	}

	add_assoc_bool(return_value, "uses_global", ops->uses_globals);
#endif
/* ZE1 and ZE2 */

	add_assoc_bool(return_value, "return_reference", ops->return_reference);
	add_assoc_long(return_value, "refcount", *(ops->refcount));
	add_assoc_long(return_value, "last", ops->last);
	add_assoc_long(return_value, "size", ops->size);
	add_assoc_long(return_value, "T", ops->T);
	add_assoc_long(return_value, "last_brk_cont", ops->last_brk_cont);
	add_assoc_long(return_value, "current_brk_cont", ops->current_brk_cont);
	add_assoc_long(return_value, "backpatch_count", ops->backpatch_count);
	add_assoc_bool(return_value, "done_pass_two", ops->done_pass_two);

	if (ops->last_brk_cont > 0) {
		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		for(i = 0; i < ops->last_brk_cont; i++) {
			zval *tmp_zval;

			MAKE_STD_ZVAL(tmp_zval);
			array_init(tmp_zval);
			add_assoc_long(tmp_zval, "cont", ops->brk_cont_array[i].cont);
			add_assoc_long(tmp_zval, "brk", ops->brk_cont_array[i].brk);
			add_assoc_long(tmp_zval, "parent", ops->brk_cont_array[i].parent);
			add_index_zval(tmpzval, i, tmp_zval);
		}
		add_assoc_zval(return_value, "brk_cont_array", tmpzval);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "brk_cont_array");
	}

	if (ops->static_variables) {
		zval *tmp_zval;

		MAKE_STD_ZVAL(tmpzval);
		array_init(tmpzval);
		zend_hash_copy(HASH_OF(tmpzval), ops->static_variables, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_zval, sizeof(zval *));
		add_assoc_zval(return_value, "static_variables", tmpzval);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "static_variables");
	}

	if (ops->start_op) {
		char sop[(sizeof(void *) * 2) + 1];

		snprintf(sop, sizeof(sop), "%X", (unsigned int)ops->start_op); 
		add_assoc_string(return_value, "start_op", sop, 1);
	} else if (options & PHP_PARSEKIT_ALWAYS_SET) {
		add_assoc_null(return_value, "start_op");
	}

	if (ops->filename) {
		add_assoc_string(return_value, "filename", ops->filename, 1);
	} else {
		add_assoc_null(return_value, "filename");
	}

	/* Leave this last, it simplifies readability */
	MAKE_STD_ZVAL(tmpzval);
	array_init(tmpzval);
	for(op = ops->opcodes, i = 0; op && i < ops->size; op++, i++) {
		zval *zop;

		MAKE_STD_ZVAL(zop);
		php_parsekit_parse_op(zop, ops, op, options TSRMLS_CC);
		add_next_index_zval(tmpzval, zop);
	}	
	add_assoc_zval(return_value, "opcodes", tmpzval);

}
Beispiel #15
0
/* {{{ */
static inline zend_string* php_memoize_args(uint32_t argc, const zval *argv) {
	php_serialize_data_t data;
	zval serial;
	uint32_t it;
	smart_str smart = {0};

	ZVAL_UNDEF(&serial);

	switch (argc) {
		case 0:
			return zend_string_copy(CG(empty_string));

		case 1: {
			switch (Z_TYPE_P(argv)) {
				case IS_STRING:
					return zend_string_copy(Z_STR_P(argv));

				case IS_LONG:
				case IS_DOUBLE:
					return zval_get_string((zval*) argv);

				case IS_TRUE:
					return zend_string_copy(PHP_MEMOIZE_STRING_TRUE);

				case IS_FALSE:
					return zend_string_copy(PHP_MEMOIZE_STRING_FALSE);

				case IS_NULL:
					return zend_string_copy(PHP_MEMOIZE_STRING_NULL);
			}

			ZVAL_COPY(&serial, argv);
		}

		/* intentionally fall through */

		default: {
			if (Z_TYPE(serial) == IS_UNDEF) {
				array_init(&serial);

				for (it = 0; it < argc; it++) {
					if (add_index_zval(&serial, it, (zval*) argv + it) == SUCCESS) {
						Z_TRY_ADDREF_P((zval*) argv + it);
					}
				}	
			}

			PHP_VAR_SERIALIZE_INIT(data);
			php_var_serialize(&smart, &serial, &data);
			PHP_VAR_SERIALIZE_DESTROY(data);

			if (EG(exception)) {
				zval_ptr_dtor(&serial);
				zend_clear_exception();
				return NULL;
			}
		}
	}

	zval_ptr_dtor(&serial);
	return smart.s;
} /* }}} */
Beispiel #16
0
/* {{{ proto Util::array_pluck(array $array, string $field[, bool $preserve_keys, bool $remove_nomatches])
   Replaces each value in an array with the specified field of the array or object that used to be the value. Very useful when you have an array of objects or arrays from a database, and you only want one specific field. For example, you want an array of emails from an array of users. */
ZEND_METHOD(util, array_pluck)
{
	zval *arr;
	char *key;
	uint keylen;
	zend_bool preserve_keys = 1;
	zend_bool remove_nomatches = 1;
	zend_bool silent = 1;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "as|bb", &arr, &key, &keylen, &preserve_keys, &remove_nomatches) == FAILURE) {
		RETURN_NULL();
	}

	zval **item;
	HashPosition pointer;
	HashTable* arr_hash = Z_ARRVAL_P(arr);
	array_init(return_value);

	zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
	while (zend_hash_get_current_data_ex(arr_hash, (void**) &item, &pointer) == SUCCESS) {
		zval *zvalue;
		MAKE_STD_ZVAL(zvalue);
		ZVAL_NULL(zvalue);
		zval *temp;
		MAKE_STD_ZVAL(temp);
		*temp = **item;
		zval_copy_ctor(temp);

		if (Z_TYPE_P(temp) == IS_OBJECT) {
			zend_class_entry *object;
			object = Z_OBJCE_P(temp);
			zval *temp_data;
			temp_data = zend_read_property(object, temp, key, keylen, silent TSRMLS_CC);
			*zvalue = *temp_data;
		} else {
			zval **temp_data;
			if (zend_hash_find(Z_ARRVAL_P(temp), key, keylen + 1, (void**) &temp_data) == SUCCESS) {
				*zvalue = **temp_data;
			}
		}

		char *type_key;
		uint type_keylen;
		ulong idx;

		if (Z_TYPE_P(zvalue) != IS_NULL) {
			if (preserve_keys) {
				int type = zend_hash_get_current_key_ex(arr_hash, &type_key, &type_keylen, &idx, 0, &pointer);
				if (type == HASH_KEY_IS_LONG) {
					add_index_zval(return_value, idx, zvalue);
				} else {
					add_assoc_zval(return_value, type_key, zvalue);
				}
			} else {
				add_next_index_zval(return_value, zvalue);
			}
		} else if (!remove_nomatches) {
			int type = zend_hash_get_current_key_ex(arr_hash, &type_key, &type_keylen, &idx, 0, &pointer);
			if (type == HASH_KEY_IS_LONG) {
				add_index_zval(return_value, idx, temp);
			} else {
				add_assoc_zval(return_value, type_key, temp);
			}
		}
		zend_hash_move_forward_ex(arr_hash, &pointer);
	}
	return;
}
Beispiel #17
0
PHP_METHOD(air_mysql_waiter, step_0) {
	AIR_INIT_THIS;
	zval *services = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_services"), 0 TSRMLS_CC);
	zval *responses = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_responses"), 0 TSRMLS_CC);
	zval *context = zend_read_property(Z_OBJCE_P(self), self, ZEND_STRL("_context"), 0 TSRMLS_CC);
	zend_class_entry *mysqli_ce = air_get_ce(ZEND_STRL("mysqli") TSRMLS_CC);
	zval *async;
	MAKE_STD_ZVAL(async);
	ZVAL_LONG(async, MYSQLI_ASYNC);

	zval *wait_pool, *m2s;
	MAKE_STD_ZVAL(wait_pool);
	array_init(wait_pool);
	MAKE_STD_ZVAL(m2s);
	array_init(m2s);

	zval *service;
	ulong idx;
	uint _idx, key_len;
	char *key;
	zval *mysqli = NULL;
	HashTable *ah = Z_ARRVAL_P(services);
	for(zend_hash_internal_pointer_reset(ah);
			zend_hash_has_more_elements(ah) == SUCCESS;){
		zval **___tmp;
		if (zend_hash_get_current_data(ah, (void**)&___tmp) == FAILURE) {
			continue;
		}
		if(zend_hash_get_current_key_ex(ah, &key, &key_len, &idx, 0, NULL) != HASH_KEY_IS_STRING) {
			key = NULL; key_len = 0;
		}
		service = *___tmp;
		if(Z_TYPE_P(service) == IS_NULL){
			zend_hash_index_del(ah, idx);
			continue;
		}
		zval *service_id = zend_read_property(air_async_service_ce, service, ZEND_STRL("_id"), 1 TSRMLS_CC);
		zval *mysql = zend_read_property(air_async_service_ce, service, ZEND_STRL("_request"), 1 TSRMLS_CC);
		zval *status = zend_read_property(air_mysql_ce, mysql, ZEND_STRL("_status"), 0 TSRMLS_CC);
		if(Z_LVAL_P(status)){
			//ignore if the mysql's been executed
			zend_hash_index_del(ah, idx);
			continue;
		}
		zval *mysql_config = zend_read_property(air_mysql_ce, mysql, ZEND_STRL("_config"), 1 TSRMLS_CC);
		zval *mode = zend_read_property(air_mysql_ce, mysql, ZEND_STRL("_mode"), 1 TSRMLS_CC);
		if(Z_TYPE_P(mode) == IS_NULL){
			air_mysql_auto_mode(mysql TSRMLS_CC);
			mode = zend_read_property(air_mysql_ce, mysql, ZEND_STRL("_mode"), 1 TSRMLS_CC);
		}
		zval **acquire_params[2] = {&mysql_config, &mode};
		mysqli = NULL;
		air_call_static_method(air_mysql_keeper_ce, "acquire", &mysqli, 2, acquire_params);
		if(Z_TYPE_P(mysqli) != IS_NULL){
			zval **build_params[1] = {&mysqli};
			zval *sql = NULL;
			air_call_method(&mysql, air_mysql_ce, NULL, ZEND_STRL("build"), &sql, 1, build_params TSRMLS_CC);
			if(sql){
				zval **query_params[2] = {&sql, &async};
				air_call_method(&mysqli, mysqli_ce, NULL, ZEND_STRL("query"), NULL, 2, query_params TSRMLS_CC);
				add_next_index_zval(wait_pool, mysqli);
				Z_ADDREF_P(service_id);
				add_index_zval(m2s, air_mysqli_get_id(mysqli TSRMLS_CC), service_id);
				zval_ptr_dtor(&sql);
			}else{
				//should not happen
				php_error(E_ERROR, "sql not found");
				zval_ptr_dtor(&mysqli);
			}
		}else{
			zval_ptr_dtor(&mysqli);
		}
		zend_hash_move_forward(ah);
	}
	zval_ptr_dtor(&async);
	add_assoc_zval(context, "pool", wait_pool);
	add_assoc_zval(context, "m2s", m2s);
	add_assoc_long(context, "waited", zend_hash_num_elements(Z_ARRVAL_P(wait_pool)));
	add_assoc_long(context, "processed", 0);
	add_assoc_long(context, "step", 1);
}