diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-07-26 13:39:16 +0200 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-07-26 13:39:16 +0200 |
commit | 340b05438b13fbe7cd937835e1abe935967330d3 (patch) | |
tree | 36099ce148c3278c10d4e203769818b16a7150fc | |
parent | ff83769a9d5fc2f0f88cd42bdb3355f509294ad9 (diff) |
renamed fastcall.cpp to eval.cpp, and moved the Php::eval() definition to the call.h header file
-rw-r--r-- | include/call.h | 5 | ||||
-rw-r--r-- | include/fastcall.h | 13 | ||||
-rw-r--r-- | phpcpp.h | 1 | ||||
-rw-r--r-- | zend/eval.cpp | 56 | ||||
-rw-r--r-- | zend/fastcall.cpp | 40 | ||||
-rw-r--r-- | zend/includes.h | 1 |
6 files changed, 61 insertions, 55 deletions
diff --git a/include/call.h b/include/call.h index 16de1fe..05c5955 100644 --- a/include/call.h +++ b/include/call.h @@ -13,6 +13,11 @@ namespace Php { /** + * List of functions that are available for use in PHP + */ +Value eval(const std::string &phpCode); + +/** * Call a function in PHP * @param name Name of the function to call * @param params Variable number of parameters diff --git a/include/fastcall.h b/include/fastcall.h deleted file mode 100644 index 29f274d..0000000 --- a/include/fastcall.h +++ /dev/null @@ -1,13 +0,0 @@ -/** - * fastcall.h - * - * This file holds some PHP functions implementation in C directly. - * - */ - -namespace Php { - - Value eval(const std::string &phpCode); - -} - @@ -60,7 +60,6 @@ #include <phpcpp/namespace.h> #include <phpcpp/extension.h> #include <phpcpp/call.h> -#include <phpcpp/fastcall.h> /** * Macro to export a function diff --git a/zend/eval.cpp b/zend/eval.cpp new file mode 100644 index 0000000..e0baaed --- /dev/null +++ b/zend/eval.cpp @@ -0,0 +1,56 @@ +/** + * Eval.cpp + * + * This file holds the implementation for the Php::eval() function + * + * @author andot <https://github.com/andot> + */ + +/** + * Dependencies + */ +#include "includes.h" + +/** + * Open PHP namespace + */ +namespace Php { + +/** + * Evaluate a PHP string + * @param phpCode The PHP code to evaluate + * @return Value The result of the evaluation + */ +Value eval(const std::string &phpCode) +{ + // we need the tsrm_ls variable + TSRMLS_FETCH(); + + // the current exception + zval* oldException = EG(exception); + + // the return zval + zval* retval = nullptr; + if (zend_eval_stringl_ex((char *)phpCode.c_str(), (int32_t)phpCode.length(), retval, (char *)"", 1 TSRMLS_CC) != SUCCESS) + { + // throw an exception, php couldn't evaluate code + throw Exception("PHP eval error"); + + // unreachable, but let's return at least something to prevent compiler warnings + return nullptr; + } + else + { + // was an exception thrown inside the function? In that case we throw a C++ new exception + // to give the C++ code the chance to catch it + if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception) TSRMLS_CC); + + // no (additional) exception was thrown + return retval ? Value(retval) : nullptr; + } +} + +/** + * End of namespace + */ +} diff --git a/zend/fastcall.cpp b/zend/fastcall.cpp deleted file mode 100644 index 3ecd598..0000000 --- a/zend/fastcall.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/** - * fastcall.cpp - * - * This file holds some PHP functions implementation in C directly. - * - */ - -#include "includes.h" - -namespace Php { - - Value eval(const std::string &phpCode) { - // we need the tsrm_ls variable - TSRMLS_FETCH(); - - // the current exception - zval* oldException = EG(exception); - - // the return zval - zval* retval = nullptr; - if (zend_eval_stringl_ex((char *)phpCode.c_str(), (int32_t)phpCode.length(), retval, (char *)"", 1 TSRMLS_CC) != SUCCESS) - { - // throw an exception, php couldn't evaluate code - throw Exception("PHP couldn't evaluate: " + phpCode); - - // unreachable, but let's return at least something to prevent compiler warnings - return nullptr; - } - else - { - // was an exception thrown inside the function? In that case we throw a C++ new exception - // to give the C++ code the chance to catch it - if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception) TSRMLS_CC); - - // no (additional) exception was thrown - return retval ? Value(retval) : nullptr; - } - } - -}
\ No newline at end of file diff --git a/zend/includes.h b/zend/includes.h index 8af557c..63b435e 100644 --- a/zend/includes.h +++ b/zend/includes.h @@ -79,7 +79,6 @@ #include "../include/namespace.h" #include "../include/extension.h" #include "../include/call.h" -#include "../include/fastcall.h" /** * Common header files for internal use only |