diff options
-rw-r--r-- | include/abstractclass.h | 38 | ||||
-rw-r--r-- | include/class.h | 41 | ||||
-rw-r--r-- | include/classbase.h | 49 | ||||
-rw-r--r-- | include/finalclass.h | 38 | ||||
-rw-r--r-- | phpcpp.h | 2 | ||||
-rw-r--r-- | src/classbase.cpp | 50 | ||||
-rw-r--r-- | src/includes.h | 2 |
7 files changed, 42 insertions, 178 deletions
diff --git a/include/abstractclass.h b/include/abstractclass.h deleted file mode 100644 index a791794..0000000 --- a/include/abstractclass.h +++ /dev/null @@ -1,38 +0,0 @@ -/** - * AbstractClass.h - * - * An abstract class can not be instantiated, it can only be extended - * - * @copyright 2014 Copernica BV - * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> - */ - -/** - * Set up namespace - */ -namespace Php { - -/** - * Class definition - */ -template <typename T> -class AbstractClass : public Class<T> -{ -public: - /** - * Constructor - * @param name Name of the class - */ - AbstractClass(const char *name) : Class<T>(name, ClassType::Abstract) {} - - /** - * Destructor - */ - virtual ~AbstractClass() {} -}; - -/** - * End namespace - */ -} - diff --git a/include/class.h b/include/class.h index ca09a66..0bfa745 100644 --- a/include/class.h +++ b/include/class.h @@ -25,23 +25,6 @@ extern struct _zend_class_entry *zend_ce_arrayaccess; //extern struct _zend_class_entry *zend_ce_serializable; /** - * SFINAE test to check if the __callStatic method is defined - * @see http://stackoverflow.com/questions/257288/is-it-possible-to-write-a-c-template-to-check-for-a-functions-existence - */ -template <typename T> -class HasCallStatic -{ - typedef char one; - typedef long two; - - template <typename C> static one test( decltype(&C::__callStatic) ) ; - template <typename C> static two test(...); - -public: - static const bool value = sizeof(test<T>(0)) == sizeof(char); -}; - -/** * Set up namespace */ namespace Php { @@ -56,21 +39,13 @@ public: /** * Constructor * - * The flags can be a combination of Php::Final and Php::Abstract. If no - * flags are set, a regular public class will be formed. + * The flags can be a combination of Php::Final and Php::Abstract. + * If no flags are set, a regular public class will be formed. * * @param name Name of the class + * @param flags Accessibility flags */ - Class(const char *name) : ClassBase(name) - { - // check for special classes, and register the interface if it does - // register the interface (we register a pointer-to-a-pointer here, - // because when this code runs (during the get_module() call), the - // interfaces are not yet initialized by the zend engine, this only - // happens later when the all classes are registered (after the - // get_module() call) -// if (std::is_base_of<ArrayAccess, T>::value) interface(&zend_ce_arrayaccess); - } + Class(const char *name, int flags = 0) : ClassBase(name, flags) {} /** * Copy constructor @@ -182,14 +157,6 @@ public: void property(const char *name, bool value, int flags = Public) { ClassBase::property(name, value, flags); } void property(const char *name, double value, int flags = Public) { ClassBase::property(name, value, flags); } -protected: - /** - * Protected constructor - * @param name - * @param flags - */ - Class(const char *name, int flags) : ClassBase(name, flags) {} - private: /** * Construct a new instance of the object diff --git a/include/classbase.h b/include/classbase.h index d19a1b2..77f7948 100644 --- a/include/classbase.h +++ b/include/classbase.h @@ -66,9 +66,16 @@ protected: /** * Protected constructor * @param classname Class name - * @param type The class type + * @param flags Class flags */ - ClassBase(const char *classname, ClassType type = ClassType::Regular) : _name(classname), _type(type) {} + ClassBase(const char *classname, int flags); + + /** + * Protected constructor + * @param classname Class name + * @param type Class type + */ + ClassBase(const char *classname, ClassType type) : _name(classname), _type(type) {} public: /** @@ -80,7 +87,6 @@ public: _type(that._type), _methods(that._methods), _members(that._members), - _interfaces(that._interfaces), _entry(nullptr) {} /** @@ -92,7 +98,6 @@ public: _type(that._type), _methods(std::move(that._methods)), _members(std::move(that._members)), - _interfaces(std::move(that._interfaces)), _entry(that._entry) { // other entry are invalid now (not that it is used..., class objects are @@ -257,35 +262,6 @@ protected: void property(const char *name, const char *value, int flags = Php::Public); void property(const char *name, double value, int flags = Php::Public); - /** - * Add an implemented interface - * - * This can only be used to register interfaces that are already defined - * by Zend, and not for user space interface or custom extension interfaces. - * This is probably not so much of a problem, as this feature is mostly - * useful for interfaces like 'Countable', 'ArrayAccess', 'Iterator', et - * cetera. Interfaces defined in user space are in normal operations - * inaccessible (user space code normally runs after the extension has been - * set up) - so we do not need a feature to set these. - * - * It does however make sense to support implementing extension-specific - * interface. We may add this feature in the future. - * - * This method is called _during_ the get_module() call when all classes - * are defined by the extension. However, at that time the Zend engine has - * not yet initialized the zend_class_entry's with the interface addresses. - * That's why we ask for a pointer-to-a-pointer. Later, when the classes - * are really registered, the Zend engine is with registering interfaces - * and the pointers point to a valid variable. - * - * @param interface - */ - void interface(struct ::_zend_class_entry **interface) - { - // register the interface - _interfaces.push_back(interface); - } - private: /** * Retrieve an array of zend_function_entry objects that hold the @@ -517,13 +493,6 @@ private: * @var std::list */ std::list<std::shared_ptr<Member>> _members; - - /** - * All interfaces that are implemented - * @var std::list - */ - std::list<struct ::_zend_class_entry**> _interfaces; - }; /** diff --git a/include/finalclass.h b/include/finalclass.h deleted file mode 100644 index 70f64fb..0000000 --- a/include/finalclass.h +++ /dev/null @@ -1,38 +0,0 @@ -/** - * FinalClass.h - * - * An final class can not be extended - * - * @copyright 2014 Copernica BV - * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> - */ - -/** - * Set up namespace - */ -namespace Php { - -/** - * Class definition - */ -template <typename T> -class FinalClass : public Class<T> -{ -public: - /** - * Constructor - * @param name Name of the class - */ - FinalClass(const char *name) : Class<T>(name, ClassType::Final) {} - - /** - * Destructor - */ - virtual ~FinalClass() {} -}; - -/** - * End namespace - */ -} - @@ -48,8 +48,6 @@ #include <phpcpp/classtype.h> #include <phpcpp/classbase.h> #include <phpcpp/class.h> -#include <phpcpp/abstractclass.h> -#include <phpcpp/finalclass.h> #include <phpcpp/interface.h> #include <phpcpp/namespace.h> #include <phpcpp/extension.h> diff --git a/src/classbase.cpp b/src/classbase.cpp index 348aaf3..0a07566 100644 --- a/src/classbase.cpp +++ b/src/classbase.cpp @@ -52,6 +52,32 @@ static Base *cpp_object(const zval *val) } /** + * Protected constructor + * @param classname Class name + * @param flags Class flags + */ +ClassBase::ClassBase(const char *classname, int flags) : _name(classname) +{ + // the flags hold a method-flag-value, this should be converted into a class-type + if (flags & Abstract) _type = ClassType::Abstract; + if (flags & Final) _type = ClassType::Final; +} + +/** + * Destructor + */ +ClassBase::~ClassBase() +{ + // destruct the entries + if (_entries) delete[] _entries; + + // php 5.3 deallocates the doc_comment by iself +#if PHP_VERSION_ID >= 50400 + if (_comment) free(_comment); +#endif +} + +/** * Extended zend_internal_function structure that we use to store an * instance of the ClassBase object. We need this for static method calls */ @@ -209,6 +235,7 @@ zend_function *ClassBase::getMethod(zval **object_ptr, char *method_name, int me function->handler = &ClassBase::callMethod; function->arg_info = nullptr; function->num_args = 0; + function->required_num_args = 0; function->scope = entry; function->fn_flags = ZEND_ACC_CALL_VIA_HANDLER; function->function_name = method_name; @@ -252,6 +279,7 @@ zend_function *ClassBase::getStaticMethod(zend_class_entry *entry, char* method, function->handler = ClassBase::callMethod; function->arg_info = nullptr; function->num_args = 0; + function->required_num_args = 0; function->scope = nullptr; function->fn_flags = ZEND_ACC_CALL_VIA_HANDLER; function->function_name = method; @@ -295,6 +323,7 @@ int ClassBase::getClosure(zval *object, zend_class_entry **entry_ptr, zend_funct function->handler = &ClassBase::callInvoke; function->arg_info = nullptr; function->num_args = 0; + function->required_num_args = 0; function->scope = entry; function->fn_flags = ZEND_ACC_CALL_VIA_HANDLER; function->function_name = nullptr; @@ -1162,20 +1191,6 @@ int ClassBase::unserialize(zval **object, zend_class_entry *entry, const unsigne } /** - * Destructor - */ -ClassBase::~ClassBase() -{ - // destruct the entries - if (_entries) delete[] _entries; - - // php 5.3 deallocates the doc_comment by iself -#if PHP_VERSION_ID >= 50400 - if (_comment) free(_comment); -#endif -} - -/** * Retrieve an array of zend_function_entry objects that hold the * properties for each method. This method is called at extension * startup time to register all methods. @@ -1283,13 +1298,6 @@ void ClassBase::initialize(const std::string &prefix) // set access types flags for class _entry->ce_flags = (int)_type; - // mark the interfaces as being implemented - for (auto &interface : _interfaces) - { - // implement interface - zend_do_implement_interface(_entry, *interface); - } - // declare all member variables for (auto &member : _members) member->initialize(_entry); } diff --git a/src/includes.h b/src/includes.h index 5f273bd..0dd027c 100644 --- a/src/includes.h +++ b/src/includes.h @@ -66,8 +66,6 @@ #include "../include/classtype.h" #include "../include/classbase.h" #include "../include/class.h" -#include "../include/abstractclass.h" -#include "../include/finalclass.h" #include "../include/interface.h" #include "../include/namespace.h" #include "../include/extension.h" |