diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2015-01-17 22:19:08 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2015-01-17 22:19:08 +0100 |
commit | 5fd8b29a1981d2d4f7c4e9925729fbe9f1c558bb (patch) | |
tree | e0738b3ebb653d1a7ae8a8c1f62f309f1895bfe5 /zend/constantimpl.h | |
parent | 821e65d876cc0ce2b32471791b02d9f7cc784c99 (diff) |
added initial implementation for registering constants
Diffstat (limited to 'zend/constantimpl.h')
-rw-r--r-- | zend/constantimpl.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/zend/constantimpl.h b/zend/constantimpl.h new file mode 100644 index 0000000..0545253 --- /dev/null +++ b/zend/constantimpl.h @@ -0,0 +1,81 @@ +/** + * ConstantImpl.h + * + * Implementation file for the constant class + * + * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> + * @copyright 2015 Copernica BV + */ + +/** + * Set up namespace + */ +namespace Php { + +/** + * Class definition + */ +class ConstantImpl +{ +public: + /** + * Constructor + * @param name + * @param value + */ + ConstantImpl(const char *name, const Value &value) : + _name(name), _value(value) {} + + /** + * Destructor + */ + virtual ~ConstantImpl() {} + + /** + * Initialize the constant + * @param prefix Namespace prefix + * @param module_number The module number + * @param tsrmls Optional parameter when running in multi-threading context + */ + void initialize(const std::string &prefix, int module_number TSRMLS_DC) const + { + // create constant structure + zend_constant constant; + + // copy zval + INIT_PZVAL_COPY(&constant.value, _value._val); + + // we have to call the copy constructor to copy the entire other zval + zval_copy_ctor(&constant.value); + + // @todo include prefix + + // set all the other constant properties + constant.flags = CONST_CS | CONST_PERSISTENT; + constant.name_len = ::strlen(_name); + constant.name = zend_strndup(_name, constant.name_len); + constant.module_number = module_number; + + // register the zval + zend_register_constant(&constant TSRMLS_CC); + } + +private: + /** + * The name of the constant + * @var const char * + */ + const char *_name; + + /** + * The value of the constant + * @var Value + */ + Value _value; +}; + +/** + * End of namespace + */ +} + |