summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-02-28 15:17:53 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-02-28 15:17:53 +0100
commit7cf89f18d766368dd4a14d35e4e144107ad7be36 (patch)
tree0bd4e449cbfddc928c25aaa1abac8b44c028c8e2
parent6072701319a3bf085bbc354c3e3dae9b7d021be0 (diff)
implemented properties
-rw-r--r--include/class.h35
-rw-r--r--include/classbase.h33
-rw-r--r--include/const.h58
-rw-r--r--include/member.h184
-rw-r--r--include/membermodifier.h49
-rw-r--r--include/members.h60
-rw-r--r--include/modifiers.h29
-rw-r--r--include/private.h55
-rw-r--r--include/protected.h57
-rw-r--r--include/public.h58
-rw-r--r--phpcpp.h8
-rw-r--r--src/boolmember.h29
-rw-r--r--src/classbase.cpp113
-rw-r--r--src/doublemember.h68
-rw-r--r--src/floatmember.h65
-rw-r--r--src/includes.h14
-rw-r--r--src/internalfunction.h71
-rw-r--r--src/longmember.h31
-rw-r--r--src/member.cpp232
-rw-r--r--src/member.h76
-rw-r--r--src/memberinfo.h86
-rw-r--r--src/methodbase.cpp24
-rw-r--r--src/methodmember.h77
-rw-r--r--src/methods.h114
-rw-r--r--src/modifiers.cpp29
-rw-r--r--src/nullmember.h29
-rw-r--r--src/stringmember.h43
27 files changed, 423 insertions, 1304 deletions
diff --git a/include/class.h b/include/class.h
index fe9ea2e..ad0e1a7 100644
--- a/include/class.h
+++ b/include/class.h
@@ -50,25 +50,6 @@ public:
virtual ~Class() {}
/**
- * Add a property to the class
- *
- * Every instance of this class will have this property. The property
- * can be Php::Public, Php::Protected or Php::Private (altough setting
- * private properties is odd as the implementation of the class is in CPP,
- * so why use private properties while the whole implementation is already
- * hidden)
- *
- * @param name Name of the property
- * @param property Actual property value
- * @param flags Optional flags
- */
-// void add(const char *name, const Property &property, int flags = Php::Public)
-// {
-// // @todo something with the flags
-// _properties[name] = property;
-// }
-
- /**
* Add a method to the class
*
* The method will be accessible as one of the class methods in your PHP
@@ -91,6 +72,22 @@ public:
void add(const char *name, void(T::*method)(Parameters &params), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_1>(method), 0, args); }
void add(const char *name, bool(T::*method)(), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_2>(method), 0, args); }
void add(const char *name, bool(T::*method)(Parameters &params), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_3>(method), 0, args); }
+
+ /**
+ * Add a property to the class
+ *
+ * Every instance of this class will have this property. The property
+ * can be Php::Public, Php::Protected or Php::Private (altough setting
+ * private properties is odd as the implementation of the class is in CPP,
+ * so why use private properties while the whole implementation is already
+ * hidden)
+ *
+ * @param name Name of the property
+ * @param value Actual property value
+ * @param flags Optional flags
+ */
+ template <typename TYPE>
+ void add(const char *name, const Type &value, int flags = Php::Public) { ClassBase::add(name, value, flags); }
protected:
/**
diff --git a/include/classbase.h b/include/classbase.h
index ad382fb..8b6d3dd 100644
--- a/include/classbase.h
+++ b/include/classbase.h
@@ -31,6 +31,7 @@ typedef Value (Base::*method_callback_3)(Parameters &);
* Forward declarations
*/
class Method;
+class Member;
/**
* Class definition
@@ -115,6 +116,30 @@ protected:
void add(const char *name, method_callback_2, int flags=0, const Arguments &args = {});
void add(const char *name, method_callback_3, int flags=0, const Arguments &args = {});
+ /**
+ * Add a property to the class
+ *
+ * Every instance of this class will have this property. The property
+ * can be Php::Public, Php::Protected or Php::Private (altough setting
+ * private properties is odd as the implementation of the class is in CPP,
+ * so why use private properties while the whole implementation is already
+ * hidden)
+ *
+ * @param name Name of the property
+ * @param value Actual property value
+ * @param flags Optional flags
+ */
+ void add(const char *name, std::nullptr_t value, int flags = Php::Public);
+ void add(const char *name, int16_t value, int flags = Php::Public);
+ void add(const char *name, int32_t value, int flags = Php::Public);
+ void add(const char *name, int64_t value, int flags = Php::Public);
+ void add(const char *name, bool value, int flags = Php::Public);
+ void add(const char *name, char value, int flags = Php::Public);
+ void add(const char *name, const std::string &value, int flags = Php::Public);
+ void add(const char *name, const char *value, int flags = Php::Public);
+ void add(const char *name, double value, int flags = Php::Public);
+
+
private:
/**
* Retrieve an array of zend_function_entry objects that hold the
@@ -151,16 +176,16 @@ private:
struct _zend_function_entry *_entries = nullptr;
/**
- * All class methods, this is a map indexed by method name
+ * All class methods
* @var set
*/
std::set<std::shared_ptr<Method>> _methods;
/**
- * All class properties, also a map indexed by name
- * @var Properties
+ * All class members (class properties)
+ * @var set
*/
-// std::map<std::string,Property> _properties;
+ std::set<std::shared_ptr<Member>> _members;
};
/**
diff --git a/include/const.h b/include/const.h
deleted file mode 100644
index 55c1792..0000000
--- a/include/const.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Const.h
- *
- * Class for adding constant properties to a class
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- *
- *
- * @todo implement const in a different manner
- */
-
-/**
- * Namespace
- */
-namespace Php {
-
-/**
- * Class definition
- */
-//class Const : public Member
-//{
-//public:
-// /**
-// * Constructor
-// * @param name Name of the property
-// * @param value Default value of the property
-// */
-// Const(const char *name) : Member(name, MemberModifier::constMember) {}
-// Const(const char *name, std::nullptr_t value) : Member(name, MemberModifier::constMember, value) {}
-// Const(const char *name, int value) : Member(name, MemberModifier::constMember, value) {}
-// Const(const char *name, long value) : Member(name, MemberModifier::constMember, value) {}
-// Const(const char *name, bool value) : Member(name, MemberModifier::constMember, value) {}
-// Const(const char *name, char value) : Member(name, MemberModifier::constMember, value) {}
-// Const(const char *name, const std::string &value) : Member(name, MemberModifier::constMember, value) {}
-// Const(const char *name, const char *value, int size=-1) : Member(name, MemberModifier::constMember, value, size) {}
-// Const(const char *name, double value) : Member(name, MemberModifier::constMember, value) {}
-//
-// /**
-// * Constructor
-// * @param name Name of the property
-// * @param method Method to add
-// * @param arguments Optional argument information
-// */
-// Const(const char *name, const _Method &method, const std::initializer_list<Argument> &arguments = {}) : Member(name, MemberModifier::constMember, method, arguments) {}
-//
-// /**
-// * Destructor
-// */
-// virtual ~Const() {}
-//
-//};
-//
-/**
- * End of namespace
- */
-}
-
diff --git a/include/member.h b/include/member.h
deleted file mode 100644
index 9104c56..0000000
--- a/include/member.h
+++ /dev/null
@@ -1,184 +0,0 @@
-/**
- * Member.h
- *
- * Base class for elements of a class
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- *
- * @todo remove this file completely
- */
-
-/**
- * Forward declarations
- */
-struct _zend_class_entry;
-
-/**
- * Namespace
- */
-namespace Php {
-
-/**
- * Forward declarations
- */
-class MemberInfo;
-
-///**
-// * Class definition
-// */
-//class Member
-//{
-//public:
-// /**
-// * Constructor
-// * @param name Name of the member
-// * @param flags Flag access to a class member (public, protected etc)
-// */
-// Member(const char *name, MemberModifier flags);
-//
-// /**
-// * Constructor
-// * @param name Name of the member
-// * @param flags Flag access to a class member (public, protected etc)
-// * @param value The value to add
-// */
-// Member(const char *name, MemberModifier flags, std::nullptr_t value);
-//
-// /**
-// * Constructor
-// * @param name Name of the member
-// * @param flags Flag access to a class member (public, protected etc)
-// * @param value The value to add
-// */
-// Member(const char *name, MemberModifier flags, int value);
-//
-// /**
-// * Constructor
-// * @param name Name of the member
-// * @param flags Flag access to a class member (public, protected etc)
-// * @param value The value to add
-// */
-// Member(const char *name, MemberModifier flags, long value);
-//
-// /**
-// * Constructor
-// * @param name Name of the member
-// * @param flags Flag access to a class member (public, protected etc)
-// * @param value The value to add
-// */
-// Member(const char *name, MemberModifier flags, bool value);
-//
-// /**
-// * Constructor
-// * @param name Name of the member
-// * @param flags Flag access to a class member (public, protected etc)
-// * @param value The value to add
-// */
-// Member(const char *name, MemberModifier flags, char value);
-//
-// /**
-// * Constructor
-// * @param name Name of the member
-// * @param flags Flag access to a class member (public, protected etc)
-// * @param value The value to add
-// */
-// Member(const char *name, MemberModifier flags, const std::string &value);
-//
-// /**
-// * Constructor
-// * @param name Name of the member
-// * @param flags Flag access to a class member (public, protected etc)
-// * @param value The value to add
-// * @param size String length
-// */
-// Member(const char *name, MemberModifier flags, const char *value, int size = -1);
-//
-// /**
-// * Constructor
-// * @param name Name of the member
-// * @param flags Flag access to a class member (public, protected etc)
-// * @param value The value to add
-// */
-// Member(const char *name, MemberModifier flags, double value);
-//
-// /**
-// * Constructor
-// * @param name Name of the method
-// * @param flags Flag access to a class member (public, protected etc)
-// * @param method The method to add
-// */
-// Member(const char *name, MemberModifier flags, const _Method &method, const std::initializer_list<Argument> &arguments = {});
-//
-// /**
-// * Copy constructor
-// * @param member The member to copy
-// */
-// Member(const Member &member);
-//
-// /**
-// * Move constructor
-// * @param member The member to move
-// */
-// Member(Member &&member);
-//
-// /**
-// * Destructor
-// */
-// virtual ~Member();
-//
-// /**
-// * Internal method to declare the property
-// * @param zend_class_entry
-// * @internal
-// */
-// void declare(struct _zend_class_entry *entry);
-//
-// /**
-// * Internal method to fill a function entry
-// * @param zend_function_entry
-// * @param classname
-// * @internal
-// */
-// void fill(struct _zend_function_entry *entry, const char *classname);
-//
-// /**
-// * Is this a property member
-// * @return bool
-// */
-// bool isProperty();
-//
-// /**
-// * Is this a method member
-// * @return bool
-// */
-// bool isMethod();
-//
-//
-//private:
-// /**
-// * Name of the member
-// * @var string
-// */
-// std::string _name;
-//
-// /**
-// * Flag access to a class member (public, protected etc)
-// * @var MemberModifier
-// */
-// MemberModifier _flags;
-//
-// /**
-// * The implementation for the member
-// * @var MemberInfo
-// */
-// MemberInfo *_info;
-//
-//
-//};
-//
-/**
- * End of namespace
- */
-}
-
diff --git a/include/membermodifier.h b/include/membermodifier.h
deleted file mode 100644
index 9c6cb0d..0000000
--- a/include/membermodifier.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * MemberModifier.h
- *
- * In this file an enumeration type is with the possible
- * member modifiers
- *
- * @author Martijn Otto
- * @copyright 2014 Copernica BV
- */
-
-/**
- * Set up namespace
- */
-namespace Php {
-
-/**
- * Supported member modifiers
- */
-typedef enum _MemberModifier {
- /**
- * Define whether a member has an implementation
- * and whether the implementation can be overwritten
- * in an extending class
- *
- * These properties are only useful for functions
- */
- abstractMember = 0x02,
- finalMember = 0x04,
-
- /**
- * Define the access level for a member
- */
- publicMember = 0x100,
- protectedMember = 0x200,
- privateMember = 0x400,
-
- /**
- * Define a member that cannot be overwritten.
- * Constant members are always public.
- *
- * This property is only useful for properties
- */
- constMember = 0
-} MemberModifier;
-
-/**
- * End namespace
- */
-}
diff --git a/include/members.h b/include/members.h
deleted file mode 100644
index f286620..0000000
--- a/include/members.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * Members.h
- *
- * Internal helper class that holds all members of a class
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- *
- *
- * @todo remove this file completely
- */
-
-/**
- * Namespace
- */
-namespace Php {
-
-///**
-// * Class definition
-// */
-//class Members : public std::vector<Member>
-//{
-//public:
-// /**
-// * Constructor
-// * @param arguments
-// */
-// Members(const std::initializer_list<Member> &members) : std::vector<Member>(members), _methods(NULL) {}
-//
-// /**
-// * Destructor
-// */
-// virtual ~Members();
-//
-// /**
-// * Get access to the methods
-// * @param classname
-// * @return Methods
-// */
-// struct _zend_function_entry *methods(const char *classname);
-//
-//private:
-// /**
-// * Number of methods
-// * @return integer
-// */
-// int methods();
-//
-// /**
-// * Array of method structures used internally in the Zend engine
-// * @var zend_function_entry
-// */
-// struct _zend_function_entry *_methods;
-//};
-
-/**
- * End of namespace
- */
-}
-
diff --git a/include/modifiers.h b/include/modifiers.h
new file mode 100644
index 0000000..a838341
--- /dev/null
+++ b/include/modifiers.h
@@ -0,0 +1,29 @@
+/**
+ * Modifiers.h
+ *
+ * In this file an enumeration type is with the possible
+ * member modifiers
+ *
+ * @author Martijn Otto
+ * @copyright 2014 Copernica BV
+ */
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * The modifiers are constants
+ */
+extern const int Abstract;
+extern const int Final;
+extern const int Public;
+extern const int Protected;
+extern const int Private;
+extern const int Const;
+
+/**
+ * End namespace
+ */
+}
diff --git a/include/private.h b/include/private.h
deleted file mode 100644
index f21ba6b..0000000
--- a/include/private.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Private.h
- *
- * Class for adding private properties to a class
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- */
-
-/**
- * Namespace
- */
-namespace Php {
-
-/**
- * Class definition
- */
-//class Private : public Member
-//{
-//public:
-// /**
-// * Constructor
-// * @param name Name of the property
-// * @param value Default value of the property
-// */
-// Private(const char *name) : Member(name, MemberModifier::privateMember) {}
-// Private(const char *name, std::nullptr_t value) : Member(name, MemberModifier::privateMember, value) {}
-// Private(const char *name, int value) : Member(name, MemberModifier::privateMember, value) {}
-// Private(const char *name, long value) : Member(name, MemberModifier::privateMember, value) {}
-// Private(const char *name, bool value) : Member(name, MemberModifier::privateMember, value) {}
-// Private(const char *name, char value) : Member(name, MemberModifier::privateMember, value) {}
-// Private(const char *name, const std::string &value) : Member(name, MemberModifier::privateMember, value) {}
-// Private(const char *name, const char *value, int size=-1) : Member(name, MemberModifier::privateMember, value, size) {}
-// Private(const char *name, double value) : Member(name, MemberModifier::privateMember, value) {}
-//
-// /**
-// * Constructor
-// * @param name Name of the property
-// * @param method Method to add
-// * @param arguments Optional argument information
-// */
-// Private(const char *name, const _Method &method, const std::initializer_list<Argument> &arguments = {}) : Member(name, MemberModifier::privateMember, method, arguments) {}
-//
-// /**
-// * Destructor
-// */
-// virtual ~Private() {}
-//
-//};
-//
-/**
- * End of namespace
- */
-}
-
diff --git a/include/protected.h b/include/protected.h
deleted file mode 100644
index aeee064..0000000
--- a/include/protected.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Protected.h
- *
- * Class for adding protected properties to a class
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- *
- * @todo remove this class completely
- */
-
-/**
- * Namespace
- */
-namespace Php {
-
-///**
-// * Class definition
-// */
-//class Protected : public Member
-//{
-//public:
-// /**
-// * Constructor
-// * @param name Name of the property
-// * @param value Default value of the property
-// */
-// Protected(const char *name) : Member(name, MemberModifier::protectedMember) {}
-// Protected(const char *name, std::nullptr_t value) : Member(name, MemberModifier::protectedMember, value) {}
-// Protected(const char *name, int value) : Member(name, MemberModifier::protectedMember, value) {}
-// Protected(const char *name, long value) : Member(name, MemberModifier::protectedMember, value) {}
-// Protected(const char *name, bool value) : Member(name, MemberModifier::protectedMember, value) {}
-// Protected(const char *name, char value) : Member(name, MemberModifier::protectedMember, value) {}
-// Protected(const char *name, const std::string &value) : Member(name, MemberModifier::protectedMember, value) {}
-// Protected(const char *name, const char *value, int size=-1) : Member(name, MemberModifier::protectedMember, value, size) {}
-// Protected(const char *name, double value) : Member(name, MemberModifier::protectedMember, value) {}
-//
-// /**
-// * Constructor
-// * @param name Name of the property
-// * @param method Method to add
-// * @param arguments Optional argument information
-// */
-// Protected(const char *name, const _Method &method, const std::initializer_list<Argument> &arguments = {}) : Member(name, MemberModifier::protectedMember, method, arguments) {}
-//
-// /**
-// * Destructor
-// */
-// virtual ~Protected() {}
-//
-//};
-//
-/**
- * End of namespace
- */
-}
-
diff --git a/include/public.h b/include/public.h
deleted file mode 100644
index a2f91f3..0000000
--- a/include/public.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Public.h
- *
- * Class for adding public properties to a class
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- *
- * @todo remove this file completely
- */
-
-/**
- * Namespace
- */
-namespace Php {
-
-/**
- * Class definition
- */
-//class Public : public Member
-//{
-//public:
-// /**
-// * Constructor
-// * @param name Name of the property
-// * @param value Default value of the property
-// */
-// Public(const char *name) : Member(name, MemberModifier::publicMember) {}
-// Public(const char *name, std::nullptr_t value) : Member(name, MemberModifier::publicMember, value) {}
-// Public(const char *name, int value) : Member(name, MemberModifier::publicMember, value) {}
-// Public(const char *name, long value) : Member(name, MemberModifier::publicMember, value) {}
-// Public(const char *name, bool value) : Member(name, MemberModifier::publicMember, value) {}
-// Public(const char *name, char value) : Member(name, MemberModifier::publicMember, value) {}
-// Public(const char *name, const std::string &value) : Member(name, MemberModifier::publicMember, value) {}
-// Public(const char *name, const char *value, int size=-1) : Member(name, MemberModifier::publicMember, value, size) {}
-// Public(const char *name, double value) : Member(name, MemberModifier::publicMember, value) {}
-//
-// /**
-// * Constructor
-// * @param name Name of the property
-// * @param method Method to add
-// * @param arguments Optional argument information
-// */
-// Public(const char *name, const _Method &method, const std::initializer_list<Argument> &arguments = {}) : Member(name, MemberModifier::publicMember, method, arguments) {}
-//
-// /**
-// * Destructor
-// */
-// virtual ~Public() {}
-//
-//
-//};
-//
-/**
- * End of namespace
- */
-}
-
diff --git a/phpcpp.h b/phpcpp.h
index 54608ac..7b19c64 100644
--- a/phpcpp.h
+++ b/phpcpp.h
@@ -36,15 +36,9 @@
#include <phpcpp/global.h>
#include <phpcpp/hashmember.h>
#include <phpcpp/parameters.h>
-#include <phpcpp/membermodifier.h>
+#include <phpcpp/modifiers.h>
#include <phpcpp/properties.h>
#include <phpcpp/base.h>
-#include <phpcpp/member.h>
-#include <phpcpp/public.h>
-#include <phpcpp/protected.h>
-#include <phpcpp/private.h>
-#include <phpcpp/const.h>
-#include <phpcpp/members.h>
#include <phpcpp/classbase.h>
#include <phpcpp/class.h>
#include <phpcpp/abstractclass.h>
diff --git a/src/boolmember.h b/src/boolmember.h
index 981a711..3dd4466 100644
--- a/src/boolmember.h
+++ b/src/boolmember.h
@@ -15,7 +15,7 @@ namespace Php {
/**
* Class definition
*/
-class BoolMember : public MemberInfo
+class BoolMember : public Member
{
private:
/**
@@ -27,9 +27,11 @@ private:
public:
/**
* Constructor
+ * @param name
* @param value
+ * @param flags
*/
- BoolMember(bool value) : MemberInfo(), _value(value) {}
+ BoolMember(const char *name, bool value, int flags) : Member(name, flags), _value(value) {}
/**
* Destructor
@@ -37,27 +39,22 @@ public:
virtual ~BoolMember() {}
/**
- * Is this a property member
- * @return bool
+ * Virtual method to declare a class constant
+ * @param entry Class entry
*/
- virtual bool isProperty() { return true; }
+ virtual void constant(struct _zend_class_entry *entry) override
+ {
+ zend_declare_class_constant_bool(entry, _name.c_str(), _name.size(), _value);
+ }
/**
* Virtual method to declare the property
* @param entry Class entry
- * @param name Name of the member
- * @param size Size of the name
- * @param flags Additional flags
*/
- virtual void declare(struct _zend_class_entry *entry, const char *name, int size, MemberModifier flags) override
+ virtual void declare(struct _zend_class_entry *entry) override
{
-#if PHP_VERSION_ID >= 50400
- if (flags == constMember) zend_declare_class_constant_bool(entry, name, size, _value);
- else zend_declare_property_bool(entry, name, size, _value, flags);
-#else
- if (flags == constMember) zend_declare_class_constant_bool(entry, (char *) name, size, _value);
- else zend_declare_property_bool(entry, (char *) name, size, _value, flags);
-#endif
+ // char* cast is necessary for php 5.3
+ zend_declare_property_bool(entry, (char *)_name.c_str(), _name.size(), _value, _flags);
}
};
diff --git a/src/classbase.cpp b/src/classbase.cpp
index 2ad51b1..8c5e238 100644
--- a/src/classbase.cpp
+++ b/src/classbase.cpp
@@ -202,9 +202,8 @@ void ClassBase::initialize()
// @todo something with the flags, but before or after the register_internal_class?
//setFlags(entry, _type.getFlags());
- // declare all properties
- // @todo enable this
-// _properties.initialize(_entry);
+ // declare all member variables
+ for (auto &member : _members) member->initialize(_entry);
}
/**
@@ -258,6 +257,114 @@ void ClassBase::add(const char *name, method_callback_3 callback, int flags, con
// add the method
_methods.insert(std::make_shared<Method>(name, callback, flags, args));
}
+
+/**
+ * Add a property to the class
+ * @param name Name of the property
+ * @param value Actual property value
+ * @param flags Optional flags
+ */
+void ClassBase::add(const char *name, std::nullptr_t value, int flags)
+{
+ // add property
+ _members.insert(std::make_shared<NullMember>(name, flags));
+}
+
+/**
+ * Add a property to the class
+ * @param name Name of the property
+ * @param value Actual property value
+ * @param flags Optional flags
+ */
+void ClassBase::add(const char *name, int16_t value, int flags)
+{
+ // add property
+ _members.insert(std::make_shared<LongMember>(name, value, flags));
+}
+
+/**
+ * Add a property to the class
+ * @param name Name of the property
+ * @param value Actual property value
+ * @param flags Optional flags
+ */
+void ClassBase::add(const char *name, int32_t value, int flags)
+{
+ // add property
+ _members.insert(std::make_shared<LongMember>(name, value, flags));
+}
+
+/**
+ * Add a property to the class
+ * @param name Name of the property
+ * @param value Actual property value
+ * @param flags Optional flags
+ */
+void ClassBase::add(const char *name, int64_t value, int flags)
+{
+ // add property
+ _members.insert(std::make_shared<LongMember>(name, value, flags));
+}
+
+/**
+ * Add a property to the class
+ * @param name Name of the property
+ * @param value Actual property value
+ * @param flags Optional flags
+ */
+void ClassBase::add(const char *name, bool value, int flags)
+{
+ // add property
+ _members.insert(std::make_shared<BoolMember>(name, value, flags));
+}
+
+/**
+ * Add a property to the class
+ * @param name Name of the property
+ * @param value Actual property value
+ * @param flags Optional flags
+ */
+void ClassBase::add(const char *name, char value, int flags)
+{
+ // add property
+ _members.insert(std::make_shared<StringMember>(name, &value, 1, flags));
+}
+
+/**
+ * Add a property to the class
+ * @param name Name of the property
+ * @param value Actual property value
+ * @param flags Optional flags
+ */
+void ClassBase::add(const char *name, const std::string &value, int flags)
+{
+ // add property
+ _members.insert(std::make_shared<StringMember>(name, value, flags));
+}
+
+/**
+ * Add a property to the class
+ * @param name Name of the property
+ * @param value Actual property value
+ * @param flags Optional flags
+ */
+void ClassBase::add(const char *name, const char *value, int flags)
+{
+ // add property
+ _members.insert(std::make_shared<StringMember>(name, value, strlen(value), flags));
+}
+
+/**
+ * Add a property to the class
+ * @param name Name of the property
+ * @param value Actual property value
+ * @param flags Optional flags
+ */
+void ClassBase::add(const char *name, double value, int flags)
+{
+ // add property
+ _members.insert(std::make_shared<FloatMember>(name, value, flags));
+}
/**
* End namespace
diff --git a/src/doublemember.h b/src/doublemember.h
deleted file mode 100644
index c541854..0000000
--- a/src/doublemember.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * DoubleMember.h
- *
- * Implementation for a property that is initially set to a boolean value
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- */
-
-/**
- * Set up namespace
- */
-namespace Php {
-
-/**
- * Class definition
- */
-class DoubleMember : public MemberInfo
-{
-private:
- /**
- * The value
- * @var double
- */
- double _value;
-
-public:
- /**
- * Constructor
- * @param value
- */
- DoubleMember(double value) : MemberInfo(), _value(value) {}
-
- /**
- * Destructor
- */
- virtual ~DoubleMember() {}
-
- /**
- * Is this a property member
- * @return bool
- */
- virtual bool isProperty() { return true; }
-
- /**
- * Virtual method to declare the property
- * @param entry Class entry
- * @param name Name of the member
- * @param size Size of the name
- * @param flags Additional flags
- */
- virtual void declare(struct _zend_class_entry *entry, const char *name, int size, MemberModifier flags) override
- {
-#if PHP_VERSION_ID >= 50400
- if (flags == constMember) zend_declare_class_constant_double(entry, name, size, _value);
- else zend_declare_property_double(entry, name, size, _value, flags);
-#else
- if (flags == constMember) zend_declare_class_constant_double(entry, (char *)name, size, _value);
- else zend_declare_property_double(entry, (char *)name, size, _value, flags);
-#endif
- }
-};
-
-/**
- * End of namespace
- */
-}
-
diff --git a/src/floatmember.h b/src/floatmember.h
new file mode 100644
index 0000000..8136fc2
--- /dev/null
+++ b/src/floatmember.h
@@ -0,0 +1,65 @@
+/**
+ * FloatMember.h
+ *
+ * Implementation for a property that is initially set to a boolean value
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013, 2014 Copernica BV
+ */
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * Class definition
+ */
+class FloatMember : public Member
+{
+private:
+ /**
+ * The value
+ * @var double
+ */
+ double _value;
+
+public:
+ /**
+ * Constructor
+ * @param name
+ * @param value
+ * @param flags
+ */
+ FloatMember(const char *name, double value, int flags) : Member(name, flags), _value(value) {}
+
+ /**
+ * Destructor
+ */
+ virtual ~FloatMember() {}
+
+ /**
+ * Virtual method to declare class constant
+ * @param entry Class entry
+ */
+ virtual void constant(struct _zend_class_entry *entry) override
+ {
+ zend_declare_class_constant_double(entry, _name.c_str(), _name.size(), _value);
+ }
+
+ /**
+ * Virtual method to declare the property
+ * @param entry Class entry
+ */
+ virtual void declare(struct _zend_class_entry *entry) override
+ {
+ // converstion to char* necessary for php 5.3
+ zend_declare_property_double(entry, (char *)_name.c_str(), _name.size(), _value, _flags);
+ }
+};
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/src/includes.h b/src/includes.h
index 392a380..f101080 100644
--- a/src/includes.h
+++ b/src/includes.h
@@ -54,15 +54,9 @@
#include "../include/global.h"
#include "../include/hashmember.h"
#include "../include/parameters.h"
-#include "../include/membermodifier.h"
+#include "../include/modifiers.h"
#include "../include/properties.h"
#include "../include/base.h"
-#include "../include/member.h"
-#include "../include/public.h"
-#include "../include/protected.h"
-#include "../include/private.h"
-#include "../include/const.h"
-#include "../include/members.h"
#include "../include/classbase.h"
#include "../include/class.h"
#include "../include/abstractclass.h"
@@ -79,14 +73,12 @@
#include "callable.h"
#include "function.h"
#include "method.h"
-#include "internalfunction.h"
-#include "memberinfo.h"
+#include "member.h"
#include "nullmember.h"
#include "longmember.h"
#include "boolmember.h"
#include "stringmember.h"
-#include "doublemember.h"
-#include "methodmember.h"
+#include "floatmember.h"
#include "arithmetic.h"
#include "origexception.h"
diff --git a/src/internalfunction.h b/src/internalfunction.h
deleted file mode 100644
index 31abcca..0000000
--- a/src/internalfunction.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * InternalFunction.h
- *
- * Helper union to create an internal function
- *
- * @documentation private
- */
-
-/**
- * Namespace
- */
-namespace Php {
-
-/**
- * An internal function
- */
-class InternalFunction
-{
-public:
- /**
- * Constructor
- * @param handler
- * @param flags
- */
- InternalFunction(void (*handler)(INTERNAL_FUNCTION_PARAMETERS), int flags = 0)
- {
- // set everything to zero
- memset(&_func, 0, sizeof(zend_internal_function));
-
- // set the appropriate properties
- _func.type = ZEND_INTERNAL_FUNCTION;
- _func.handler = handler;
- _func.fn_flags = flags;
-
-// _func.function_name = NULL;
-// _func.scope = NULL;
-// _func.prototype = NULL;
-// _func.num_args = 0;
-// _func.required_num_args = 0;
-// _func.arg_info = NULL;
-// _func.module = NULL;
- }
-
- /**
- * Destructor
- */
- virtual ~InternalFunction() {}
-
- /**
- * Cast to zend_function pointer
- * @return zend_function
- */
- zend_function *function()
- {
- return (zend_function *)&_func;
- }
-
-private:
- /**
- * The internal function object
- * @var zend_internal_function
- */
- zend_internal_function _func;
-};
-
-
-/**
- * End of namespace
- */
-}
-
diff --git a/src/longmember.h b/src/longmember.h
index 8e89292..09d3d8a 100644
--- a/src/longmember.h
+++ b/src/longmember.h
@@ -4,7 +4,7 @@
* Implementation for a property that is initially set to a long value
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
+ * @copyright 2013, 2014 Copernica BV
*/
/**
@@ -15,7 +15,7 @@ namespace Php {
/**
* Class definition
*/
-class LongMember : public MemberInfo
+class LongMember : public Member
{
private:
/**
@@ -27,9 +27,11 @@ private:
public:
/**
* Constructor
+ * @param name
* @param value
+ * @param flags
*/
- LongMember(long value) : MemberInfo(), _value(value) {}
+ LongMember(const char *name, long value, int flags) : Member(name, flags), _value(value) {}
/**
* Destructor
@@ -37,27 +39,22 @@ public:
virtual ~LongMember() {}
/**
- * Is this a property member
- * @return bool
+ * Declare class constant
+ * @param entry Class entry
*/
- virtual bool isProperty() { return true; }
+ virtual void constant(struct _zend_class_entry *entry) override
+ {
+ zend_declare_class_constant_long(entry, _name.c_str(), _name.size(), _value);
+ }
/**
* Virtual method to declare the property
* @param entry Class entry
- * @param name Name of the member
- * @param size Size of the name
- * @param flags Additional flags
*/
- virtual void declare(struct _zend_class_entry *entry, const char *name, int size, MemberModifier flags) override
+ virtual void declare(struct _zend_class_entry *entry) override
{
-#if PHP_VERSION_ID >= 50400
- if (flags == constMember) zend_declare_class_constant_long(entry, name, size, _value);
- else zend_declare_property_long(entry, name, size, _value, flags);
-#else
- if (flags == constMember) zend_declare_class_constant_long(entry, (char *) name, size, _value);
- else zend_declare_property_long(entry, (char *) name, size, _value, flags);
-#endif
+ // char* cast is necessary for php 5.3
+ zend_declare_property_long(entry, (char *)_name.c_str(), _name.size(), _value, _flags);
}
};
diff --git a/src/member.cpp b/src/member.cpp
deleted file mode 100644
index e3e7ff2..0000000
--- a/src/member.cpp
+++ /dev/null
@@ -1,232 +0,0 @@
-/**
- * Member.cpp
- *
- * Implementation for class members
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- *
- *
- * @todo refactor this class to a property
- */
-#include "includes.h"
-
-/**
- * Set up namespace
- */
-namespace Php {
-
-#ifdef XXXX
-
-/**
- * Constructor
- * @param name Name of the member
- * @param flags Flag access to a class member (bublic, protected etc)
- */
-Member::Member(const char *name, MemberModifier flags) : _name(name), _flags(flags)
-{
- // create a null member
- _info = new NullMember();
-}
-
-/**
- * Constructor
- * @param name Name of the member
- * @param flags Flag access to a class member (bublic, protected etc)
- * @param value The value to add
- */
-Member::Member(const char *name, MemberModifier flags, std::nullptr_t value) : _name(name), _flags(flags)
-{
- // create a null member
- _info = new NullMember();
-}
-
-/**
- * Constructor
- * @param name Name of the member
- * @param flags Flag access to a class member (bublic, protected etc)
- * @param value The value to add
- */
-Member::Member(const char *name, MemberModifier flags, int value) : _name(name), _flags(flags)
-{
- // create a long member
- _info = new LongMember(value);
-}
-
-/**
- * Constructor
- * @param name Name of the member
- * @param flags Flag access to a class member (bublic, protected etc)
- * @param value The value to add
- */
-Member::Member(const char *name, MemberModifier flags, long value) : _name(name), _flags(flags)
-{
- // create a long member
- _info = new LongMember(value);
-}
-
-/**
- * Constructor
- * @param name Name of the member
- * @param flags Flag access to a class member (bublic, protected etc)
- * @param value The value to add
- */
-Member::Member(const char *name, MemberModifier flags, bool value) : _name(name), _flags(flags)
-{
- // create a bool member
- _info = new BoolMember(value);
-}
-
-/**
- * Constructor
- * @param name Name of the member
- * @param flags Flag access to a class member (bublic, protected etc)
- * @param value The value to add
- */
-Member::Member(const char *name, MemberModifier flags, char value) : _name(name), _flags(flags)
-{
- // create a new string member
- _info = new StringMember(&value, 1);
-}
-
-/**
- * Constructor
- * @param name Name of the member
- * @param flags Flag access to a class member (bublic, protected etc)
- * @param value The value to add
- */
-Member::Member(const char *name, MemberModifier flags, const std::string &value) : _name(name), _flags(flags)
-{
- // create a new string member
- _info = new StringMember(value);
-}
-
-/**
- * Constructor
- * @param name Name of the member
- * @param flags Flag access to a class member (bublic, protected etc)
- * @param value The value to add
- * @param size String length
- */
-Member::Member(const char *name, MemberModifier flags, const char *value, int size) : _name(name), _flags(flags)
-{
- // create a new string member
- if (size < 0) size = strlen(value);
- _info = new StringMember(value, size);
-}
-
-/**
- * Constructor
- * @param name Name of the member
- * @param flags Flag access to a class member (bublic, protected etc)
- * @param value The value to add
- */
-Member::Member(const char *name, MemberModifier flags, double value) : _name(name), _flags(flags)
-{
- // create a new double member
- _info = new DoubleMember(value);
-}
-
-/**
- * Constructor
- * @param name Name of the method
- * @param pub Is this a public method (otherwise it is protected)
- * @param method The method to add
- */
-Member::Member(const char *name, MemberModifier flags, const _Method &method, const std::initializer_list<Argument> &arguments) : _name(name), _flags(flags)
-{
- // methods cannot be constant, so in that case we default to
- // a public member function instead
- if (_flags == constMember) _flags = publicMember;
-
- // create method member
- _info = new MethodMember(name, method, arguments);
-}
-
-/**
- * Copy constructor
- * @param member The member to copy
- */
-Member::Member(const Member &member) : _flags(member._flags)
-{
- // copy info object, and name and public members
- _info = member._info;
- _name = member._name;
-
- // update refcount in info object
- _info->refcount(+1);
-}
-
-/**
- * Move constructor
- * @param member The member to move
- */
-Member::Member(Member &&member) : _flags(member._flags)
-{
- // move info object, and name and public properties
- _info = member._info;
- _name = std::move(member._name);
-
- // reset info in other object
- member._info = NULL;
-}
-
-/**
- * Destructor
- */
-Member::~Member()
-{
- // leap out if there is no other info object, or when it is also used by other objects
- if (!_info || _info->refcount(-1) > 0) return;
-
- // deallocate info object
- delete _info;
-}
-
-/**
- * Is this a property member
- * @return bool
- */
-bool Member::isProperty()
-{
- return _info && _info->isProperty();
-}
-
-/**
- * Is this a method member
- * @return bool
- */
-bool Member::isMethod()
-{
- return _info && _info->isMethod();
-}
-
-/**
- * Internal method to declare the property
- * @var zend_class_entry
- */
-void Member::declare(struct _zend_class_entry *entry)
-{
- // let the info object handle stuff
- _info->declare(entry, _name.c_str(), _name.size(), _flags TSRMLS_CC);
-}
-
-/**
- * Internal method to fill a function entry
- * @param zend_function_entry
- * @param classname
- * @internal
- */
-void Member::fill(struct _zend_function_entry *entry, const char *classname)
-{
- // let the info object do this
- _info->fill(entry, classname, _flags);
-}
-
-#endif
-
-/**
- * End of namespace
- */
-}
-
diff --git a/src/member.h b/src/member.h
new file mode 100644
index 0000000..a1bce52
--- /dev/null
+++ b/src/member.h
@@ -0,0 +1,76 @@
+/**
+ * Member.h
+ *
+ * Base class for properties of a class
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013 Copernica BV
+ *
+ * @todo remove this file completely
+ */
+
+/**
+ * Namespace
+ */
+namespace Php {
+
+/**
+ * Class definition
+ */
+class Member
+{
+public:
+ /**
+ * Constructor
+ * @param name Name of the member
+ * @param flags Flag access to a class member (public, protected etc)
+ */
+ Member(const char *name, int flags) : _name(name), _flags(flags) {}
+
+ /**
+ * Destructor
+ */
+ virtual ~Member();
+
+ /**
+ * Initialize the member
+ * @param zend_class_entry
+ */
+ void initialize(struct _zend_class_entry *entry)
+ {
+ if (_flags == Const) constant(entry);
+ else declare(entry);
+ }
+
+protected:
+ /**
+ * Internal method to declare the property as constant
+ * @param zend_class_entry
+ */
+ virtual void constant(struct _zend_class_entry *entry) = 0;
+
+ /**
+ * Internal method to declare the property
+ * @param zend_class_entry
+ */
+ virtual void declare(struct _zend_class_entry *entry) = 0;
+
+protected:
+ /**
+ * The member name
+ * @var std::string
+ */
+ std::string _name;
+
+ /**
+ * The member flags
+ * @var int
+ */
+ int _flags;
+};
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/src/memberinfo.h b/src/memberinfo.h
deleted file mode 100644
index fed7976..0000000
--- a/src/memberinfo.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * MemberInfo.h
- *
- * Base class for the implementation of class members
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- */
-
-/**
- * Set up namespace
- */
-namespace Php {
-
-/**
- * Class definition
- */
-class MemberInfo
-{
-private:
- /**
- * Number of references
- * @var int
- */
- int _refcount;
-
-public:
- /**
- * Constructor
- */
- MemberInfo() : _refcount(1) {}
-
- /**
- * Virtual destructor
- */
- virtual ~MemberInfo() {}
-
- /**
- * Retrieve refcount
- * @return int
- */
- int refcount() { return _refcount; }
-
- /**
- * Refcount after making a change
- * @param change
- * @return integer
- */
- int refcount(int change) { return _refcount += change; }
-
- /**
- * Is this a property member
- * @return bool
- */
- virtual bool isProperty() { return false; }
-
- /**
- * Is this a method member
- * @return bool
- */
- virtual bool isMethod() { return false; }
-
- /**
- * Virtual method to declare the property
- * @param entry Class entry
- * @param name Name of the member
- * @param size Size of the name
- * @param flags Additional flags
- */
- virtual void declare(struct _zend_class_entry *entry, const char *name, int size, MemberModifier flags) {};
-
- /**
- * Fill a function entry object
- * @param entry Function entry
- * @param classname Name of the class
- * @param flags Is this a public method?
- */
- virtual void fill(struct _zend_function_entry *entry, const char *classname, MemberModifier flags) {};
-};
-
-/**
- * End of namespace
- */
-}
-
-
diff --git a/src/methodbase.cpp b/src/methodbase.cpp
deleted file mode 100644
index 81ce40a..0000000
--- a/src/methodbase.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * MethodBase.cpp
- *
- * Implementation of the MethodBase class
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2014 Copernica BV
- */
-#include "includes.h"
-
-/**
- * Set up namespace
- *
- * @todo remove file
- */
-namespace Php {
-
-/**
- * End namespace
- */
-}
-
-
- \ No newline at end of file
diff --git a/src/methodmember.h b/src/methodmember.h
deleted file mode 100644
index 5d903e9..0000000
--- a/src/methodmember.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * MethodMember.h
- *
- * Implementation for a method in a class
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- *
- * @todo remove this class
- * @todo but do implement this for properties
- */
-
-/**
- * Set up namespace
- */
-namespace Php {
-
-///**
-// * Class definition
-// */
-//class MethodMember : public MemberInfo, public Function
-//{
-//public:
-// /**
-// * Constructor
-// * @param name
-// * @param method
-// * @param arguments
-// */
-// MethodMember(const char *name, const _Method &method, const std::initializer_list<Argument> &arguments = {}) : Function(name, arguments), _method(method) {}
-//
-// /**
-// * Destructor
-// */
-// virtual ~MethodMember() {}
-//
-// /**
-// * Is this a method member
-// * @return bool
-// */
-// virtual bool isMethod() { return true; }
-//
-// /**
-// * Fill a function entry object
-// * @param entry Function entry
-// * @param classname Name of the class
-// * @param method Is this a public entry
-// */
-// virtual void fill(struct _zend_function_entry *entry, const char *classname, MemberModifier flags) override
-// {
-// // call function object
-// Function::fill(entry, classname, flags);
-// }
-//
-// /**
-// * Method that gets called every time the function is executed
-// * @param params The parameters that were passed
-// * @return Variable Return value
-// */
-// virtual Value invoke(Parameters &params)
-// {
-// return _method.invoke(params);
-// }
-//
-//private:
-// /**
-// * The method pointer
-// * @var _Method
-// */
-// _Method _method;
-//};
-
-/**
- * End of namespace
- */
-}
-
diff --git a/src/methods.h b/src/methods.h
deleted file mode 100644
index 08c129b..0000000
--- a/src/methods.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/**
- * Methods.h
- *
- * Class in which all methods are stored. This is a class that is used
- * internally by the PHP-CPP library, and that you do not have to use
- * as an extension writer.
- *
- * Essentially, it is std::map that is a littlebit extended with features
- * to initialize the methods in the Zend engine
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2014 Copernica BV
- */
-
-/**
- * Set up namespace
- */
-namespace Php {
-
-/**
- * Class definition
- */
-class Methods
-{
-public:
- /**
- * Constructor
- */
- Methods() {}
-
- /**
- * Destructor
- */
- virtual ~Methods()
- {
- // destruct the entries
- if (_entries) delete[] _entries;
- }
-
- /**
- * Retrieve an array of zend_function_entry objects that hold the
- * properties for each method. This method is called at extension
- * startup time to register all methods.
- *
- * @param classname The class name
- * @return zend_function_entry[]
- */
- const struct _zend_function_entry *entries(const std::string &classname)
- {
- // already initialized?
- if (_entries) return _entries;
-
- // allocate memory for the functions
- _entries = new zend_function_entry[_methods.size() + 1];
-
- // keep iterator counter
- int i = 0;
-
- // loop through the functions
- for (auto &method : _methods)
- {
- // retrieve entry
- zend_function_entry *entry = &_entries[i++];
-
- // let the function fill the entry
- // @todo check flags for the method
- method->initialize(entry, classname);
- }
-
- // last entry should be set to all zeros
- zend_function_entry *last = &_entries[i];
-
- // all should be set to zero
- memset(last, 0, sizeof(zend_function_entry));
-
- // done
- return _entries;
- }
-
- /**
- * Add a method
- * @param name
- * @param method
- */
- void add(MethodBase *method)
- {
- // add the method
- _methods.insert(std::shared_ptr<MethodBase>(method));
- }
-
-
-private:
- /**
- * Pointer to the entries
- * @var zend_function_entry[]
- */
- struct _zend_function_entry *_entries = nullptr;
-
- /**
- * Map of all methods
- *
- * A unique_ptr would have been cooler, but that somehow does not compile
- *
- * @var std::set
- */
- std::set<std::shared_ptr<MethodBase>> _methods;
-
-};
-
-/**
- * End namespace
- */
-}
-
diff --git a/src/modifiers.cpp b/src/modifiers.cpp
new file mode 100644
index 0000000..946b910
--- /dev/null
+++ b/src/modifiers.cpp
@@ -0,0 +1,29 @@
+/**
+ * Modifiers.cpp
+ *
+ * In this file an enumeration type is with the possible
+ * member modifiers
+ *
+ * @author Martijn Otto
+ * @copyright 2014 Copernica BV
+ */
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * The modifiers are constants
+ */
+const int Abstract = 0x02;
+const int Final = 0x04;
+const int Public = 0x100;
+const int Protected = 0x200;
+const int Private = 0x400;
+const int Const = 0;
+
+/**
+ * End namespace
+ */
+}
diff --git a/src/nullmember.h b/src/nullmember.h
index 252704c..943bf31 100644
--- a/src/nullmember.h
+++ b/src/nullmember.h
@@ -15,13 +15,15 @@ namespace Php {
/**
* Class definition
*/
-class NullMember : public MemberInfo
+class NullMember : public Member
{
public:
/**
* Constructor
+ * @param name
+ * @param flags
*/
- NullMember() : MemberInfo() {}
+ NullMember(const char *name, int flags) : Member(name, flags) {}
/**
* Destructor
@@ -29,27 +31,22 @@ public:
virtual ~NullMember() {}
/**
- * Is this a property member
- * @return bool
+ * Internal method to declare the property as constant
+ * @param zend_class_entry
*/
- virtual bool isProperty() { return true; }
+ virtual void constant(struct _zend_class_entry *entry) override
+ {
+ zend_declare_class_constant_null(entry, _name.c_str(), _name.size());
+ }
/**
* Virtual method to declare the property
* @param entry Class entry
- * @param name Name of the member
- * @param size Size of the name
- * @param flags Additional flags
*/
- virtual void declare(struct _zend_class_entry *entry, const char *name, int size, MemberModifier flags) override
+ virtual void declare(struct _zend_class_entry *entry) override
{
-#if PHP_VERSION_ID >= 50400
- if (flags == constMember) zend_declare_class_constant_null(entry, name, size);
- else zend_declare_property_null(entry, name, size, flags);
-#else
- if (flags == constMember) zend_declare_class_constant_null(entry, (char *) name, size);
- else zend_declare_property_null(entry, (char *) name, size, flags);
-#endif
+ // char* cast is necessary for php 5.3
+ zend_declare_property_null(entry, (char *)_name.c_str(), _name.size(), _flags);
}
};
diff --git a/src/stringmember.h b/src/stringmember.h
index c5e2a45..c80e0a1 100644
--- a/src/stringmember.h
+++ b/src/stringmember.h
@@ -15,7 +15,7 @@ namespace Php {
/**
* Class definition
*/
-class StringMember : public MemberInfo
+class StringMember : public Member
{
private:
/**
@@ -27,16 +27,28 @@ private:
public:
/**
* Constructor
+ * @param name
* @param value
+ * @param size
+ * @param flags
*/
- StringMember(const std::string &value) : MemberInfo(), _value(value) {}
+ StringMember(const char *name, const char *value, size_t size, int flags) : Member(name, flags), _value(value, size) {}
/**
* Constructor
+ * @param name
* @param value
- * @param size
+ * @param flags
+ */
+ StringMember(const char *name, const char *value, int flags) : StringMember(name, value, strlen(value), flags) {}
+
+ /**
+ * Constructor
+ * @param name
+ * @param value
+ * @param flags
*/
- StringMember(const char *value, int size) : MemberInfo(), _value(value, size) {}
+ StringMember(const char *name, const std::string &value, int flags) : Member(name, flags), _value(value) {}
/**
* Destructor
@@ -44,27 +56,22 @@ public:
virtual ~StringMember() {}
/**
- * Is this a property member
- * @return bool
+ * Virtual method to declare class constant
+ * @param entry Class entry
*/
- virtual bool isProperty() { return true; }
+ virtual void constant(struct _zend_class_entry *entry) override
+ {
+ zend_declare_class_constant_stringl(entry, _name.c_str(), _name.size(), _value.c_str(), _value.size());
+ }
/**
* Virtual method to declare the property
* @param entry Class entry
- * @param name Name of the member
- * @param size Size of the name
- * @param flags Additional flags
*/
- virtual void declare(struct _zend_class_entry *entry, const char *name, int size, MemberModifier flags) override
+ virtual void declare(struct _zend_class_entry *entry) override
{
-#if PHP_VERSION_ID >= 50400
- if (flags == constMember) zend_declare_class_constant_stringl(entry, name, size, _value.c_str(), _value.size());
- else zend_declare_property_stringl(entry, name, size, _value.c_str(), _value.size(), flags);
-#else
- if (flags == constMember) zend_declare_class_constant_stringl(entry, (char*) name, size, (char *) _value.c_str(), _value.size());
- else zend_declare_property_stringl(entry, (char*) name, size, (char *) _value.c_str(), _value.size(), flags);
-#endif
+ // cast to char* is necessary for php 5.3
+ zend_declare_property_stringl(entry, (char *)_name.c_str(), _name.size(), (char *)_value.c_str(), _value.size(), _flags);
}
};