7 * @author Vasil Rangelov <boen.robot@gmail.com>
8 * @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
9 * @license http://www.opensource.org/licenses/mit-license.php MIT
10 * @link http://phpdoc.org
13 namespace phpDocumentor\Reflection\DocBlock;
16 * The context in which a DocBlock occurs.
18 * @author Vasil Rangelov <boen.robot@gmail.com>
19 * @license http://www.opensource.org/licenses/mit-license.php MIT
20 * @link http://phpdoc.org
24 /** @var string The current namespace. */
25 protected $namespace = '';
27 /** @var array List of namespace aliases => Fully Qualified Namespace. */
28 protected $namespace_aliases = array();
30 /** @var string Name of the structural element, within the namespace. */
34 * Cteates a new context.
35 * @param string $namespace The namespace where this DocBlock
37 * @param array $namespace_aliases List of namespace aliases => Fully
38 * Qualified Namespace.
39 * @param string $lsen Name of the structural element, within
42 public function __construct(
44 array $namespace_aliases = array(),
47 if (!empty($namespace)) {
48 $this->setNamespace($namespace);
50 $this->setNamespaceAliases($namespace_aliases);
51 $this->setLSEN($lsen);
55 * @return string The namespace where this DocBlock resides in.
57 public function getNamespace()
59 return $this->namespace;
63 * @return array List of namespace aliases => Fully Qualified Namespace.
65 public function getNamespaceAliases()
67 return $this->namespace_aliases;
71 * Returns the Local Structural Element Name.
73 * @return string Name of the structural element, within the namespace.
75 public function getLSEN()
81 * Sets a new namespace.
83 * Sets a new namespace for the context. Leading and trailing slashes are
84 * trimmed, and the keywords "global" and "default" are treated as aliases
87 * @param string $namespace The new namespace to set.
91 public function setNamespace($namespace)
93 if ('global' !== $namespace
94 && 'default' !== $namespace
96 // Srip leading and trailing slash
97 $this->namespace = trim((string)$namespace, '\\');
99 $this->namespace = '';
105 * Sets the namespace aliases, replacing all previous ones.
107 * @param array $namespace_aliases List of namespace aliases => Fully
108 * Qualified Namespace.
112 public function setNamespaceAliases(array $namespace_aliases)
114 $this->namespace_aliases = array();
115 foreach ($namespace_aliases as $alias => $fqnn) {
116 $this->setNamespaceAlias($alias, $fqnn);
122 * Adds a namespace alias to the context.
124 * @param string $alias The alias name (the part after "as", or the last
125 * part of the Fully Qualified Namespace Name) to add.
126 * @param string $fqnn The Fully Qualified Namespace Name for this alias.
127 * Any form of leading/trailing slashes are accepted, but what will be
128 * stored is a name, prefixed with a slash, and no trailing slash.
132 public function setNamespaceAlias($alias, $fqnn)
134 $this->namespace_aliases[$alias] = '\\' . trim((string)$fqnn, '\\');
139 * Sets a new Local Structural Element Name.
141 * Sets a new Local Structural Element Name. A local name also contains
142 * punctuation determining the kind of structural element (e.g. trailing "("
143 * and ")" for functions and methods).
145 * @param string $lsen The new local name of a structural element.
149 public function setLSEN($lsen)
151 $this->lsen = (string)$lsen;