From 68fd128d82819db1022137a45ca3224cee8ef029 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Wed, 11 Sep 2013 08:00:28 -0700 Subject: The environment object that is passed to functions now always is the same environment object, added move operator= to Value class to make moving zvals faster, and added request startup and request closedown methods --- include/extension.h | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'include/extension.h') diff --git a/include/extension.h b/include/extension.h index b322533..ceeed78 100644 --- a/include/extension.h +++ b/include/extension.h @@ -28,6 +28,11 @@ struct _zend_module_entry; */ namespace Php { +/** + * Optional callback types for starting and stopping the request + */ +typedef bool (*request_callback)(Environment &); + /** * A couple of predefined native callback functions that can be registered. * These are functions that optional accept a Request and/or Parameters object, @@ -52,9 +57,10 @@ public: * Constructor that defines a number of functions right away * @param name Extension name * @param version Extension version string - * @param functions The functions that are defined + * @param callback Function that is called when request starts + * @param callback Function that is called when request ends */ - Extension(const char *name = NULL, const char *version = NULL); + Extension(const char *name = NULL, const char *version = NULL, request_callback start = NULL, request_callback stop = NULL); /** * No copy'ing and no moving @@ -109,6 +115,7 @@ public: */ virtual Environment *createEnvironment() { + // allocate the environment return new Environment(this); } @@ -121,6 +128,7 @@ public: */ virtual void deleteEnvironment(Environment *environment) { + // destruct the environment delete environment; } @@ -133,9 +141,13 @@ public: * * @return boolean */ - bool startRequest(Environment &environment) + virtual bool startRequest(Environment &environment) { - return true; + // ok if no callback was set + if (!_start) return true; + + // call the callback function + return _start(environment); } /** @@ -146,9 +158,13 @@ public: * * @return boolean */ - bool endRequest(Environment &environment) + virtual bool endRequest(Environment &environment) { - return true; + // ok if no callback is set + if (!_stop) return true; + + // call callback + return _stop(environment); } /** @@ -212,6 +228,18 @@ private: */ _zend_module_entry *_entry; + /** + * Callback that is called before each request + * @var request_callback + */ + request_callback _start; + + /** + * Callback that is called after each request + * @var request_callback + */ + request_callback _stop; + }; /** -- cgit v1.2.3