diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2015-01-25 18:38:35 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2015-01-25 18:38:35 +0100 |
commit | 3e6fb6ef89600abf2a282396384aab80ec9390ce (patch) | |
tree | fb15a9b4a5379823f787beccc0f34d6ebd8af74c /zend/constantimpl.h | |
parent | 089c92358d4f43f1715d94244acb4d665fe50d29 (diff) |
Php::Constant objects can now also be added to a Php::Class to create class constants
Diffstat (limited to 'zend/constantimpl.h')
-rw-r--r-- | zend/constantimpl.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/zend/constantimpl.h b/zend/constantimpl.h index bf2ac25..bfae410 100644 --- a/zend/constantimpl.h +++ b/zend/constantimpl.h @@ -113,6 +113,52 @@ public: virtual ~ConstantImpl() {} /** + * Add the constant to a class + * @param clss The class to add it to + */ + void addTo(ClassBase &clss) + { + // check the zval type + switch (Z_TYPE(_constant.value)) { + + case IS_NULL: + // set a null constant + clss.property(_name, nullptr, Php::Const); + break; + + case IS_LONG: + // set a long constant + clss.property(_name, Z_LVAL(_constant.value), Php::Const); + break; + + case IS_DOUBLE: + // set a double constant + clss.property(_name, Z_DVAL(_constant.value), Php::Const); + break; + + case IS_BOOL: + // set a boolean constant + clss.property(_name, Z_BVAL(_constant.value), Php::Const); + break; + + case IS_STRING: + // set a string constant + clss.property(_name, std::string(Z_STRVAL(_constant.value), Z_STRLEN(_constant.value)), Php::Const); + break; + + default: + // this should not happen, the constant can only be constructed as one + // of the above types, so it should be impossible to end up here. But + // for completeness, we convert the constant to a string, here + convert_to_string(&_constant.value); + + // set as string constant + clss.property(_name, std::string(Z_STRVAL(_constant.value), Z_STRLEN(_constant.value)), Php::Const); + break; + } + } + + /** * Initialize the constant * @param prefix Namespace prefix * @param module_number The module number |