diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-14 10:32:32 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-14 10:32:32 +0100 |
commit | 4c55148476952276ece19f5b975ca0a0233dee4c (patch) | |
tree | f16b9da14403c33f1ca951e16e58841a3d88f091 /include | |
parent | 159781ee8257329ca9c40306f7495a8c2f31f710 (diff) |
implemented __destruct magic method
Diffstat (limited to 'include')
-rw-r--r-- | include/base.h | 5 | ||||
-rw-r--r-- | include/class.h | 15 | ||||
-rw-r--r-- | include/classbase.h | 13 |
3 files changed, 32 insertions, 1 deletions
diff --git a/include/base.h b/include/base.h index 6cf75df..2d5b815 100644 --- a/include/base.h +++ b/include/base.h @@ -111,6 +111,11 @@ public: { return Value(this)[name]; } + + /** + * Overridable method that is called right before an object is destructed + */ + void __destruct() const; /** * Overridable method that is called to check if a property is set diff --git a/include/class.h b/include/class.h index 9fa14a7..31e29a8 100644 --- a/include/class.h +++ b/include/class.h @@ -247,7 +247,7 @@ private: T *object = (T *)base; // call the method on the base object - return base->__call(name, params); + return object->__call(name, params); } /** @@ -302,6 +302,19 @@ private: } /** + * Call the __destruct method + * @param object + */ + virtual Value callDestruct(Base *base) const override + { + // cast to actual object + T *obj = (T *)base; + + // pass on + return obj->__destruct(); + } + + /** * Call a the __callStatic() function * @param name Name of the function * @param params Parameters passed to the function diff --git a/include/classbase.h b/include/classbase.h index 0ea6ea4..24e8f5a 100644 --- a/include/classbase.h +++ b/include/classbase.h @@ -150,6 +150,11 @@ protected: virtual int callCompare(Base *object1, Base *object2) const { return 1; } /** + * Call the __destruct method + */ + virtual Value callDestruct(Base *base) const { return nullptr; } + + /** * Call the __call(), __invoke() or __callStatic() method * @param base Object to call on * @param name Name of the method @@ -283,6 +288,8 @@ private: */ static struct _zend_object_value createObject(struct _zend_class_entry *entry); static struct _zend_object_value cloneObject(struct _zval_struct *val); + static void destructObject(struct _zend_object *object, unsigned int handle); + static void freeObject(struct _zend_object *object); /** * Static member function that get called when a method or object is called @@ -495,6 +502,12 @@ private: * @var std::list */ std::list<std::shared_ptr<Member>> _members; + + /** + * Base object has access to the members + * This is needed by the Base::store() method + */ + friend class Base; }; /** |