summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/class.h18
-rw-r--r--include/classbase.h6
-rw-r--r--src/classbase.cpp6
-rw-r--r--src/classimpl.h11
4 files changed, 33 insertions, 8 deletions
diff --git a/include/class.h b/include/class.h
index 8c78069..7b9a928 100644
--- a/include/class.h
+++ b/include/class.h
@@ -197,13 +197,13 @@ public:
*
* The base class that you supply must already be registered. And because
* your extension is most likely registered before any user space PHP scripts
- * run, you can only specify built-in classes, or classes that you created
- * in your own extension.
+ * run, you can only specify classes that you created in your own extension.
*
- * @param name Name of the base class
+ * @param base Php::Class object
* @return Class Same object to allow chaining
*/
-// Class<T> &extends(const char *name) { ClassBase::extends(name); return *this; }
+ template<typename CLASS>
+ Class<T> &extends(const Class<CLASS> &base) { ClassBase::extends(base); return *this; }
private:
/**
@@ -534,9 +534,17 @@ private:
}
/**
- * Namespaces have access to the private base class
+ * Namespaces have access to the private base class, so that the classes
+ * can be registered.
*/
friend class Namespace;
+
+ /**
+ * All Php::Class<AnyThing> also need access to the base class to
+ * register this class as base class.
+ */
+ template<typename ANYTHING> friend class Class;
+
};
/**
diff --git a/include/classbase.h b/include/classbase.h
index c2a9022..a736c4e 100644
--- a/include/classbase.h
+++ b/include/classbase.h
@@ -245,7 +245,7 @@ protected:
/**
* Set property with callbacks
* @param name Name of the property
- * @param getter Getter method
+ * @param getter Getter methode
* @param setter Setter method
*/
void property(const char *name, const getter_callback_0 &getter);
@@ -263,9 +263,9 @@ protected:
/**
* Set the base class
- * @param name Name of the base class
+ * @param base Php::Class object that is the base
*/
-// void extends(const std::string &name) { _base = name; }
+ void extends(const ClassBase &base);
private:
/**
diff --git a/src/classbase.cpp b/src/classbase.cpp
index c753c34..18d81d5 100644
--- a/src/classbase.cpp
+++ b/src/classbase.cpp
@@ -118,6 +118,12 @@ void ClassBase::property(const char *name, const getter_callback_1 &getter, cons
void ClassBase::implements(const ClassBase &interface) { _impl->implements(interface._impl); }
/**
+ * Set the base class
+ * @param base Php::Class object that is the base
+ */
+void ClassBase::extends(const ClassBase &base) { _impl->extends(base._impl); }
+
+/**
* End namespace
*/
}
diff --git a/src/classimpl.h b/src/classimpl.h
index 03dc548..4da4eba 100644
--- a/src/classimpl.h
+++ b/src/classimpl.h
@@ -78,6 +78,12 @@ private:
* @var std::list
*/
std::list<std::shared_ptr<ClassImpl>> _interfaces;
+
+ /**
+ * The parent/base class
+ * @var std::shared_ptr
+ */
+ std::shared_ptr<ClassImpl> _parent;
/**
@@ -407,6 +413,11 @@ public:
*/
void implements(const std::shared_ptr<ClassImpl> &interface) { _interfaces.push_back(interface); }
+ /**
+ * Set the base class
+ * @param base The base class
+ */
+ void extends(const std::shared_ptr<ClassImpl> &base) { _parent = base; }
};