diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2015-01-13 22:47:44 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2015-01-13 22:47:44 +0100 |
commit | e14d8c6f985aeaeb247387b51d6ec027655efb99 (patch) | |
tree | af2baf1e73668fe994bb6254a35b507b664f2fc0 | |
parent | 75944e3e755053bc2ebe9a2a8c55575941f79a56 (diff) |
in response to issue #156: the super-global arrays Php::POST, Php::SERVER, etcetera can now be iterated over, and they can be assigned to a regular Php::Value variable
-rw-r--r-- | include/super.h | 49 | ||||
-rw-r--r-- | include/value.h | 2 | ||||
-rw-r--r-- | phpcpp.h | 2 | ||||
-rw-r--r-- | zend/includes.h | 2 | ||||
-rw-r--r-- | zend/super.cpp | 32 |
5 files changed, 53 insertions, 34 deletions
diff --git a/include/super.h b/include/super.h index 97ba6b8..7b568e0 100644 --- a/include/super.h +++ b/include/super.h @@ -41,7 +41,11 @@ public: * @param key * @return Value */ - Value operator[](const std::string &key); + Value operator[](const std::string &key) + { + // convert object to a value object, and retrieve the key + return value()[key]; + } /** * Array access operator @@ -49,7 +53,41 @@ public: * @param key * @return Value */ - Value operator[](const char *key); + Value operator[](const char *key) + { + // convert object to a value object, and retrieve the key + return value()[key]; + } + + /** + * Casting operator to cast to a value object + * @return Value + */ + operator Value () + { + // we have a private function for this + return value(); + } + + /** + * Return an iterator for iterating over the variables + * @return iterator + */ + ValueIterator begin() + { + // convert to value, and call begin on the value object + return value().begin(); + } + + /** + * Return an iterator for iterating over the variables + * @return iterator + */ + ValueIterator end() + { + // convert to value, and call end on that object + return value().end(); + } private: /** @@ -63,6 +101,13 @@ private: * @var name */ const char *_name; + + /** + * Turn the object into a value object + * @return Value + */ + Value value(); + }; /** diff --git a/include/value.h b/include/value.h index 363779d..c3de4d5 100644 --- a/include/value.h +++ b/include/value.h @@ -1144,7 +1144,7 @@ protected: void setRaw(const char *key, int size, const Value &value); /** - * Internal helper method to create an iterator + * Internal helper method to create an ` * @param begin Should the iterator start at the begin? * @return iterator */ @@ -44,8 +44,8 @@ #include <phpcpp/byval.h> #include <phpcpp/byref.h> #include <phpcpp/global.h> -#include <phpcpp/super.h> #include <phpcpp/hashmember.h> +#include <phpcpp/super.h> #include <phpcpp/parameters.h> #include <phpcpp/modifiers.h> #include <phpcpp/base.h> diff --git a/zend/includes.h b/zend/includes.h index 0b6a138..1552778 100644 --- a/zend/includes.h +++ b/zend/includes.h @@ -63,8 +63,8 @@ #include "../include/byval.h" #include "../include/byref.h" #include "../include/global.h" -#include "../include/super.h" #include "../include/hashmember.h" +#include "../include/super.h" #include "../include/parameters.h" #include "../include/modifiers.h" #include "../include/base.h" diff --git a/zend/super.cpp b/zend/super.cpp index a2fa0a9..ea690fe 100644 --- a/zend/super.cpp +++ b/zend/super.cpp @@ -23,33 +23,10 @@ Super FILES (TRACK_VARS_FILES, "_FILES"); Super REQUEST (TRACK_VARS_REQUEST, "_REQUEST"); /** - * Array access operator - * This can be used for accessing associative arrays - * @param key + * Convert object to a value * @return Value */ -Value Super::operator[](const std::string &key) -{ - // we need the tsrm_ls pointer - TSRMLS_FETCH(); - - // call zend_is_auto_global to ensure that the just-in-time globals are loaded - if (_name) { zend_is_auto_global(_name, ::strlen(_name) TSRMLS_CC); _name = nullptr; } - - // create a value object that wraps around the actual zval - Value value(PG(http_globals)[_index]); - - // pass on the call - return value.get(key); -} - -/** - * Array access operator - * This can be used for accessing associative arrays - * @param key - * @return Value - */ -Value Super::operator[](const char *key) +Value Super::value() { // we need the tsrm_ls pointer TSRMLS_FETCH(); @@ -58,10 +35,7 @@ Value Super::operator[](const char *key) if (_name) { zend_is_auto_global(_name, ::strlen(_name) TSRMLS_CC); _name = nullptr; } // create a value object that wraps around the actual zval - Value value(PG(http_globals)[_index]); - - // pass on the call - return value.get(key); + return Value(PG(http_globals)[_index]); } /** |