/** * Generate global scope code * * @access public * @return string */ function globalCode($extension) { $upname = strtoupper($this->name); ob_start(); echo "/* {{{ Class {$this->name} */\n\n"; echo "static zend_class_entry * {$this->name}_ce_ptr = NULL;\n\n"; echo "/* {{{ Methods */\n\n"; foreach ($this->methods as $method) { echo $method->cCode($extension); echo "\n"; } echo "static zend_function_entry {$this->name}_methods[] = {\n"; foreach ($this->methods as $method) { echo " " . $method->methodEntry() . "\n"; } echo " { NULL, NULL, NULL }\n"; echo "};\n\n"; echo "/* }}} Methods */\n\n"; if ($this->payloadType) { echo "\nstatic zend_object_handlers {$this->name}_obj_handlers;\n\nstatic void {$this->name}_obj_free(void *object TSRMLS_DC)\n{\n php_obj_{$this->name} *payload = (php_obj_{$this->name} *)object;\n \n {$this->payloadType} *data = payload->data;\n" . $this->getPayloadDtor($extension) . "\n efree(object);\n}\n\nstatic zend_object_value {$this->name}_obj_create(zend_class_entry *class_type TSRMLS_DC)\n{\n php_obj_{$this->name} *payload;\n zval *tmp;\n zend_object_value retval;\n\n payload = (php_obj_{$this->name} *)emalloc(sizeof(php_obj_{$this->name}));\n memset(payload, 0, sizeof(php_obj_{$this->name}));\n payload->obj.ce = class_type;\n" . $this->getPayloadCtor($extension) . "\n retval.handle = zend_objects_store_put(payload, NULL, (zend_objects_free_object_storage_t) {$this->name}_obj_free, NULL TSRMLS_CC);\n retval.handlers = &{$this->name}_obj_handlers;\n \n return retval;\n}\n\n"; } echo "static void class_init_{$this->name}(void)\n{\n"; echo " zend_class_entry ce;\n\n"; echo " INIT_CLASS_ENTRY(ce, \"{$this->name}\", {$this->name}_methods);\n"; if ($this->payloadType) { echo " ce.create_object = {$this->name}_obj_create;\n"; } if ($this->extends) { echo " {$this->name}_ce_ptr = zend_register_internal_class_ex(&ce, NULL, \"{$this->extends}\" TSRMLS_CC);\n"; } else { echo " {$this->name}_ce_ptr = zend_register_internal_class(&ce);\n"; } if ($this->payloadType) { echo " memcpy(&{$this->name}_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));\n"; echo " {$this->name}_obj_handlers.clone_obj = NULL;\n"; } if ($this->isFinal) { echo " {$this->name}_ce_ptr->ce_flags |= ZEND_ACC_FINAL_CLASS;\n"; } if ($this->isAbstract) { echo " {$this->name}_ce_ptr->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;\n"; } if (!empty($this->properties)) { echo "\n /* {{{ Property registration */\n\n"; foreach ($this->properties as $property) { echo $property->minitCode($this->name . "_ce_ptr"); } echo " /* }}} Property registration */\n\n"; } if (!empty($this->constants)) { echo "\n"; echo CodeGen_PECL_Element_ClassConstant::minitHeader(); foreach ($this->constants as $constant) { echo $constant->minitCode($this->name . "_ce_ptr"); } echo CodeGen_PECL_Element_ClassConstant::minitFooter(); } if (count($this->implements)) { ob_start(); echo "zend_class_entry **tmp;\n"; $interfaces = array(); foreach ($this->implements as $interface) { echo sprintf("if (SUCCESS == zend_hash_find(CG(class_table), \"%s\", %d, (void **)&tmp)) {\n", strtolower($interface), strlen($interface) + 1); echo " zend_class_implements({$this->name}_ce_ptr TSRMLS_CC, 1, *tmp);\n"; echo "} else {\n"; echo " php_error(E_WARNING, \"Couldn't find interface '{$interface}' while setting up class '{$this->name}', skipped\");\n"; echo "}\n"; } echo $extension->codegen->varblock(ob_get_clean()); } echo "}\n\n"; echo "/* }}} Class {$this->name} */\n\n"; return ob_get_clean(); }
function tagstart_class_constant($attr) { $err = $this->checkAttributes($attr, array("name", "type", "value")); if (PEAR::isError($err)) { return $err; } $const = new CodeGen_PECL_Element_ClassConstant(); if (!isset($attr["name"])) { return PEAR::raiseError("name attribute missing for class constant"); } $err = $const->setName($attr["name"]); if (PEAR::isError($err)) { return $err; } if (!isset($attr["type"])) { return PEAR::raiseError("type attribute missing for class constant"); } $err = $const->setType($attr["type"]); if (PEAR::isError($err)) { return $err; } if (!isset($attr["value"])) { return PEAR::raiseError("value attribute missing for class constant"); } $err = $const->setValue($attr["value"]); if (PEAR::isError($err)) { return $err; } return $this->helper->addConstant($const); }