diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/class.h | 44 | ||||
-rw-r--r-- | include/classbase.h | 10 | ||||
-rw-r--r-- | include/countable.h | 6 |
3 files changed, 25 insertions, 35 deletions
diff --git a/include/class.h b/include/class.h index 3326507..ab4a3e0 100644 --- a/include/class.h +++ b/include/class.h @@ -18,8 +18,11 @@ /** * Zend/SPL interfaces that we support */ -extern struct _zend_class_entry *spl_ce_Countable; -extern struct _zend_class_entry *spl_ce_ArrayAccess; +//extern struct _zend_class_entry *zend_ce_traversable; +//extern struct _zend_class_entry *zend_ce_aggregate; +//extern struct _zend_class_entry *zend_ce_iterator; +extern struct _zend_class_entry *zend_ce_arrayaccess; +//extern struct _zend_class_entry *zend_ce_serializable; /** * Set up namespace @@ -43,36 +46,13 @@ public: */ Class(const char *name) : ClassBase(name) { - // check for special classes - if (std::is_base_of<Countable, T>::value) - { - // 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 - // happens later when the all classes are registered (after the - // get_module() call) - interface(&spl_ce_Countable); - - // add the count method - method("count", &T::count, {}); - } - - // check for special classes - if (std::is_base_of<ArrayAccess, T>::value) - { - // 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 - // happens later when the all classes are registered (after the - // get_module() call) - interface(&spl_ce_ArrayAccess); - - // add the count method - method("count", &T::offsetSet); - method("count", &T::offsetGet); - method("count", &T::offsetUnset); - method("count", &T::offsetExists); - } + // 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); } /** diff --git a/include/classbase.h b/include/classbase.h index 92e637d..05ab2f4 100644 --- a/include/classbase.h +++ b/include/classbase.h @@ -233,6 +233,16 @@ private: static struct _zend_object_value createObject(struct _zend_class_entry *entry); /** + * Function that is used to count the number of elements in the object + * If the user has implemented the Countable interface, this method will + * call the count() method + * @param val + * @param count + * @return int + */ + static int countElements(zval *object, long *count TSRMLS_DC); + + /** * Retrieve pointer to our own object handlers * @return zend_object_handlers */ diff --git a/include/countable.h b/include/countable.h index 1b99463..d4c1823 100644 --- a/include/countable.h +++ b/include/countable.h @@ -7,7 +7,7 @@ * class MyClass : public Php::Base, public Php::Countable { ... } * * You will have to implement the count() method, which should return the - * number of elements in the class + * number of elements in the object * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2014 Copernica BV @@ -26,9 +26,9 @@ class Countable public: /** * Retrieve the number of items in the class - * @return Value + * @return long */ - virtual Value count() = 0; + virtual long count() = 0; }; |