diff options
-rw-r--r-- | include/class.h | 2 | ||||
-rw-r--r-- | include/classbase.h | 3 | ||||
-rw-r--r-- | include/interface.h | 12 | ||||
-rw-r--r-- | phpcpp.h | 2 | ||||
-rw-r--r-- | src/classbase.cpp | 6 | ||||
-rw-r--r-- | src/classimpl.cpp | 12 | ||||
-rw-r--r-- | src/classimpl.h | 12 |
7 files changed, 35 insertions, 14 deletions
diff --git a/include/class.h b/include/class.h index 8bc034c..8c78069 100644 --- a/include/class.h +++ b/include/class.h @@ -186,7 +186,7 @@ public: * @param interface Interface object * @return Class Same object to allow chaining */ -// Class<T> &implements(const Interface &interface) { ClassBase::implements(interface); return *this; } + Class<T> &implements(const Interface &interface) { ClassBase::implements(interface); return *this; } /** * Add a base class diff --git a/include/classbase.h b/include/classbase.h index e399efe..c2a9022 100644 --- a/include/classbase.h +++ b/include/classbase.h @@ -259,7 +259,7 @@ protected: * Add an interface * @param interface Interface object */ -// void implements(const ClassBase &interface) { _interfaces.push_back(&interface); } + void implements(const ClassBase &interface); /** * Set the base class @@ -268,7 +268,6 @@ protected: // void extends(const std::string &name) { _base = name; } private: - /** * Pointer to the actual implementation * @var std::shared_ptr<ClassImpl> diff --git a/include/interface.h b/include/interface.h index 36f4d50..32462c8 100644 --- a/include/interface.h +++ b/include/interface.h @@ -41,12 +41,18 @@ public: // return self return *this; } - -private: + /** - * Namespaces have access to the private base class + * The namespace needs to have access to the private ClassBase base + * class, to actually register the interface. */ friend class Namespace; + + /** + * All Php::Class<AnyThing> also need access to the base class to + * register an interface. + */ + template<typename ANYTHING> friend class Class; }; /** @@ -77,8 +77,8 @@ #include <phpcpp/serializable.h> #include <phpcpp/classtype.h> #include <phpcpp/classbase.h> -#include <phpcpp/class.h> #include <phpcpp/interface.h> +#include <phpcpp/class.h> #include <phpcpp/namespace.h> #include <phpcpp/extension.h> #include <phpcpp/call.h> diff --git a/src/classbase.cpp b/src/classbase.cpp index 037661e..c753c34 100644 --- a/src/classbase.cpp +++ b/src/classbase.cpp @@ -112,6 +112,12 @@ void ClassBase::property(const char *name, const getter_callback_0 &getter, cons 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<std::string,std::shared_ptr<Property>> _properties; + /** + * Interfaces that are implemented + * @var std::list + */ + std::list<std::shared_ptr<ClassImpl>> _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<Property>(getter,setter); } void property(const char *name, const getter_callback_1 &getter, const setter_callback_1 &setter) { _properties[name] = std::make_shared<Property>(getter,setter); } - + /** + * Add an interface that is implemented + * @param interface The interface that is implemented + */ + void implements(const std::shared_ptr<ClassImpl> &interface) { _interfaces.push_back(interface); } }; |