summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Schoenmakers <toon.schoenmakers@copernica.com>2015-09-17 10:47:53 +0200
committerToon Schoenmakers <toon.schoenmakers@copernica.com>2015-09-17 10:47:53 +0200
commit448b1b873537bed4b616c284ba75ce9392f838a9 (patch)
tree54dd039d4581280451490fadc35580db7ec0b5ef
parent2df547bfd3caf93d36b3775f3e748ad52f6e422b (diff)
Added support for passing the error types in the set_error_handler
-rw-r--r--include/call.h2
-rw-r--r--include/errors.h42
-rw-r--r--include/value.h2
-rw-r--r--phpcpp.h1
-rw-r--r--zend/exception_handler.cpp7
-rw-r--r--zend/includes.h1
6 files changed, 51 insertions, 4 deletions
diff --git a/include/call.h b/include/call.h
index 80b3c74..55e9ed6 100644
--- a/include/call.h
+++ b/include/call.h
@@ -47,7 +47,7 @@ inline PHPCPP_EXPORT Value require(const std::string &filename) { return requ
extern PHPCPP_EXPORT Value require_once(const char *filename);
inline PHPCPP_EXPORT Value require_once(const std::string &filename) { return require_once(filename.c_str()); }
extern PHPCPP_EXPORT Value set_exception_handler(const std::function<Value(Parameters &params)> &handler);
-extern PHPCPP_EXPORT Value set_error_handler(const std::function<Value(Parameters &params)> &handler);
+extern PHPCPP_EXPORT Value set_error_handler(const std::function<Value(Parameters &params)> &handler, Error error = Error::All);
extern PHPCPP_EXPORT const char *sapi_name();
/**
diff --git a/include/errors.h b/include/errors.h
new file mode 100644
index 0000000..e1a95d8
--- /dev/null
+++ b/include/errors.h
@@ -0,0 +1,42 @@
+/**
+ * Errors.h
+ *
+ * In this file an enumeration type is defined with all error flags.
+ *
+ * @author Toon Schoenmakers <toon.schoenmakers@copernica.com>
+ * @copyright 2015 Copernica BV
+ */
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * Supported types of errors, this is mostly a copy from Zend/zend_errors.h
+ */
+enum class PHPCPP_EXPORT Error : int {
+ Error = (1 << 0L),
+ Warning = (1 << 1L),
+ Parse = (1 << 2L),
+ Notice = (1 << 3L),
+ CoreError = (1 << 4L),
+ CoreWarning = (1 << 5L),
+ CompileError = (1 << 6L),
+ CompileWarning = (1 << 7L),
+ UserError = (1 << 8L),
+ UserWarning = (1 << 9L),
+ UserNotice = (1 << 10L),
+ Strict = (1 << 11L),
+ RecoverableError = (1 << 12L),
+ Deprecated = (1 << 13L),
+ UserDeprecated = (1 << 14L),
+
+ Core = (CoreError | CoreWarning),
+ All = (Error | Warning | Parse | Notice | CoreError | CoreWarning | CompileError | CompileWarning | UserError | UserWarning | UserNotice | RecoverableError | Deprecated | UserDeprecated )
+};
+
+/**
+ * End of namespace
+ */
+}
diff --git a/include/value.h b/include/value.h
index bfd8e40..8c10bd8 100644
--- a/include/value.h
+++ b/include/value.h
@@ -1215,7 +1215,7 @@ protected:
* Friend functions which have to access that zval directly
*/
friend Value set_exception_handler(const std::function<Value(Parameters &params)> &handler);
- friend Value set_error_handler(const std::function<Value(Parameters &params)> &handler);
+ friend Value set_error_handler(const std::function<Value(Parameters &params)> &handler, Error error);
};
/**
diff --git a/phpcpp.h b/phpcpp.h
index b5385a7..a46d764 100644
--- a/phpcpp.h
+++ b/phpcpp.h
@@ -36,6 +36,7 @@
#include <phpcpp/exception.h>
#include <phpcpp/fatalerror.h>
#include <phpcpp/streams.h>
+#include <phpcpp/errors.h>
#include <phpcpp/type.h>
#include <phpcpp/hashparent.h>
#include <phpcpp/value.h>
diff --git a/zend/exception_handler.cpp b/zend/exception_handler.cpp
index 75361b2..b864e78 100644
--- a/zend/exception_handler.cpp
+++ b/zend/exception_handler.cpp
@@ -43,7 +43,10 @@ Value set_exception_handler(const std::function<Value(Parameters &params)> &hand
return output;
}
-Value set_error_handler(const std::function<Value(Parameters &params)> &handler)
+/**
+ * Set a std::function as a php error handler
+ */
+Value set_error_handler(const std::function<Value(Parameters &params)> &handler, Error error)
{
// create the functor which wraps our callback
Function functor(handler);
@@ -62,7 +65,7 @@ Value set_error_handler(const std::function<Value(Parameters &params)> &handler)
// copy our zval into the user_error_handler
MAKE_COPY_ZVAL(&value, EG(user_error_handler));
- EG(user_error_handler_error_reporting) = (int) (E_ALL | E_STRICT);
+ EG(user_error_handler_error_reporting) = (int) error;
// return the original handler
return output;
diff --git a/zend/includes.h b/zend/includes.h
index aed5ed0..4d35cfd 100644
--- a/zend/includes.h
+++ b/zend/includes.h
@@ -57,6 +57,7 @@
#include "../include/fatalerror.h"
#include "../include/streams.h"
#include "../include/type.h"
+#include "../include/errors.h"
#include "../include/hashparent.h"
#include "../include/value.h"
#include "../include/valueiterator.h"