summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorvalmat <ufabiz@gmail.com>2014-04-09 11:00:05 +0600
committervalmat <ufabiz@gmail.com>2014-04-09 11:00:05 +0600
commit6c7c846edd5b74450b76532da33c25e6cc6a10a4 (patch)
tree51b0e0be5c43ddba6ca9351026fc94bf8ae7bc07 /include
parent08ed8866a5bba0b23a8d5587116a968512df2568 (diff)
parent33760c3efba4207eac826ff080b5f9b9672fc60e (diff)
Merge branch 'master' into ini-master
Conflicts: include/namespace.h zend/extensionimpl.cpp
Diffstat (limited to 'include')
-rw-r--r--include/argument.h111
-rw-r--r--include/array.h4
-rw-r--r--include/base.h42
-rw-r--r--include/class.h5
-rw-r--r--include/exception.h37
-rw-r--r--include/extension.h129
-rw-r--r--include/init.h54
-rw-r--r--include/iterator.h102
-rw-r--r--include/namespace.h178
-rw-r--r--include/object.h2
-rw-r--r--include/parameters.h29
-rw-r--r--include/value.h3
-rw-r--r--include/valueiterator.h12
13 files changed, 246 insertions, 462 deletions
diff --git a/include/argument.h b/include/argument.h
index 68ac7df..81b1bf4 100644
--- a/include/argument.h
+++ b/include/argument.h
@@ -8,15 +8,10 @@
* classes instead.
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
+ * @copyright 2013, 2014 Copernica BV
*/
/**
- * Forward declaration
- */
-struct _zend_arg_info;
-
-/**
* Set up namespace
*/
namespace Php {
@@ -28,21 +23,9 @@ class Argument
{
public:
/**
- * Copy constructor
- * @param argument
- */
- Argument(const Argument &argument);
-
- /**
- * Move constructor
- * @param argument
- */
- Argument(Argument &&argument);
-
- /**
* Destructor
*/
- virtual ~Argument();
+ virtual ~Argument() {}
protected:
/**
@@ -52,7 +35,8 @@ protected:
* @param required Is this argument required?
* @param byref Is this a reference argument
*/
- Argument(const char *name, Type type, bool required = true, bool byref = false);
+ Argument(const char *name, Type type, bool required = true, bool byref = false) :
+ _name(name), _type(type), _required(required), _byReference(byref) {}
/**
* Constructor
@@ -62,17 +46,11 @@ protected:
* @param required Is this argument required?
* @param byref Is this a reference argument?
*/
- Argument(const char *name, const char *classname, bool nullable = true, bool required = true, bool byref = false);
+ Argument(const char *name, const char *classname, bool nullable = true, bool required = true, bool byref = false) :
+ _name(name), _type(Type::Object), _classname(classname), _nullable(nullable), _required(required), _byReference(byref) {}
public:
/**
- * Fill an arg_info structure with data
- * @param info
- * @internal
- */
- void fill(struct _zend_arg_info *info) const;
-
- /**
* Is this a required argument?
* @return bool
* @internal
@@ -81,19 +59,88 @@ public:
{
return _required;
}
-
+
+ /**
+ * Name of the argument
+ * @return std::string
+ */
+ const std::string &name() const
+ {
+ return _name;
+ }
+
+ /**
+ * Type-hint for the argument
+ * @return Type
+ */
+ Type type() const
+ {
+ return _type;
+ }
+
+ /**
+ * If the type is a class, the name of the class
+ * @return std::string
+ */
+ const std::string &classname() const
+ {
+ return _classname;
+ }
+
+ /**
+ * Is it allowed to pass parameter with a null value?
+ * @return bool
+ */
+ bool allowNull() const
+ {
+ return _nullable;
+ }
+
+ /**
+ * Is this a parameter-by-reference?
+ * @return bool
+ */
+ bool byReference() const
+ {
+ return _byReference;
+ }
+
private:
/**
- * The argument info
- * @var zend_arg_info
+ * Name of the argument
+ * @var std::string
*/
- struct _zend_arg_info *_info;
+ std::string _name;
/**
+ * Type of argument
+ * @var Type
+ */
+ Type _type;
+
+ /**
+ * Classname, if this is a parameter that is supposed to be an instance of a class
+ * @var std::string
+ */
+ std::string _classname;
+
+ /**
+ * May the parameter be null?
+ * @var bool
+ */
+ bool _nullable;
+
+ /**
* Is this a required argument
* @var bool
*/
bool _required;
+
+ /**
+ * Is this a 'by-reference' parameter?
+ * @var bool
+ */
+ bool _byReference;
};
/**
diff --git a/include/array.h b/include/array.h
index 26fec24..0b6ceb9 100644
--- a/include/array.h
+++ b/include/array.h
@@ -31,7 +31,7 @@ public:
Array(const Value &value) : Value(value)
{
// type must be valid
- if (value.type() != Type::Array) throw Php::Exception("Assiging a non-array to an array variable");
+ if (value.type() != Type::Array) throw Php::Exception("Assigning a non-array to an array variable");
}
/**
@@ -93,7 +93,7 @@ public:
if (this == &value) return *this;
// type must be valid
- if (value.type() != Type::Array) throw Php::Exception("Assiging a non-array to a fixed array variable");
+ if (value.type() != Type::Array) throw Php::Exception("Assigning a non-array to a fixed array variable");
// call base
Value::operator=(value);
diff --git a/include/base.h b/include/base.h
index 8b3e561..87c7483 100644
--- a/include/base.h
+++ b/include/base.h
@@ -13,13 +13,21 @@ namespace Php {
/**
* Forward declarations
*/
-struct MixedObject;
+class ObjectImpl;
+
/**
* Class definition
*/
class Base
{
+private:
+ /**
+ * Object handle in the PHP engine
+ * @var ObjectImpl
+ */
+ ObjectImpl *_impl = nullptr;
+
protected:
/**
* Constructor
@@ -241,41 +249,25 @@ public:
*/
int __compare(const Base &base) const;
-
-private:
- /**
- * Store the object in the zend object cache
- * @param entry
- * @param tsrm_ls
- * @return MixedObject
- */
- MixedObject *store(struct _zend_class_entry *entry TSRMLS_DC);
+private:
/**
- * Retrieve the handle
- * @return int
+ * Get access to the implementation object
+ * @return ObjectImpl
*/
- int handle() const
+ const ObjectImpl *implementation() const
{
- return _handle;
+ return _impl;
}
-
- /**
- * The handle in the zend object cache
- * @var int
- */
- int _handle = 0;
/**
- * Friends that have access to the private members
+ * Classes that have direct access to private date
*/
- friend class Value;
+ friend class ObjectImpl;
friend class Object;
- friend class ClassImpl;
-
+ friend class Value;
};
-
/**
* End of namespace
*/
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/exception.h b/include/exception.h
index dd38035..671df9e 100644
--- a/include/exception.h
+++ b/include/exception.h
@@ -30,42 +30,51 @@ private:
*/
int _code;
+ /**
+ * Has this exception been processed by native C++ code?
+ * @var bool
+ */
+ bool _processed = false;
+
public:
/**
* Constructor
* @param &string
*/
- Exception(const std::string &message, int code = 0) : std::exception(), _message(message), _code(code)
- {
- }
+ Exception(const std::string &message, int code = 0) : std::exception(), _message(message), _code(code) {}
/**
* Destructor
*/
- virtual ~Exception() throw()
+ virtual ~Exception() throw() {}
+
+ /**
+ * Overridden what method
+ * @return const char *
+ */
+ virtual const char *what() const noexcept override
{
+ return _message.c_str();
}
/**
* Returns the message of the exception.
* @return &string
*/
- std::string &message() throw()
+ const std::string &message() const throw()
{
return _message;
}
/**
- * Process the exception
- *
- * This method is called only from within the PHP-CPP library,
- * and will turn the exception into a PHP exception
- *
- * @param tsrm_ls
- *
- * @internal
+ * Is this a native exception (one that was thrown from C++ code)
+ * @return bool
*/
- virtual void process(TSRMLS_D);
+ virtual bool native() const
+ {
+ // yes, it is native
+ return true;
+ }
};
/**
diff --git a/include/extension.h b/include/extension.h
index 6d1fa0c..fcc0f72 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/init.h b/include/init.h
deleted file mode 100644
index 8f914f5..0000000
--- a/include/init.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Init.h
- *
- * Variables and structured required by the Zend engine to work
- * with global variables
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- */
-
-/**
- * Namespace
- */
-namespace Php {
-
-/**
- * The way how PHP C API deals with "global" variables is peculiar.
- *
- * The following macros are supposed to turn into a structure that is going
- * to be instantiated for each parallel running request, and for which the
- * PHP engine allocates a certain amount of memory, and a magic pointer that
- * is passed and should be forwarded to every thinkable PHP function.
- *
- * We don't use this architecture. We have our own environment object
- * that makes much more sense, and that we use. However, the Zend engine
- * expects this structure and this structure to exist.
- */
-ZEND_BEGIN_MODULE_GLOBALS(phpcpp)
-ZEND_END_MODULE_GLOBALS(phpcpp)
-
-/**
- * And now we're going to define a macro. This also is a uncommon architecture
- * from PHP to get access to a variable from the structure above.
- */
-#ifdef ZTS
-#define PHPCPP_G(v) TSRMG(phpcpp_globals_id, phpcpp_globals *, v)
-#else
-#define PHPCPP_G(v) (phpcpp_globals.v)
-#endif
-
-/**
- * We're almost there, we now need to declare an instance of the
- * structure defined above (if building for a single thread) or some
- * sort of impossible to understand magic pointer-to-a-pointer (for
- * multi-threading builds). We make this a static variable because
- * this already is bad enough.
- */
-extern ZEND_DECLARE_MODULE_GLOBALS(phpcpp)
-
-/**
- * End of namespace
- */
-}
-
diff --git a/include/iterator.h b/include/iterator.h
index 13b30fc..331c8b3 100644
--- a/include/iterator.h
+++ b/include/iterator.h
@@ -2,19 +2,19 @@
* Iterator.h
*
* Base class for iterators. Extension writers that want to create traversable
- * classes, should override this class and implement all pure virtual methods
- * in it.
+ * classes, should override the Php::Traversable base class. This base class
+ * forces you to implement a getIterator() method that returns an instance of
+ * a Php::Iterator class.
+ *
+ * In this file you find the signature of the Php::Iterator class. It mostly has
+ * pure virtual methods, which means that you should create a derived class
+ * that implements all these methods.
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2014 Copernica BV
*/
/**
- * Forward declarations
- */
-struct _zend_object_iterator_funcs;
-
-/**
* Set up namespace
*/
namespace Php {
@@ -64,7 +64,7 @@ public:
*/
virtual void rewind() = 0;
-private:
+protected:
/**
* During the lifetime of the iterator, the object over which
* it iterates is keps as a private variable. This ensures that
@@ -73,92 +73,6 @@ private:
*/
Value _object;
- /**
- * The current() method that is called by the Zend engine wants a
- * pointer-to-pointer-to-a-zval. Because of this, we have to keep the
- * current value in memory after the current() method returns because
- * the pointer would otherwise fall out of scope. This is (once again)
- * odd behavior of the Zend engine, but we'll have to live with that
- * @var Value
- */
- Value _current;
-
- /**
- * Internal method that returns the implementation object
- * @return zend_object_iterator
- */
- struct _zend_object_iterator *implementation();
-
- /**
- * Iterator destructor method
- * @param iter
- * @param tsrm_ls
- */
- static void destructor(struct _zend_object_iterator *iter TSRMLS_DC);
-
- /**
- * Iterator valid function
- * Returns FAILURE or SUCCESS
- * @param iter
- * @param tsrm_ls
- * @return int
- */
- static int valid(struct _zend_object_iterator *iter TSRMLS_DC);
-
- /**
- * Fetch the current item
- * @param iter
- * @param data
- * @param tsrm_ls
- */
- static void current(struct _zend_object_iterator *iter, struct _zval_struct ***data TSRMLS_DC);
-
- /**
- * Fetch the key for the current element (optional, may be NULL). The key
- * should be written into the provided zval* using the ZVAL_* macros. If
- * this handler is not provided auto-incrementing integer keys will be
- * used.
- * @param iter
- * @param data
- * @param tsrm_ls
- */
- static void key(struct _zend_object_iterator *iter, struct _zval_struct *data TSRMLS_DC);
-
- /**
- * Function to retrieve the current key, php 5.3 style
- * @param iter
- * @param str_key
- * @param str_key_len
- * @param int_key
- * @param tsrm_ls
- * @return HASH_KEY_IS_STRING or HASH_KEY_IS_LONG
- */
- static int key(struct _zend_object_iterator *iter, char **str_key, unsigned int *str_key_len, unsigned long *int_key TSRMLS_DC);
-
- /**
- * Step forwards to the next element
- * @param iter
- * @param tsrm_ls
- */
- static void next(struct _zend_object_iterator *iter TSRMLS_DC);
-
- /**
- * Rewind the iterator back to the start
- * @param iter
- * @param tsrm_ls
- */
- static void rewind(struct _zend_object_iterator *iter TSRMLS_DC);
-
- /**
- * Get access to all iterator functions
- * @return zend_object_iterator_funcs
- */
- static struct _zend_object_iterator_funcs *functions();
-
- /**
- * Classbase is a friend
- */
- friend class ClassImpl;
};
/**
diff --git a/include/namespace.h b/include/namespace.h
index 5830339..25d4e5e 100644
--- a/include/namespace.h
+++ b/include/namespace.h
@@ -23,32 +23,43 @@ 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;
+
/**
- * Move constructor
- * @param ns
+ * Ini entry defined by the extension
+ * @var list
*/
- Namespace(Namespace &&ns) :
- _name(std::move(ns._name)),
- _functions(std::move(ns._functions)),
- _classes(std::move(ns._classes)),
- _namespaces(std::move(ns._namespaces)) {}
+ std::list<std::shared_ptr<Ini>> _ini_entries;
+
+public:
+ /**
+ * Constructor
+ * @param name Name of the namespace
+ */
+ Namespace(const char *name) : _name(name) {}
/**
* Destructor
@@ -56,7 +67,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,106 +79,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;
}
-
/**
* Add a ini entry to the extension by moving it
* @param ini The class implementation
@@ -175,11 +171,8 @@ public:
*/
Namespace &add(Ini &&ini)
{
- // make a copy of the object
- auto *copy = new Ini(std::move(ini));
-
// and add it to the list of classes
- _ini_entries.push_back(std::unique_ptr<Ini>(copy));
+ _ini_entries.push_back(std::unique_ptr<Ini>(new Ini(std::move(ini))));
// allow chaining
return *this;
@@ -192,48 +185,13 @@ public:
*/
Namespace &add(const Ini &ini)
{
- // make a copy of the object
- auto *copy = new Ini(std::move(ini));
-
// and add it to the list of classes
- _ini_entries.push_back(std::unique_ptr<Ini>(copy));
+ _ini_entries.push_back(std::unique_ptr<Ini>(new Ini(ini)));
// 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;
-
- /**
- * Ini entry defined by the extension
- * @var list
- */
- std::list<std::shared_ptr<Ini>> _ini_entries;
-
/**
* The total number of functions
* @return size_t
@@ -249,21 +207,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);
+
};
/**
diff --git a/include/object.h b/include/object.h
index 1445943..97c9482 100644
--- a/include/object.h
+++ b/include/object.h
@@ -140,7 +140,7 @@ public:
if (this == &value) return *this;
// type must be valid
- if (value.type() != Type::Object) throw Php::Exception("Assiging a non-object to an object variable");
+ if (value.type() != Type::Object) throw Php::Exception("Assigning a non-object to an object variable");
// call base
Value::operator=(value);
diff --git a/include/parameters.h b/include/parameters.h
index fa53004..b464260 100644
--- a/include/parameters.h
+++ b/include/parameters.h
@@ -22,15 +22,25 @@ class Base;
*/
class Parameters : public std::vector<Value>
{
-public:
+private:
/**
- * Constructor
- * @param this_ptr Optional this_ptr
- * @param argc Number of arguments
- * @param tsrm_ls
+ * The base object
+ * @var Base
*/
- Parameters(struct _zval_struct *this_ptr, int argc TSRMLS_DC);
+ Base *_object = nullptr;
+protected:
+ /**
+ * Protected constructor
+ *
+ * The constructor is protected because extension programmers are not
+ * supposed to instantiate parameters objects themselves
+ *
+ * @param object The 'this' object
+ */
+ Parameters(Base *object) : _object(object) {}
+
+public:
/**
* Destructor
*/
@@ -44,13 +54,6 @@ public:
{
return _object;
}
-
-private:
- /**
- * The base object
- * @var Base
- */
- Base *_object = nullptr;
};
/**
diff --git a/include/value.h b/include/value.h
index e7fa825..95985d7 100644
--- a/include/value.h
+++ b/include/value.h
@@ -943,12 +943,13 @@ protected:
friend class Globals;
friend class Member;
friend class ClassImpl;
- friend class Iterator;
+ friend class IteratorImpl;
friend class Extension;
friend class HashIterator;
friend class TraverseIterator;
friend class HashMember<int>;
friend class HashMember<std::string>;
+ friend class Callable;
};
/**
diff --git a/include/valueiterator.h b/include/valueiterator.h
index fd8118d..95cdac6 100644
--- a/include/valueiterator.h
+++ b/include/valueiterator.h
@@ -12,12 +12,6 @@
*/
/**
- * Forward declaration
- */
-struct _hashtable;
-struct bucket;
-
-/**
* Set up namespace
*/
namespace Php {
@@ -25,7 +19,7 @@ namespace Php {
/**
* Forward declarations
*/
-class IteratorImpl;
+class ValueIteratorImpl;
/**
* Class definition
@@ -37,7 +31,7 @@ public:
* Constructor
* @param impl Implementation iterator
*/
- ValueIterator(IteratorImpl *impl) : _impl(impl) {}
+ ValueIterator(ValueIteratorImpl *impl) : _impl(impl) {}
/**
* Copy constructor
@@ -125,7 +119,7 @@ private:
* Pointer to the actual implementation
* @var std::unique_ptr
*/
- IteratorImpl *_impl;
+ ValueIteratorImpl *_impl;
};