-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathContainer.php
159 lines (141 loc) · 3.01 KB
/
Container.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* Google_Container
*
* @desc Create a xhtml element container where the chart object resides.
* @package Google
* @author Thomas Schaefer
* @copyright Thomas Schaefer
* @since 2009-05-31
*/
/**
* Google_Container
*
* @desc Create a xhtml element container where the chart object resides.
* @package Google
* @author Thomas Schaefer
* @copyright Thomas Schaefer
* @since 2009-05-31
*/
class Google_Container {
/**
* @var string
*/
private $id;
/**
* @var string
*/
private $errorContainer;
/**
* @var Google_Container
*/
private $error;
/**
* @var bool
*/
private $hasPrefix = false;
/**
* @var string
*/
private $prefix = 'gc-';
/**
* @var string
*/
private $element = 'div';
/**
* @var array
*/
private $attributes = array();
/**
* __construct
* @param array $attributes
* @param string $prefix
* @param string $element
*/
public function __construct($attributes=array(), $prefix=true, $element='div') {
$this->element = (string) $element;
$this->attributes = $attributes;
$this->hasPrefix= (bool)$prefix;
}
/**
* reportTo
* @desc dependency injection of a container which is used to show
* repsonse messages
* @param string $name
* @param Google_Container $c
*/
public function reportTo($name, Google_Container $c) {
if($this->id !== $c->getHash()){
$this->errorContainer = $name;
$this->error = $c;
} else {
throw new InvalidArgumentException("id and hash are equal. It is not allowed to inject an object into itself.");
}
}
/**
* getErrorContainer
* @return string returns the name of the error container
*/
public function getErrorContainer() {
return $this->errorContainer;
}
/**
* getError
* @desc returns the error container's name
* @return string
*/
public function getError() {
if($this->error instanceof Google_Container) {
return $this->error->getErrorContainer();
} else {
return '';
}
}
/**
* setId
* @desc set the unique hash
* @return void
*/
public function setId(){
$this->id = spl_object_hash($this);
}
/**
* getHash
* @return string
*/
public function getHash(){
return $this->id;
}
/**
* getId
* @return string
*/
public function getId(){
return $this->id;
}
/**
*__toString
* render container into xhtml string
* @return string
*/
public function __toString() {
$string = '<'. $this->element;
$strAttr = array();
if($this->id) { // make container unique
$this->attributes["id"] = ($this->hasPrefix?$this->prefix:'').(array_key_exists("id",$this->attributes)?$this->attributes["id"]:$this->id);
$this->attributes["class"] = $this->prefix.(array_key_exists("class",$this->attributes)?$this->attributes["class"]:"container");
}
if(count($this->attributes)) {
foreach($this->attributes as $name => $val) {
$strAttr[] = $name .'="'. (string)$val.'"';
}
if(count($strAttr)>0){
$string .=' ';
$string .= implode(" ", $strAttr);
}
}
$string .= '>';
$string .= '</'. $this->element.'>';
return $string;
}
}