1: <?php
2: /**
3: * @author Jefferson González
4: * @license MIT
5: * @link http://github.com/peg-org/peg-src Source code.
6: */
7:
8: namespace Peg\Lib\Definitions\Element;
9:
10: /**
11: * Represents a namespace.
12: */
13: class NamespaceElement
14: {
15:
16: /**
17: * Holds the name of the namespace.
18: * @var string
19: */
20: public $name;
21:
22: /**
23: * Flag that indicates if this is the global scope namespace (\).
24: * @var bool
25: */
26: public $is_global;
27:
28: /**
29: * Array of constants declared on the namespace.
30: * @var \Peg\Lib\Definitions\Element\Constant[]
31: */
32: public $constants;
33:
34: /**
35: * Array of enumerations declared on the namespace.
36: * @var \Peg\Lib\Definitions\Element\Enumeration[]
37: */
38: public $enumerations;
39:
40: /**
41: * Array of type definitions declared on the file.
42: * @var \Peg\Lib\Definitions\Element\TypeDef[]
43: */
44: public $type_definitions;
45:
46: /**
47: * Array of variables declared on the namespace.
48: * @var \Peg\Lib\Definitions\Element\GlobalVariable[]
49: */
50: public $global_variables;
51:
52: /**
53: * Array of functions declared on the namespace.
54: * @var \Peg\Lib\Definitions\Element\FunctionElement[]
55: */
56: public $functions;
57:
58: /**
59: * Array of classes declared on the namespace.
60: * @var \Peg\Lib\Definitions\Element\ClassElement[]
61: */
62: public $classes;
63:
64: /**
65: * Initializes a namespace element.
66: * @param string $name
67: */
68: public function __construct($name)
69: {
70: if($name == "")
71: $name = "\\";
72:
73: $this->name = $name;
74:
75: if($name == "\\")
76: {
77: $this->is_global = true;
78: }
79: else
80: {
81: $this->is_global = false;
82: }
83:
84: $this->constants = array();
85:
86: $this->enumerations = array();
87:
88: $this->type_definitions = array();
89:
90: $this->global_variables = array();
91:
92: $this->functions = array();
93:
94: $this->classes = array();
95: }
96:
97: /**
98: * Check if the namespace has constants.
99: * @return bool
100: */
101: public function HasConstants()
102: {
103: return count($this->constants) > 0;
104: }
105:
106: /**
107: * Check if the namespace has enumerations.
108: * @return bool
109: */
110: public function HasEnumerations()
111: {
112: return count($this->enumerations) > 0;
113: }
114:
115: /**
116: * Check if the namespace has type definitions.
117: * @return bool
118: */
119: public function HasTypeDefs()
120: {
121: return count($this->type_definitions) > 0;
122: }
123:
124: /**
125: * Check if the namespace has global variables.
126: * @return bool
127: */
128: public function HasGlobalVariables()
129: {
130: return count($this->global_variables) > 0;
131: }
132:
133: /**
134: * Check if the namespace has functions.
135: * @return bool
136: */
137: public function HasFunctions()
138: {
139: return count($this->functions) > 0;
140: }
141:
142: /**
143: * Check if the namespace has classes.
144: * @return bool
145: */
146: public function HasClasses()
147: {
148: return count($this->classes) > 0;
149: }
150:
151: }