From 3953d8833e070fa1d6cc7b264dd19ed56c909f02 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Wed, 9 Apr 2014 10:08:29 +0200 Subject: added support for accessing array keys by other value objects, support for unsetting array members, support for array_key_exists(), isset() and unset() functions (feature request in from issue #71) --- include/call.h | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'include/call.h') diff --git a/include/call.h b/include/call.h index 3ad4776..6c5dd8f 100644 --- a/include/call.h +++ b/include/call.h @@ -44,17 +44,41 @@ Value call(const char *name, Params&&... params) * make the code run on the highway), it is not expected that these functions * are going to be used very often anyway. */ -inline Value array_keys(const Value &value) { return call("array_keys", value); } -inline Value array_values(const Value &value) { return call("array_values", value); } -inline Value echo(const char *input) { out << input; return nullptr; } -inline Value echo(const std::string &input) { out << input; return nullptr; } -inline Value empty(const Value &value) { return value.isNull() || !value.boolValue(); } -inline Value empty(const HashMember &member) { return !member.exists() || empty(member.value()); } -inline Value empty(const HashMember &member) { return !member.exists() || empty(member.value()); } -inline Value ini_get(const Value &value) { return call("ini_get", value); } -//inline Value isset(const Value &value) { return call("isset", value); } -//inline Value isset(const HashMember &member) { return member.exists() && isset(member.value()); } -//inline Value isset(const HashMember &member) { return member.exists() && isset(member.value()); } +inline Value array_key_exists(const Value &key, const Value &array) { return array.contains(key); } +inline Value array_key_exists(int key, const Value &array) { return array.contains(key); } +inline Value array_key_exists(const char *key, const Value &array) { return array.contains(key); } +inline Value array_key_exists(const std::string &key, const Value &array) { return array.contains(key); } +inline Value array_keys(const Value &value) { return call("array_keys", value); } +inline Value array_values(const Value &value) { return call("array_values", value); } +inline Value echo(const char *input) { out << input; return nullptr; } +inline Value echo(const std::string &input) { out << input; return nullptr; } +inline Value empty(const Value &value) { return value.isNull() || !value.boolValue(); } +inline Value empty(const HashMember &member) { return !member.exists() || empty(member.value()); } +inline Value empty(const HashMember &member) { return !member.exists() || empty(member.value()); } +inline Value ini_get(const Value &value) { return call("ini_get", value); } +inline Value is_array(const Value &value) { return value.isArray(); } +inline void unset(HashMember &member) { member.unset(); } +inline void unset(HashMember &member) { member.unset(); } +inline void unset(HashMember &member) { member.unset(); } + +/** + * The isset function conflicts with the 'isset' macro defined by the Zend engine + */ +#pragma push_macro("isset"); +#undef isset + +/** + * Define the isset function + */ +inline Value isset(const Value &value) { return call("isset", value); } +inline Value isset(const HashMember &member) { return member.exists() && isset(member.value()); } +inline Value isset(const HashMember &member) { return member.exists() && isset(member.value()); } +inline Value isset(const HashMember &member) { return member.exists() && isset(member.value()); } + +/** + * Re-install the ISSET macro + */ +#pragma pop_macro("isset"); /** * End of namespace -- cgit v1.2.3