diff --git a/CodeGen/PECL/Element.php b/CodeGen/PECL/Element.php index 608c7d6..b4697f8 100644 --- a/CodeGen/PECL/Element.php +++ b/CodeGen/PECL/Element.php @@ -161,5 +161,24 @@ function isKeyword($name) return false; } + /** + * Checks whether a string is a valid namespace + * + * @access public + * @param string name + * @return bool boolean false if a reserved keyword is used + */ + function isNamespace($name) + { + $parts = explode('\\\\', $name); + + foreach ($parts as $part) { + if (self::isKeyword($part)) { + return false; + } + + return true; + } + } } diff --git a/CodeGen/PECL/Element/Class.php b/CodeGen/PECL/Element/Class.php index bd03b91..5af26dd 100644 --- a/CodeGen/PECL/Element/Class.php +++ b/CodeGen/PECL/Element/Class.php @@ -77,6 +77,39 @@ function getName() return $this->name; } + /** + * Namespace of the class + * + * @var string + */ + protected $namespace = ""; + + /** + * class name setter + * + * @param string Classnamespace + */ + function setNamespace($namespace) + { + if (!self::isNamespace($namespace)) { + return PEAR::raiseError("'$namespace' is not a valid namespace"); + } + + $this->namespace = $namespace; + + return true; + } + + /** + * class name getter + * + * @return string Classnamespace + */ + function getNamespace() + { + return $this->namespace; + } + /** * A short description * @@ -511,7 +544,13 @@ function globalCode($extension) echo " zend_class_entry ce;\n\n"; - echo " INIT_CLASS_ENTRY(ce, \"{$this->name}\", {$this->name}_methods);\n"; + + if (empty($this->namespace)) { + echo " INIT_CLASS_ENTRY(ce, \"{$this->name}\", {$this->name}_methods);\n"; + } + else { + echo " INIT_NS_CLASS_ENTRY(ce, \"{$this->namespace}\", \"{$this->name}\", {$this->name}_methods);\n"; + } if ($this->payloadType) { echo " ce.create_object = {$this->name}_obj_create;\n"; diff --git a/CodeGen/PECL/Element/Interface.php b/CodeGen/PECL/Element/Interface.php index 61dda19..e391c6d 100644 --- a/CodeGen/PECL/Element/Interface.php +++ b/CodeGen/PECL/Element/Interface.php @@ -45,7 +45,7 @@ class CodeGen_PECL_Element_Interface implements CodeGen_PECL_Element_ObjectInterface { /** - * The class name + * The interface name * * @var string */ @@ -77,6 +77,39 @@ function getName() return $this->name; } + /** + * namespace get()er + * + * @return string + */ + function getNamespace() + { + return $this->namespace; + } + + /** + * The namespace namespace + * + * @var string + */ + protected $namespace = ""; + + /** + * namespace set()er + * + * @param string + */ + function setNamespace($namespace) + { + if (!self::isNamespace($namespace)) { + return PEAR::raiseError("'$namespace' is not a valid namespace"); + } + + $this->namespace = $namespace; + + return true; + } + /** * A short description * @@ -237,7 +270,14 @@ function globalCode($extension) echo " zend_class_entry **parent_ce;\n"; } echo "\n"; - echo " INIT_CLASS_ENTRY(ce, \"{$this->name}\", {$this->name}_methods);\n"; + + if (empty($this->namespace)) { + echo " INIT_CLASS_ENTRY(ce, \"{$this->name}\", {$this->name}_methods);\n"; + } + else { + echo " INIT_NS_CLASS_ENTRY(ce, \"{$this->namespace}\", \"{$this->name}\", {$this->name}_methods);\n"; + } + echo " {$this->name}_ce_ptr = zend_register_internal_interface(&ce TSRMLS_CC);\n"; if ($this->extends) { diff --git a/CodeGen/PECL/ExtensionParser.php b/CodeGen/PECL/ExtensionParser.php index 280fd0f..8074010 100644 --- a/CodeGen/PECL/ExtensionParser.php +++ b/CodeGen/PECL/ExtensionParser.php @@ -909,7 +909,7 @@ function tagend_extension_tests($attr, $data) { function tagstart_extension_class($attr) { - $err = $this->checkAttributes($attr, array("name", "extends", "final", "abstract", "if")); + $err = $this->checkAttributes($attr, array("name", "namespace", "extends", "final", "abstract", "if")); if (PEAR::isError($err)) { return $err; } @@ -927,6 +927,13 @@ function tagstart_extension_class($attr) return PEAR::raiseError("name attribut for class missing"); } + if (isset($attr["namespace"])) { + $err = $class->setNamespace($attr["namespace"]); + if (PEAR::isError($err)) { + return $err; + } + } + if (isset($attr["extends"])) { $err = $class->setExtends($attr["extends"]); if (PEAR::isError($err)) { @@ -1237,7 +1244,7 @@ function tagend_group_class($attr, $data) function tagstart_extension_interface($attr) { - $err = $this->checkAttributes($attr, array("name", "extends", "if")); + $err = $this->checkAttributes($attr, array("name", "namespace", "extends", "if")); if (PEAR::isError($err)) { return $err; } @@ -1255,6 +1262,13 @@ function tagstart_extension_interface($attr) return PEAR::raiseError("name attribut for class missing"); } + if (isset($attr["namespace"])) { + $err = $interface->setNamespace($attr["namespace"]); + if (PEAR::isError($err)) { + return $err; + } + } + if (isset($attr["extends"])) { $err = $interface->setExtends($attr["extends"]); if (PEAR::isError($err)) {