]> granicus.if.org Git - php/commitdiff
add convenience functions or adding class properties. Ok'd for commit by Andi.
authorGeorge Schlossnagle <gschlossnagle@php.net>
Sun, 6 Jul 2003 19:55:20 +0000 (19:55 +0000)
committerGeorge Schlossnagle <gschlossnagle@php.net>
Sun, 6 Jul 2003 19:55:20 +0000 (19:55 +0000)
Zend/zend_API.c
Zend/zend_API.h

index 52e32af03d07116ddb32fec7f8ba7c6822244272..213262fd35d9cfba6666f2a4569fe9cb2f969ea4 100644 (file)
@@ -1576,6 +1576,51 @@ ZEND_API char *zend_get_module_version(char *module_name)
     return module->version;
 }
 
+ZEND_API void zend_declare_property(zend_class_entry *ce, char *name, int namelen, zval *property, int access_type)
+{
+       zend_property_info property_info;
+       HashTable *target_symbol_table;
+
+       if (!(access_type & ZEND_ACC_PPP_MASK)) {
+               access_type |= ZEND_ACC_PUBLIC;
+       }
+       if (access_type & ZEND_ACC_STATIC) {
+               target_symbol_table = ce->static_members;
+       } else {
+               target_symbol_table = &ce->default_properties;
+       }
+       switch (access_type & ZEND_ACC_PPP_MASK) {
+         case ZEND_ACC_PRIVATE: {
+               char *priv_name;
+               int priv_name_length;
+
+               mangle_property_name(&priv_name, &priv_name_length, ce->name, ce->name_length, name, namelen);
+               zend_hash_update(target_symbol_table, priv_name, priv_name_length+1, &property, sizeof(zval *), NULL);
+               property_info.name = priv_name;
+               property_info.name_length = priv_name_length;
+         }
+         break;
+         case ZEND_ACC_PROTECTED: {
+               char *prot_name;
+               int prot_name_length;
+
+               mangle_property_name(&prot_name, &prot_name_length, "*", 1, name, namelen);
+               zend_hash_update(target_symbol_table, prot_name, prot_name_length+1, &property, sizeof(zval *), NULL);
+               property_info.name = prot_name;
+               property_info.name_length = prot_name_length;
+         }
+         break;
+         case ZEND_ACC_PUBLIC:
+               zend_hash_update(target_symbol_table, name, namelen, &property, sizeof(zval *), NULL);
+               property_info.name = estrdup(name);
+               property_info.name_length = namelen;
+               break;
+       }
+       property_info.flags = access_type;
+       property_info.h = zend_get_hash_value(property_info.name, property_info.name_length+1);
+
+       zend_hash_update(&ce->properties_info, name, namelen + 1, &property_info, sizeof(zend_property_info), NULL);
+}
 /*
  * Local variables:
  * tab-width: 4
index 5a6169ea1f3a5393c749fe825ee3fde6882a01ee..edccc9ae9b1daf3fc9595b8dc9b86c162e252110 100644 (file)
@@ -256,6 +256,7 @@ ZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length,
 
 ZEND_API ZEND_FUNCTION(display_disabled_function);
 ZEND_API ZEND_FUNCTION(display_disabled_class);
+ZEND_API void zend_declare_property(zend_class_entry *ce, char *name, int namelen, zval *property, int access_type);
 
 #if ZEND_DEBUG
 #define CHECK_ZVAL_STRING(z) \
@@ -411,6 +412,27 @@ ZEND_API ZEND_FUNCTION(display_disabled_class);
 #define ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var, _refcount, _is_ref)            \
        ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), name, name_length, var, _refcount, _is_ref)
 
+#define ZEND_PRIVATE_PROPERTY(class_ptr, name, value) \
+{ \
+       char *_name = (name); \
+       int namelen = strlen(_name); \
+       zend_declare_property(class_ptr, _name, namelen, value, ZEND_ACC_PRIVATE); \
+}
+
+#define ZEND_PROTECTED_PROPERTY(class_ptr, name, value) \
+{ \
+       char *_name = (name); \
+       int namelen = strlen(_name); \
+       zend_declare_property(class_ptr, _name, namelen, value, ZEND_ACC_PROTECTED); \
+}
+
+#define ZEND_PUBLIC_PROPERTY(class_ptr, name, value) \
+{ \
+       char *_name = (name); \
+       int namelen = strlen(_name); \
+       zend_declare_property(class_ptr, _name, namelen, value, ZEND_ACC_PUBLIC); \
+}
+
 #define HASH_OF(p) ((p)->type==IS_ARRAY ? (p)->value.ht : (((p)->type==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p) TSRMLS_CC) : NULL)))
 #define ZVAL_IS_NULL(z) ((z)->type==IS_NULL)