81aa83ce537d42738558b25b9734c1e42dea0a15
[yaffs-website] / vendor / phpdocumentor / reflection-docblock / src / phpDocumentor / Reflection / DocBlock / Context.php
1 <?php
2 /**
3  * phpDocumentor
4  *
5  * PHP Version 5.3
6  *
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
11  */
12
13 namespace phpDocumentor\Reflection\DocBlock;
14
15 /**
16  * The context in which a DocBlock occurs.
17  *
18  * @author  Vasil Rangelov <boen.robot@gmail.com>
19  * @license http://www.opensource.org/licenses/mit-license.php MIT
20  * @link    http://phpdoc.org
21  */
22 class Context
23 {
24     /** @var string The current namespace. */
25     protected $namespace = '';
26
27     /** @var array List of namespace aliases => Fully Qualified Namespace. */
28     protected $namespace_aliases = array();
29     
30     /** @var string Name of the structural element, within the namespace. */
31     protected $lsen = '';
32     
33     /**
34      * Cteates a new context.
35      * @param string $namespace         The namespace where this DocBlock
36      *     resides in.
37      * @param array  $namespace_aliases List of namespace aliases => Fully
38      *     Qualified Namespace.
39      * @param string $lsen              Name of the structural element, within
40      *     the namespace.
41      */
42     public function __construct(
43         $namespace = '',
44         array $namespace_aliases = array(),
45         $lsen = ''
46     ) {
47         if (!empty($namespace)) {
48             $this->setNamespace($namespace);
49         }
50         $this->setNamespaceAliases($namespace_aliases);
51         $this->setLSEN($lsen);
52     }
53
54     /**
55      * @return string The namespace where this DocBlock resides in.
56      */
57     public function getNamespace()
58     {
59         return $this->namespace;
60     }
61
62     /**
63      * @return array List of namespace aliases => Fully Qualified Namespace.
64      */
65     public function getNamespaceAliases()
66     {
67         return $this->namespace_aliases;
68     }
69     
70     /**
71      * Returns the Local Structural Element Name.
72      * 
73      * @return string Name of the structural element, within the namespace.
74      */
75     public function getLSEN()
76     {
77         return $this->lsen;
78     }
79     
80     /**
81      * Sets a new namespace.
82      * 
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
85      * to no namespace.
86      * 
87      * @param string $namespace The new namespace to set.
88      * 
89      * @return $this
90      */
91     public function setNamespace($namespace)
92     {
93         if ('global' !== $namespace
94             && 'default' !== $namespace
95         ) {
96             // Srip leading and trailing slash
97             $this->namespace = trim((string)$namespace, '\\');
98         } else {
99             $this->namespace = '';
100         }
101         return $this;
102     }
103     
104     /**
105      * Sets the namespace aliases, replacing all previous ones.
106      * 
107      * @param array $namespace_aliases List of namespace aliases => Fully
108      *     Qualified Namespace.
109      * 
110      * @return $this
111      */
112     public function setNamespaceAliases(array $namespace_aliases)
113     {
114         $this->namespace_aliases = array();
115         foreach ($namespace_aliases as $alias => $fqnn) {
116             $this->setNamespaceAlias($alias, $fqnn);
117         }
118         return $this;
119     }
120     
121     /**
122      * Adds a namespace alias to the context.
123      * 
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.
129      * 
130      * @return $this
131      */
132     public function setNamespaceAlias($alias, $fqnn)
133     {
134         $this->namespace_aliases[$alias] = '\\' . trim((string)$fqnn, '\\');
135         return $this;
136     }
137     
138     /**
139      * Sets a new Local Structural Element Name.
140      * 
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).
144      * 
145      * @param string $lsen The new local name of a structural element.
146      * 
147      * @return $this
148      */
149     public function setLSEN($lsen)
150     {
151         $this->lsen = (string)$lsen;
152         return $this;
153     }
154 }