From c8d1519f31baed0fb399dac9333e48e2f9e910ad Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sat, 1 Mar 2014 10:32:26 +0100 Subject: namespace implementation, compile issue for php 5.4 and higher --- include/extension.h | 95 +++++++++++++++++------------------------------------ 1 file changed, 31 insertions(+), 64 deletions(-) (limited to 'include/extension.h') diff --git a/include/extension.h b/include/extension.h index 4a89cf9..72c7d56 100644 --- a/include/extension.h +++ b/include/extension.h @@ -28,21 +28,10 @@ struct _zend_module_entry; */ namespace Php { -/** - * A couple of predefined native callback functions that can be registered. - * These are functions that optional accept a Request and/or Parameters object, - * and that either return void or a Value object. - */ -typedef void (*native_callback_0)(); -typedef void (*native_callback_1)(Parameters &); -typedef Value (*native_callback_2)(); -typedef Value (*native_callback_3)(Parameters &); - /** * Forward declaration */ class Extension; -class Function; /** * Optional callback types for starting and stopping the request @@ -53,7 +42,7 @@ typedef bool (*request_callback)(Extension *extension); /** * Class definition */ -class Extension +class Extension : public Namespace { public: /** @@ -77,36 +66,36 @@ public: virtual ~Extension(); /** - * Initialize the extension. - * - * This method is called after the extension has been loaded, constructed - * and after the compatibility has been checked, but before the requests - * are handled. You can override this method to add your own initialization. - * - * The default behavior of this function is to enable all classes that are - * defined in this extension, so that they are also available in PHP. + * Initialize the extension after it was registered * - * The method should return true on success, and false on failure (in which - * case the extension will not be used) + * You can override this method to add your own initialization code. The + * default implementation registers all classes and namespaces * * @return bool */ - virtual bool initialize(); + virtual bool initialize() + { + // initialize the namespace + Namespace::initialize(""); + + // ok + return true; + } /** - * Finalize the extension - * - * This method gets called after all requests were handled, and right before - * the Apache module or CLI script will exit. You can override it to add - * your own cleanup code. + * Finalize the extension after it was registered + * + * You can override this method to do your own cleanup right before the + * extension object is going to be destructed * * @return bool */ virtual bool finalize() { + // ok return true; } - + /** * Start a request * @@ -142,32 +131,6 @@ public: return _stop(this); } - /** - * Add a native function directly to the extension - * @param name Name of the function - * @param function The function to add - * @param arguments Optional argument specification - */ - void add(const char *name, native_callback_0 function, const Arguments &arguments = {}); - void add(const char *name, native_callback_1 function, const Arguments &arguments = {}); - void add(const char *name, native_callback_2 function, const Arguments &arguments = {}); - void add(const char *name, native_callback_3 function, const Arguments &arguments = {}); - - /** - * Add a native class to the extension - * @param name Name of the class - * @param type The class implementation - */ - template - void add(const Class &type) - { - // make a copy of the object - auto *info = new Class(type); - - // and copy it to the list of classes - _classes.insert(std::unique_ptr(info)); - } - /** * Retrieve the module entry * @@ -178,19 +141,23 @@ public: */ _zend_module_entry *module(); - -private: /** - * Functions defined in the library - * @var set + * Cast to a module entry + * @return _zend_module_entry* */ - std::set> _functions; - + operator _zend_module_entry * () + { + return module(); + } + +private: /** - * Classes defined in the library, indexed by their name - * @var set + * Initialize all functions in this namespace + * @param ns Namespace prefix + * @param entries The array to be filled + * @return int Number of functions that were initialized */ - std::set> _classes; + size_t initialize(const std::string &ns, zend_function_entry entries[]); /** * The information that is passed to the Zend engine -- cgit v1.2.3