From a3bd6dc04d5210ddeffdda5884f51c0e5b37ec27 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Wed, 2 Apr 2014 23:12:31 +0200 Subject: added Class::implements() method to allow classes that implement interfaces (request from issue #52) --- src/classbase.cpp | 6 ++++++ src/classimpl.cpp | 12 ++++++------ src/classimpl.h | 12 +++++++++++- 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/classbase.cpp b/src/classbase.cpp index 037661e..c753c34 100644 --- a/src/classbase.cpp +++ b/src/classbase.cpp @@ -111,6 +111,12 @@ void ClassBase::property(const char *name, const getter_callback_1 &getter, cons void ClassBase::property(const char *name, const getter_callback_0 &getter, const setter_callback_1 &setter) { _impl->property(name, getter, setter); } void ClassBase::property(const char *name, const getter_callback_1 &getter, const setter_callback_1 &setter) { _impl->property(name, getter, setter); } +/** + * Add an interface + * @param interface Interface object + */ +void ClassBase::implements(const ClassBase &interface) { _impl->implements(interface._impl); } + /** * End namespace */ diff --git a/src/classimpl.cpp b/src/classimpl.cpp index 1ee7b0b..f63ddec 100644 --- a/src/classimpl.cpp +++ b/src/classimpl.cpp @@ -1399,12 +1399,12 @@ void ClassImpl::initialize(ClassBase *base, const std::string &prefix TSRMLS_DC) // register the class _entry = zend_register_internal_class(&entry TSRMLS_CC); -// // register the classes -// for (auto &interface : _interfaces) -// { -// // register this interface -// zend_class_implements(_entry, 1, interface->_entry); -// } + // register the classes + for (auto &interface : _interfaces) + { + // register this interface + zend_class_implements(_entry, 1, interface->_entry); + } // allocate doc comment to contain an empty string + a hidden pointer if (!_comment) diff --git a/src/classimpl.h b/src/classimpl.h index bfb4532..03dc548 100644 --- a/src/classimpl.h +++ b/src/classimpl.h @@ -73,6 +73,12 @@ private: */ std::map> _properties; + /** + * Interfaces that are implemented + * @var std::list + */ + std::list> _interfaces; + /** * Retrieve an array of zend_function_entry objects that hold the @@ -395,7 +401,11 @@ public: void property(const char *name, const getter_callback_0 &getter, const setter_callback_1 &setter) { _properties[name] = std::make_shared(getter,setter); } void property(const char *name, const getter_callback_1 &getter, const setter_callback_1 &setter) { _properties[name] = std::make_shared(getter,setter); } - + /** + * Add an interface that is implemented + * @param interface The interface that is implemented + */ + void implements(const std::shared_ptr &interface) { _interfaces.push_back(interface); } }; -- cgit v1.2.3