summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-06 14:44:03 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-06 14:44:03 +0200
commit9bc5d1ed595e0ff0b7cec9a87d06a7923c211ebd (patch)
tree56681046544fce1bad3466a77b62194a4978ec89 /include
parent97269e8159b419fa624980ce70de908f22c4982c (diff)
removed all zend dependencies from the public extension object, and moved it into the src directory
Diffstat (limited to 'include')
-rw-r--r--include/class.h5
-rw-r--r--include/extension.h129
-rw-r--r--include/namespace.h155
3 files changed, 87 insertions, 202 deletions
diff --git a/include/class.h b/include/class.h
index 7b9a928..e0316df 100644
--- a/include/class.h
+++ b/include/class.h
@@ -16,11 +16,6 @@
*/
/**
- * Zend/SPL interfaces that we support
- */
-extern struct _zend_class_entry *zend_ce_arrayaccess;
-
-/**
* Set up namespace
*/
namespace Php {
diff --git a/include/extension.h b/include/extension.h
index f9361b3..84789d3 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -6,7 +6,7 @@
* apache process starts - and will be used for all subsequent requests that
* are handled by Apache.
*
- * For some environments (for example CLI scripts and FastCGI calls) only one
+ * For some environments (for example CLI scripts and CGI calls) only one
* request is handled by an extension instance, but for others (when PHP runs
* as module in a webserver) many requests are handled by the same extension
* instance.
@@ -16,11 +16,6 @@
*/
/**
- * Structures referenced in this class
- */
-struct _zend_module_entry;
-
-/**
* Set up namespace
*/
namespace Php {
@@ -28,7 +23,7 @@ namespace Php {
/**
* Forward declaration
*/
-class Extension;
+class ExtensionImpl;
/**
* Signature of a callback
@@ -46,7 +41,7 @@ public:
* @param name Extension name
* @param version Extension version string
*/
- Extension(const char *name = NULL, const char *version = NULL);
+ Extension(const char *name, const char *version = "1.0");
/**
* No copy'ing and no moving
@@ -67,13 +62,10 @@ public:
* is handled. You can register this callback if you want to be notified
* when the engine is ready, for example to initialize certain things.
*
- * @param callback
+ * @param callback Function to be called
+ * @return Extension Same object to allow chaining
*/
- void onStartup(const Callback &callback)
- {
- // copy callback
- _onStartup = callback;
- }
+ Extension &onStartup(const Callback &callback);
/**
* Register a function to be called when the PHP engine is going to stop
@@ -81,13 +73,10 @@ public:
* The callback will be called right before the process is going to stop.
* You can register a function if you want to clean up certain things.
*
- * @param callback
+ * @param callback Function to be called
+ * @return Extension Same object to allow chaining
*/
- void onShutdown(const Callback &callback)
- {
- // copy callback
- _onShutdown = callback;
- }
+ Extension &onShutdown(const Callback &callback);
/**
* Register a callback that is called at the beginning of each pageview/request
@@ -97,13 +86,10 @@ public:
* multiple requests after each other, and you may want to set back certain
* global variables to their initial variables in front of each request
*
- * @param callback
+ * @param callback Function to be called
+ * @return Extension Same object to allow chaining
*/
- void onRequest(const Callback &callback)
- {
- // copy callback
- _onRequest = callback;
- }
+ Extension &onRequest(const Callback &callback);
/**
* Register a callback that is called to cleanup things after a pageview/request
@@ -113,105 +99,38 @@ public:
* This method is called onIdle because the extension is idle in between
* requests.
*
- * @param callback
+ * @param callback Function to be called
+ * @return Extension Same object to allow chaining
*/
- void onIdle(const Callback &callback)
- {
- // copy callback
- _onIdle = callback;
- }
+ Extension &onIdle(const Callback &callback);
/**
- * Retrieve the module entry
+ * Retrieve the module pointer
*
* This is the memory address that should be exported by the get_module()
* function.
*
- * @return _zend_module_entry
+ * @return void*
*/
- _zend_module_entry *module();
+ void *module();
/**
* Cast to a module entry
- * @return _zend_module_entry*
+ *
+ * @return void*
*/
- operator _zend_module_entry * ()
+ operator void * ()
{
return module();
}
private:
/**
- * The information that is passed to the Zend engine
- *
- * Although it would be slightly faster to not make this a pointer, this
- * would require that client code also includes the PHP header files, which
- * we try to prevent with the PHP-CPP library, so we allocate it dynamically.
+ * The implementation object
*
- * @var zend_module_entry
- */
- _zend_module_entry *_entry;
-
- /**
- * Callback that is called after the engine is initialized and before the
- * pageviews are going to be handled
- * @var Callback
- */
- Callback _onStartup;
-
- /**
- * Callback that is called in front of each request
- * @var Callback
- */
- Callback _onRequest;
-
- /**
- * Callback that is called right after each request
- * @var Callback
- */
- Callback _onIdle;
-
- /**
- * Callback that is called right before the engine is closing down
- * @var Callback
- */
- Callback _onShutdown;
-
- /**
- * Function that is called when the extension initializes
- * @param type Module type
- * @param number Module number
- * @param tsrm_ls
- * @return int 0 on success
- */
- static int onStartup(int type, int module_number TSRMLS_DC);
-
- /**
- * Function that is called when the extension is about to be stopped
- * @param type Module type
- * @param number Module number
- * @param tsrm_ls
- * @return int
- */
- static int onShutdown(int type, int module_number TSRMLS_DC);
-
- /**
- * Function that is called when a request starts
- * @param type Module type
- * @param number Module number
- * @param tsrm_ls
- * @return int 0 on success
- */
- static int onRequest(int type, int module_number TSRMLS_DC);
-
- /**
- * Function that is called when a request is ended
- * @param type Module type
- * @param number Module number
- * @param tsrm_ls
- * @return int 0 on success
+ * @var ExtensionImpl
*/
- static int onIdle(int type, int module_number TSRMLS_DC);
+ ExtensionImpl *_impl;
};
/**
diff --git a/include/namespace.h b/include/namespace.h
index de73924..cd871d4 100644
--- a/include/namespace.h
+++ b/include/namespace.h
@@ -23,32 +23,37 @@ class Function;
*/
class Namespace
{
-public:
+protected:
/**
- * Constructor
- * @param name Name of the namespace
+ * Name of the namespace
+ * @var string
*/
- Namespace(const char *name) : _name(name) {}
+ std::string _name;
+
+ /**
+ * Functions defined in the namespace
+ * @var list
+ */
+ std::list<std::shared_ptr<Function>> _functions;
+
+ /**
+ * Classes defined in the namespace
+ * @var list
+ */
+ std::list<std::shared_ptr<ClassBase>> _classes;
/**
- * Copy constructor
- * @param ns Namespace to copy
+ * Namespaces defined inside the namespace
+ * @var list
*/
- Namespace(const Namespace &ns) :
- _name(ns._name),
- _functions(ns._functions),
- _classes(ns._classes),
- _namespaces(ns._namespaces) {}
-
+ std::list<std::shared_ptr<Namespace>> _namespaces;
+
+public:
/**
- * Move constructor
- * @param ns
+ * Constructor
+ * @param name Name of the namespace
*/
- Namespace(Namespace &&ns) :
- _name(std::move(ns._name)),
- _functions(std::move(ns._functions)),
- _classes(std::move(ns._classes)),
- _namespaces(std::move(ns._namespaces)) {}
+ Namespace(const char *name) : _name(name) {}
/**
* Destructor
@@ -56,7 +61,7 @@ public:
virtual ~Namespace() {}
/**
- * Add a native function directly to the extension
+ * Add a native function directly to the namespace
* @param name Name of the function
* @param function The function to add
* @param arguments Optional argument specification
@@ -68,131 +73,91 @@ public:
Namespace &add(const char *name, const native_callback_3 &function, const Arguments &arguments = {});
/**
- * Add a native class to the extension by moving it
+ * Add a native class to the namespace by moving it
* @param type The class implementation
* @return Namespace Same object to allow chaining
*/
template<typename T>
Namespace &add(Class<T> &&type)
{
- // make a copy of the object
- auto *copy = new Class<T>(std::move(type));
-
- // and add it to the list of classes
- _classes.push_back(std::unique_ptr<ClassBase>(copy));
+ // make a copy of the object, and add it to the list of classes
+ _classes.push_back(std::unique_ptr<ClassBase>(new Class<T>(std::move(type))));
// allow chaining
return *this;
}
/**
- * Add a native class to the extension by copying it
+ * Add a native class to the namespace by copying it
* @param type The class implementation
- * @param Namespace Same object to allow chaining
+ * @return Namespace Same object to allow chaining
*/
template<typename T>
Namespace &add(const Class<T> &type)
{
- // make a copy of the object
- auto *copy = new Class<T>(std::move(type));
-
// and add it to the list of classes
- _classes.push_back(std::unique_ptr<ClassBase>(copy));
+ _classes.push_back(std::unique_ptr<ClassBase>(new Class<T>(type)));
// allow chaining
return *this;
}
/**
- * Add an interface to the extension by moving it
+ * Add an interface to the namespace by moving it
* @param interface The interface properties
+ * @return Namespace Same object to allow chaining
*/
Namespace &add(Interface &&interface)
{
- // make a copy of the object
- auto *copy = new Interface(std::move(interface));
-
- // and add it to the list of classes
- _classes.push_back(std::unique_ptr<ClassBase>(copy));
+ // make a copy and add it to the list of classes
+ _classes.push_back(std::unique_ptr<ClassBase>(new Interface(std::move(interface))));
// allow chaining
return *this;
}
/**
- * Add an interface to the extension by copying it
+ * Add an interface to the namespace by copying it
* @param interface The interface properties
+ * @return Namespace Same object to allow chaining
*/
Namespace &add(const Interface &interface)
{
- // make a copy of the object
- auto *copy = new Interface(interface);
-
- // and add it to the list of classes
- _classes.push_back(std::unique_ptr<ClassBase>(copy));
+ // make a copy and add it to the list of classes
+ _classes.push_back(std::unique_ptr<ClassBase>(new Interface(interface)));
// allow chaining
return *this;
}
/**
- * Add a namespace to the extension by moving it
+ * Add a namespace to the namespace by moving it
* @param ns The namespace
+ * @return Namespace Same object to allow chaining
*/
Namespace &add(Namespace &&ns)
{
- // make a copy of the object
- auto *copy = new Namespace(std::move(ns));
-
// add it to the list of namespaces
- _namespaces.push_back(std::unique_ptr<Namespace>(copy));
+ _namespaces.push_back(std::unique_ptr<Namespace>(new Namespace(std::move(ns))));
// allow chaining
return *this;
}
/**
- * Add a namespace to the extension by copying it
+ * Add a namespace to the namespace by copying it
* @param ns The namespace
+ * @return Namespace Same object to allow chaining
*/
Namespace &add(const Namespace &ns)
{
- // make a copy of the object
- auto *copy = new Namespace(std::move(ns));
-
- // add it to the list of namespaces
- _namespaces.push_back(std::unique_ptr<Namespace>(copy));
+ // make a copy and add it to the list of namespaces
+ _namespaces.push_back(std::unique_ptr<Namespace>(new Namespace(ns)));
// allow chaining
return *this;
}
-
-protected:
- /**
- * Name of the namespace
- * @var string
- */
- std::string _name;
-
- /**
- * Functions defined by the extension
- * @var list
- */
- std::list<std::shared_ptr<Function>> _functions;
-
- /**
- * Classes defined by the extension
- * @var list
- */
- std::list<std::shared_ptr<ClassBase>> _classes;
-
- /**
- * Namespaces defined by the extension
- * @var list
- */
- std::list<std::shared_ptr<Namespace>> _namespaces;
-
/**
* The total number of functions
* @return size_t
@@ -208,21 +173,27 @@ protected:
// done
return result;
}
-
+
/**
- * 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
+ * Apply a callback to each registered function
+ *
+ * The callback will be called with the name of the namespace, and
+ * a reference to the registered function.
+ *
+ * @param callback
*/
- size_t initialize(const std::string &ns, struct _zend_function_entry entries[]);
-
+ void apply(const std::function<void(const std::string &ns, Function &func)> &callback);
+
/**
- * Initialize the namespace after it was registered
- * @param parent Parent namespace
- * @param tsrm_ls
+ * Apply a callback to each registered class
+ *
+ * The callback will be called with the name of the namespace, and
+ * a reference to the registered class.
+ *
+ * @param callback
*/
- void initialize(const std::string &parent TSRMLS_DC);
+ void apply(const std::function<void(const std::string &ns, ClassBase &clss)> &callback);
+
};
/**