@@ -30,162 +30,162 @@ |
||
30 | 30 | */ |
31 | 31 | class Input extends Common |
32 | 32 | { |
33 | - /** |
|
34 | - * the name of element |
|
35 | - * |
|
36 | - * @access private |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $_sType = null; |
|
40 | - |
|
41 | - /** |
|
42 | - * the label of element |
|
43 | - * |
|
44 | - * @access private |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - private $_sLabel = null; |
|
48 | - |
|
49 | - /** |
|
50 | - * the value of element |
|
51 | - * |
|
52 | - * @access private |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - private $_sValue = null; |
|
56 | - |
|
57 | - /** |
|
58 | - * constructor that it increment (static) for all use |
|
59 | - * |
|
60 | - * @access public |
|
61 | - * @param string $sName name |
|
62 | - * @param string $sType type of input |
|
63 | - * @param string $sLabel label of input |
|
64 | - * @param string $sValue value of input |
|
65 | - */ |
|
66 | - public function __construct(string $sName, string $sType, string $sLabel = null, string $sValue = null) |
|
67 | - { |
|
68 | - $this->setName($sName); |
|
69 | - $this->setType($sType); |
|
70 | - $this->setValue($sValue); |
|
71 | - |
|
72 | - if ($sLabel !== null) { $this->setLabel($sLabel); } else { $this->setLabel($sName); } |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * get the type |
|
77 | - * |
|
78 | - * @access public |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getType() : string |
|
82 | - { |
|
83 | - return $this->_sType; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * set the type |
|
88 | - * |
|
89 | - * @access public |
|
90 | - * @param string $sType type of input; |
|
91 | - * @return \Venus\lib\Form\Input |
|
92 | - */ |
|
93 | - public function setType(string $sType) : Input |
|
94 | - { |
|
95 | - $this->_sType = $sType; |
|
96 | - return $this; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * get the Value |
|
101 | - * |
|
102 | - * @access public |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function getValue() : string |
|
106 | - { |
|
107 | - return $this->_sValue; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * set the Value |
|
112 | - * |
|
113 | - * @access public |
|
114 | - * @param string $sValue Value of input; |
|
115 | - * @return \Venus\lib\Form\Input |
|
116 | - */ |
|
117 | - public function setValue(string $sValue) : Input |
|
118 | - { |
|
119 | - $this->_sValue = $sValue; |
|
120 | - return $this; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * get the Label |
|
125 | - * |
|
126 | - * @access public |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function getLabel() : string |
|
130 | - { |
|
131 | - return $this->_sLabel; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * set the Label |
|
136 | - * |
|
137 | - * @access public |
|
138 | - * @param string $sLabel Label of input; |
|
139 | - * @return \Venus\lib\Form\Input |
|
140 | - */ |
|
141 | - public function setLabel(string $sLabel) : Input |
|
142 | - { |
|
143 | - $this->_sLabel = $sLabel; |
|
144 | - return $this; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * if the button is clicked |
|
149 | - * |
|
150 | - * @access public |
|
151 | - * @param string $sType type of input; |
|
152 | - * @return boolean |
|
153 | - */ |
|
154 | - public function isClicked(string $sType) : bool |
|
155 | - { |
|
156 | - if ($this->getType() === 'submit' || $this->getType() === 'button') { |
|
157 | - |
|
158 | - if (isset($_POST[$this->getName()])) { return true; } |
|
159 | - } |
|
160 | - |
|
161 | - return false; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * get the <html> |
|
166 | - * |
|
167 | - * @access public |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function fetch() : string |
|
171 | - { |
|
172 | - $sContent = ''; |
|
173 | - |
|
174 | - if ($this->getType() === 'text' || $this->getType() === 'password' || $this->getType() === 'file' |
|
175 | - || $this->getType() === 'tel' || $this->getType() === 'url' || $this->getType() === 'email' |
|
176 | - || $this->getType() === 'search' || $this->getType() === 'date' || $this->getType() === 'time' |
|
177 | - || $this->getType() === 'datetime' || $this->getType() === 'month' || $this->getType() === 'week' |
|
178 | - || $this->getType() === 'number' || $this->getType() === 'range' || $this->getType() === 'color') { |
|
179 | - |
|
180 | - $sContent .= '<label>'.$this->getLabel().'</label> '; |
|
181 | - } |
|
182 | - |
|
183 | - $sContent .= '<input type="'.$this->getType().'" name="'.$this->getName().'"'; |
|
184 | - |
|
185 | - if ($this->getValue() !== null) { $sContent .= ' value="'.$this->getValue().'"'; } |
|
186 | - |
|
187 | - $sContent .= '/>'; |
|
188 | - |
|
189 | - return $sContent; |
|
190 | - } |
|
33 | + /** |
|
34 | + * the name of element |
|
35 | + * |
|
36 | + * @access private |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $_sType = null; |
|
40 | + |
|
41 | + /** |
|
42 | + * the label of element |
|
43 | + * |
|
44 | + * @access private |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + private $_sLabel = null; |
|
48 | + |
|
49 | + /** |
|
50 | + * the value of element |
|
51 | + * |
|
52 | + * @access private |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + private $_sValue = null; |
|
56 | + |
|
57 | + /** |
|
58 | + * constructor that it increment (static) for all use |
|
59 | + * |
|
60 | + * @access public |
|
61 | + * @param string $sName name |
|
62 | + * @param string $sType type of input |
|
63 | + * @param string $sLabel label of input |
|
64 | + * @param string $sValue value of input |
|
65 | + */ |
|
66 | + public function __construct(string $sName, string $sType, string $sLabel = null, string $sValue = null) |
|
67 | + { |
|
68 | + $this->setName($sName); |
|
69 | + $this->setType($sType); |
|
70 | + $this->setValue($sValue); |
|
71 | + |
|
72 | + if ($sLabel !== null) { $this->setLabel($sLabel); } else { $this->setLabel($sName); } |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * get the type |
|
77 | + * |
|
78 | + * @access public |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getType() : string |
|
82 | + { |
|
83 | + return $this->_sType; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * set the type |
|
88 | + * |
|
89 | + * @access public |
|
90 | + * @param string $sType type of input; |
|
91 | + * @return \Venus\lib\Form\Input |
|
92 | + */ |
|
93 | + public function setType(string $sType) : Input |
|
94 | + { |
|
95 | + $this->_sType = $sType; |
|
96 | + return $this; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * get the Value |
|
101 | + * |
|
102 | + * @access public |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function getValue() : string |
|
106 | + { |
|
107 | + return $this->_sValue; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * set the Value |
|
112 | + * |
|
113 | + * @access public |
|
114 | + * @param string $sValue Value of input; |
|
115 | + * @return \Venus\lib\Form\Input |
|
116 | + */ |
|
117 | + public function setValue(string $sValue) : Input |
|
118 | + { |
|
119 | + $this->_sValue = $sValue; |
|
120 | + return $this; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * get the Label |
|
125 | + * |
|
126 | + * @access public |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function getLabel() : string |
|
130 | + { |
|
131 | + return $this->_sLabel; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * set the Label |
|
136 | + * |
|
137 | + * @access public |
|
138 | + * @param string $sLabel Label of input; |
|
139 | + * @return \Venus\lib\Form\Input |
|
140 | + */ |
|
141 | + public function setLabel(string $sLabel) : Input |
|
142 | + { |
|
143 | + $this->_sLabel = $sLabel; |
|
144 | + return $this; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * if the button is clicked |
|
149 | + * |
|
150 | + * @access public |
|
151 | + * @param string $sType type of input; |
|
152 | + * @return boolean |
|
153 | + */ |
|
154 | + public function isClicked(string $sType) : bool |
|
155 | + { |
|
156 | + if ($this->getType() === 'submit' || $this->getType() === 'button') { |
|
157 | + |
|
158 | + if (isset($_POST[$this->getName()])) { return true; } |
|
159 | + } |
|
160 | + |
|
161 | + return false; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * get the <html> |
|
166 | + * |
|
167 | + * @access public |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function fetch() : string |
|
171 | + { |
|
172 | + $sContent = ''; |
|
173 | + |
|
174 | + if ($this->getType() === 'text' || $this->getType() === 'password' || $this->getType() === 'file' |
|
175 | + || $this->getType() === 'tel' || $this->getType() === 'url' || $this->getType() === 'email' |
|
176 | + || $this->getType() === 'search' || $this->getType() === 'date' || $this->getType() === 'time' |
|
177 | + || $this->getType() === 'datetime' || $this->getType() === 'month' || $this->getType() === 'week' |
|
178 | + || $this->getType() === 'number' || $this->getType() === 'range' || $this->getType() === 'color') { |
|
179 | + |
|
180 | + $sContent .= '<label>'.$this->getLabel().'</label> '; |
|
181 | + } |
|
182 | + |
|
183 | + $sContent .= '<input type="'.$this->getType().'" name="'.$this->getName().'"'; |
|
184 | + |
|
185 | + if ($this->getValue() !== null) { $sContent .= ' value="'.$this->getValue().'"'; } |
|
186 | + |
|
187 | + $sContent .= '/>'; |
|
188 | + |
|
189 | + return $sContent; |
|
190 | + } |
|
191 | 191 | } |
@@ -33,207 +33,207 @@ |
||
33 | 33 | */ |
34 | 34 | class Container |
35 | 35 | { |
36 | - /** |
|
37 | - * complete view |
|
38 | - * |
|
39 | - * @access private |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - private $_sView = null; |
|
43 | - |
|
44 | - /** |
|
45 | - * form library with its entity |
|
46 | - * |
|
47 | - * @access private |
|
48 | - * @var Form |
|
49 | - */ |
|
50 | - private $_oForm = null; |
|
51 | - |
|
52 | - /** |
|
53 | - * Block the save in the entity if you don't call handleRequest |
|
54 | - * |
|
55 | - * @access private |
|
56 | - * @var bool |
|
57 | - */ |
|
58 | - private $_bHandleRequestActivate = false; |
|
59 | - |
|
60 | - /** |
|
61 | - * Request of the formular |
|
62 | - * |
|
63 | - * @access private |
|
64 | - * @var array |
|
65 | - */ |
|
66 | - private $_aRequest = null; |
|
67 | - |
|
68 | - /** |
|
69 | - * get the Value |
|
70 | - * |
|
71 | - * @access public |
|
72 | - * @return \stdClass |
|
73 | - */ |
|
74 | - public function createView() : \stdClass |
|
75 | - { |
|
76 | - $oView = new \stdClass; |
|
77 | - $oView->form = $this->_sView; |
|
78 | - $oView->form_start = $this->_oForm->getFormInObject()->start; |
|
79 | - $oView->form_end = $this->_oForm->getFormInObject()->end; |
|
80 | - $oView->form_row = array(); |
|
81 | - |
|
82 | - foreach ($this->_oForm->getFormInObject()->form as $sKey => $mValue) { |
|
83 | - |
|
84 | - if ($mValue instanceof Container) { |
|
85 | - |
|
86 | - $oNewForm = $mValue->createView(); |
|
87 | - $oView->form_row[$sKey] = $oNewForm->form_row; |
|
88 | - } else { |
|
89 | - |
|
90 | - $oView->form_row[$sKey] = $mValue; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - return $oView; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * set the Value |
|
99 | - * |
|
100 | - * @access public |
|
101 | - * @param string $sView Display of form; |
|
102 | - * @return \Venus\lib\Form\Container |
|
103 | - */ |
|
104 | - public function setView(string $sView) : Container |
|
105 | - { |
|
106 | - $this->_sView = $sView; |
|
107 | - return $this; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * handle the request to do many actions on it |
|
112 | - * |
|
113 | - * @access public |
|
114 | - * @param array $aRequest request like $_POST |
|
115 | - * @return bool |
|
116 | - */ |
|
117 | - public function handleRequest(array $aRequest) : bool |
|
118 | - { |
|
119 | - if (!count($_POST)) { return true; } |
|
120 | - |
|
121 | - // Validation |
|
122 | - foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
123 | - |
|
124 | - if (!$sValue instanceof self && !$this->_validate($sValue)) { |
|
125 | - |
|
126 | - return false; |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - // Save |
|
131 | - if ($this->_oForm->getIdEntity() > 0 && $this->_oForm->getSynchronizeEntity() !== null && count($aRequest) > 0) { |
|
132 | - |
|
133 | - $sModelName = str_replace('Entity', 'Model', $this->_oForm->getSynchronizeEntity()); |
|
134 | - $oModel = new $sModelName; |
|
135 | - |
|
136 | - $oEntity = new $this->_oForm->getSynchronizeEntity(); |
|
137 | - $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
138 | - $sMethodName = 'set_'.$sPrimaryKey; |
|
139 | - |
|
140 | - call_user_func_array(array(&$oEntity, $sMethodName), array($this->_oForm->getIdEntity())); |
|
141 | - |
|
142 | - foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
143 | - |
|
144 | - $sMethodName = 'set_'.$sValue->getName().''; |
|
145 | - call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
|
146 | - } |
|
147 | - |
|
148 | - $oEntity->save(); |
|
149 | - } else if ($this->_oForm->getSynchronizeEntity() !== null && isset($aRequest) && count($aRequest) > 0) { |
|
150 | - |
|
151 | - $oEntity = new $this->_oForm->_sSynchronizeEntity; |
|
152 | - |
|
153 | - foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
154 | - |
|
155 | - $sMethodName = 'set_'.$sValue->getName().''; |
|
156 | - call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
|
157 | - } |
|
158 | - |
|
159 | - $this->_oForm->setIdEntityCreated($oEntity->save()); |
|
160 | - } |
|
161 | - |
|
162 | - $this->_bHandleRequestActivate = true; |
|
163 | - $this->_aRequest = $aRequest; |
|
164 | - return true; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * set Form lib with its entity |
|
169 | - * |
|
170 | - * @access public |
|
171 | - * @param Form $oForm request like $_POST |
|
172 | - * @return \Venus\lib\Form\Container |
|
173 | - */ |
|
174 | - public function setForm(Form $oForm) : Container |
|
175 | - { |
|
176 | - $this->_oForm = $oForm; |
|
177 | - return $this; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * if this form is validate and save |
|
182 | - * |
|
183 | - * @access public |
|
184 | - * @return boolean |
|
185 | - */ |
|
186 | - public function isValid() : bool |
|
187 | - { |
|
188 | - if ($this->_bHandleRequestActivate === true) { return true; } else { return false; } |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * if this form is validate and save |
|
193 | - * |
|
194 | - * @access public |
|
195 | - * @return boolean |
|
196 | - */ |
|
197 | - public function isSubmitted() : bool |
|
198 | - { |
|
199 | - if (isset($_POST['validform'.$this->_oForm->getFormNumber()]) && $_POST['validform'.$this->_oForm->getFormNumber()] == 1) { |
|
200 | - |
|
201 | - return true; |
|
202 | - } else { |
|
203 | - |
|
204 | - return false; |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * if this form is validate and save |
|
210 | - * |
|
211 | - * @access public |
|
212 | - * @param string $sElementName element name what we want test the click |
|
213 | - * @return boolean |
|
214 | - */ |
|
215 | - public function isClicked(string $sElementName) : bool |
|
216 | - { |
|
217 | - if (isset($_POST[$sElementName]) && $_POST[$sElementName]) { return true; } else { return false; } |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * if the element is valide or not (with the constraint) |
|
222 | - * |
|
223 | - * @access private |
|
224 | - * @param object $oElement element of formular |
|
225 | - * @return boolean |
|
226 | - */ |
|
227 | - private function _validate($oElement) : bool |
|
228 | - { |
|
229 | - foreach ($oElement->getConstraint() as $oConstraint) { |
|
230 | - |
|
231 | - if (!$oConstraint->validate($_POST[$oElement->getName()])) { |
|
232 | - |
|
233 | - return false; |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - return true; |
|
238 | - } |
|
36 | + /** |
|
37 | + * complete view |
|
38 | + * |
|
39 | + * @access private |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + private $_sView = null; |
|
43 | + |
|
44 | + /** |
|
45 | + * form library with its entity |
|
46 | + * |
|
47 | + * @access private |
|
48 | + * @var Form |
|
49 | + */ |
|
50 | + private $_oForm = null; |
|
51 | + |
|
52 | + /** |
|
53 | + * Block the save in the entity if you don't call handleRequest |
|
54 | + * |
|
55 | + * @access private |
|
56 | + * @var bool |
|
57 | + */ |
|
58 | + private $_bHandleRequestActivate = false; |
|
59 | + |
|
60 | + /** |
|
61 | + * Request of the formular |
|
62 | + * |
|
63 | + * @access private |
|
64 | + * @var array |
|
65 | + */ |
|
66 | + private $_aRequest = null; |
|
67 | + |
|
68 | + /** |
|
69 | + * get the Value |
|
70 | + * |
|
71 | + * @access public |
|
72 | + * @return \stdClass |
|
73 | + */ |
|
74 | + public function createView() : \stdClass |
|
75 | + { |
|
76 | + $oView = new \stdClass; |
|
77 | + $oView->form = $this->_sView; |
|
78 | + $oView->form_start = $this->_oForm->getFormInObject()->start; |
|
79 | + $oView->form_end = $this->_oForm->getFormInObject()->end; |
|
80 | + $oView->form_row = array(); |
|
81 | + |
|
82 | + foreach ($this->_oForm->getFormInObject()->form as $sKey => $mValue) { |
|
83 | + |
|
84 | + if ($mValue instanceof Container) { |
|
85 | + |
|
86 | + $oNewForm = $mValue->createView(); |
|
87 | + $oView->form_row[$sKey] = $oNewForm->form_row; |
|
88 | + } else { |
|
89 | + |
|
90 | + $oView->form_row[$sKey] = $mValue; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + return $oView; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * set the Value |
|
99 | + * |
|
100 | + * @access public |
|
101 | + * @param string $sView Display of form; |
|
102 | + * @return \Venus\lib\Form\Container |
|
103 | + */ |
|
104 | + public function setView(string $sView) : Container |
|
105 | + { |
|
106 | + $this->_sView = $sView; |
|
107 | + return $this; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * handle the request to do many actions on it |
|
112 | + * |
|
113 | + * @access public |
|
114 | + * @param array $aRequest request like $_POST |
|
115 | + * @return bool |
|
116 | + */ |
|
117 | + public function handleRequest(array $aRequest) : bool |
|
118 | + { |
|
119 | + if (!count($_POST)) { return true; } |
|
120 | + |
|
121 | + // Validation |
|
122 | + foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
123 | + |
|
124 | + if (!$sValue instanceof self && !$this->_validate($sValue)) { |
|
125 | + |
|
126 | + return false; |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + // Save |
|
131 | + if ($this->_oForm->getIdEntity() > 0 && $this->_oForm->getSynchronizeEntity() !== null && count($aRequest) > 0) { |
|
132 | + |
|
133 | + $sModelName = str_replace('Entity', 'Model', $this->_oForm->getSynchronizeEntity()); |
|
134 | + $oModel = new $sModelName; |
|
135 | + |
|
136 | + $oEntity = new $this->_oForm->getSynchronizeEntity(); |
|
137 | + $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
138 | + $sMethodName = 'set_'.$sPrimaryKey; |
|
139 | + |
|
140 | + call_user_func_array(array(&$oEntity, $sMethodName), array($this->_oForm->getIdEntity())); |
|
141 | + |
|
142 | + foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
143 | + |
|
144 | + $sMethodName = 'set_'.$sValue->getName().''; |
|
145 | + call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
|
146 | + } |
|
147 | + |
|
148 | + $oEntity->save(); |
|
149 | + } else if ($this->_oForm->getSynchronizeEntity() !== null && isset($aRequest) && count($aRequest) > 0) { |
|
150 | + |
|
151 | + $oEntity = new $this->_oForm->_sSynchronizeEntity; |
|
152 | + |
|
153 | + foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
154 | + |
|
155 | + $sMethodName = 'set_'.$sValue->getName().''; |
|
156 | + call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
|
157 | + } |
|
158 | + |
|
159 | + $this->_oForm->setIdEntityCreated($oEntity->save()); |
|
160 | + } |
|
161 | + |
|
162 | + $this->_bHandleRequestActivate = true; |
|
163 | + $this->_aRequest = $aRequest; |
|
164 | + return true; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * set Form lib with its entity |
|
169 | + * |
|
170 | + * @access public |
|
171 | + * @param Form $oForm request like $_POST |
|
172 | + * @return \Venus\lib\Form\Container |
|
173 | + */ |
|
174 | + public function setForm(Form $oForm) : Container |
|
175 | + { |
|
176 | + $this->_oForm = $oForm; |
|
177 | + return $this; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * if this form is validate and save |
|
182 | + * |
|
183 | + * @access public |
|
184 | + * @return boolean |
|
185 | + */ |
|
186 | + public function isValid() : bool |
|
187 | + { |
|
188 | + if ($this->_bHandleRequestActivate === true) { return true; } else { return false; } |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * if this form is validate and save |
|
193 | + * |
|
194 | + * @access public |
|
195 | + * @return boolean |
|
196 | + */ |
|
197 | + public function isSubmitted() : bool |
|
198 | + { |
|
199 | + if (isset($_POST['validform'.$this->_oForm->getFormNumber()]) && $_POST['validform'.$this->_oForm->getFormNumber()] == 1) { |
|
200 | + |
|
201 | + return true; |
|
202 | + } else { |
|
203 | + |
|
204 | + return false; |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * if this form is validate and save |
|
210 | + * |
|
211 | + * @access public |
|
212 | + * @param string $sElementName element name what we want test the click |
|
213 | + * @return boolean |
|
214 | + */ |
|
215 | + public function isClicked(string $sElementName) : bool |
|
216 | + { |
|
217 | + if (isset($_POST[$sElementName]) && $_POST[$sElementName]) { return true; } else { return false; } |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * if the element is valide or not (with the constraint) |
|
222 | + * |
|
223 | + * @access private |
|
224 | + * @param object $oElement element of formular |
|
225 | + * @return boolean |
|
226 | + */ |
|
227 | + private function _validate($oElement) : bool |
|
228 | + { |
|
229 | + foreach ($oElement->getConstraint() as $oConstraint) { |
|
230 | + |
|
231 | + if (!$oConstraint->validate($_POST[$oElement->getName()])) { |
|
232 | + |
|
233 | + return false; |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + return true; |
|
238 | + } |
|
239 | 239 | } |
@@ -30,201 +30,201 @@ |
||
30 | 30 | */ |
31 | 31 | class Date |
32 | 32 | { |
33 | - /** |
|
34 | - * set name of image |
|
35 | - * |
|
36 | - * @access public |
|
37 | - * @param int $iWeek number of week |
|
38 | - * @param int $iYear year |
|
39 | - * @param string $sFormat |
|
40 | - * @return Date |
|
41 | - */ |
|
42 | - public static function getWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : Date |
|
43 | - { |
|
44 | - $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
45 | - |
|
46 | - if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
47 | - |
|
48 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; } |
|
49 | - |
|
50 | - $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift; |
|
51 | - $iTimestampLastDay = mktime(0, 0, 0, 1, 6, $iYear) + $iWeekInSeconds + $iShift + 604800; |
|
52 | - |
|
53 | - return array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay)); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * set name of image |
|
58 | - * |
|
59 | - * @access public |
|
60 | - * @return \Venus\lib\Date |
|
61 | - */ |
|
62 | - public static function getActualWeek() : Date |
|
63 | - { |
|
64 | - return self::getWeek(date('W'), date('Y')); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * set name of image |
|
69 | - * |
|
70 | - * @access public |
|
71 | - * @param string $sMonth number of week |
|
72 | - * @param string $sLanguage language |
|
73 | - * @return \Venus\lib\Date |
|
74 | - */ |
|
75 | - public static function getMonthInWord(string $sMonth, string $sLanguage = 'fr') : Date |
|
76 | - { |
|
77 | - if ($sLanguage == 'fr') { |
|
78 | - |
|
79 | - if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } |
|
80 | - else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } |
|
81 | - else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } |
|
82 | - else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } |
|
83 | - else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } |
|
84 | - else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } |
|
85 | - else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } |
|
86 | - else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } |
|
87 | - else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } |
|
88 | - else if ($sMonth == 10) { return 'Octobre'; } |
|
89 | - else if ($sMonth == 11) { return 'Novembre'; } |
|
90 | - else if ($sMonth == 12) { return 'Décembre'; } |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * set name of image |
|
96 | - * |
|
97 | - * @access public |
|
98 | - * @param mixed $sDay number of day |
|
99 | - * @param string $sLanguage language |
|
100 | - * @return \Venus\lib\Date |
|
101 | - */ |
|
102 | - public static function getDayInWord(string $sDay, string $sLanguage = 'fr') : Date |
|
103 | - { |
|
104 | - if ($sLanguage == 'fr') { |
|
105 | - |
|
106 | - if ($sDay == 0) { return 'dimanche'; } |
|
107 | - else if ($sDay == 1) { return 'lundi'; } |
|
108 | - else if ($sDay == 2) { return 'mardi'; } |
|
109 | - else if ($sDay == 3) { return 'mercredi'; } |
|
110 | - else if ($sDay == 4) { return 'jeudi'; } |
|
111 | - else if ($sDay == 5) { return 'vendredi'; } |
|
112 | - else if ($sDay == 6) { return 'samedi'; } |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * get age by date |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @param unknown $sBirthday |
|
121 | - * @return int |
|
122 | - */ |
|
123 | - public static function getAgeByDate(string $sBirthday) : int |
|
124 | - { |
|
125 | - list($iYear, $iMonth, $iDay) = preg_split('/[-.]/', $sBirthday); |
|
126 | - |
|
127 | - $aToday = array(); |
|
128 | - $aToday['mois'] = date('n'); |
|
129 | - $aToday['jour'] = date('j'); |
|
130 | - $aToday['annee'] = date('Y'); |
|
131 | - |
|
132 | - $iYears = $aToday['annee'] - $iYear; |
|
133 | - |
|
134 | - if ($aToday['mois'] <= $iMonth) { |
|
135 | - |
|
136 | - if ($iMonth == $aToday['mois']) { |
|
137 | - |
|
138 | - if ($iDay > $aToday['jour']) { $iYears--; } |
|
139 | - } |
|
140 | - else { |
|
141 | - |
|
142 | - $iYears--; |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - return $iYears; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * set name of image |
|
151 | - * |
|
152 | - * @access public |
|
153 | - * @param int $iWeek number of week |
|
154 | - * @param int $iYear year |
|
155 | - * @return \Venus\lib\Date |
|
156 | - */ |
|
157 | - public static function getMiddleWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : array |
|
158 | - { |
|
159 | - $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
160 | - |
|
161 | - if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
|
162 | - else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
163 | - |
|
164 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
165 | - else { $iWeekInSeconds = 0; } |
|
166 | - |
|
167 | - if (date('N') > 2) { |
|
168 | - |
|
169 | - $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift + 172800; |
|
170 | - $iTimestampLastDay = $iTimestamp + 604800; |
|
171 | - } |
|
172 | - else { |
|
173 | - |
|
174 | - $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift - 432000; |
|
175 | - $iTimestampLastDay = $iTimestamp + 604800; |
|
176 | - } |
|
177 | - |
|
178 | - $aDates = array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay)); |
|
179 | - |
|
180 | - if (preg_replace('/^([0-9]+)-[0-9]+-[0-9]+$/', '$1', $aDates[0]) != date('Y')) { |
|
181 | - |
|
182 | - $aDates[0] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', date('Y').'$1', $aDates[0]); |
|
183 | - $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y')+1).'$1', $aDates[1]); |
|
184 | - } |
|
185 | - |
|
186 | - return $aDates; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * set name of image |
|
191 | - * |
|
192 | - * @access public |
|
193 | - * @return array |
|
194 | - */ |
|
195 | - public static function getActualMiddleWeek() : array |
|
196 | - { |
|
197 | - return self::getMiddleWeek(date('W'), date('Y')); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * get time of kind "X hour ago" |
|
202 | - * |
|
203 | - * @access public |
|
204 | - * @param string $sDateTime datetime to convert |
|
205 | - * @param string $sLanguage language |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - public static function getTimeAgoInString(string $sDateTime, string $sLanguage = 'fr') : string |
|
209 | - { |
|
210 | - if ($sLanguage == 'fr') { |
|
211 | - |
|
212 | - $sStartReturn = 'Il y a'; |
|
213 | - $sEndReturn = ''; |
|
214 | - $sMinutes = 'minute(s) '; |
|
215 | - $sHours = 'heure(s) '; |
|
216 | - $sDays = 'jour(s) '; |
|
217 | - $sMonths = 'mois '; |
|
218 | - $sYears = 'mois '; |
|
219 | - } |
|
220 | - |
|
221 | - $oDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $sDateTime); |
|
222 | - $iTimeStamp = time() - $oDateTime->getTimestamp(); |
|
223 | - |
|
224 | - if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; } |
|
225 | - if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; } |
|
226 | - if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; } |
|
227 | - if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } |
|
228 | - else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
229 | - } |
|
33 | + /** |
|
34 | + * set name of image |
|
35 | + * |
|
36 | + * @access public |
|
37 | + * @param int $iWeek number of week |
|
38 | + * @param int $iYear year |
|
39 | + * @param string $sFormat |
|
40 | + * @return Date |
|
41 | + */ |
|
42 | + public static function getWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : Date |
|
43 | + { |
|
44 | + $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
45 | + |
|
46 | + if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
47 | + |
|
48 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; } |
|
49 | + |
|
50 | + $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift; |
|
51 | + $iTimestampLastDay = mktime(0, 0, 0, 1, 6, $iYear) + $iWeekInSeconds + $iShift + 604800; |
|
52 | + |
|
53 | + return array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay)); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * set name of image |
|
58 | + * |
|
59 | + * @access public |
|
60 | + * @return \Venus\lib\Date |
|
61 | + */ |
|
62 | + public static function getActualWeek() : Date |
|
63 | + { |
|
64 | + return self::getWeek(date('W'), date('Y')); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * set name of image |
|
69 | + * |
|
70 | + * @access public |
|
71 | + * @param string $sMonth number of week |
|
72 | + * @param string $sLanguage language |
|
73 | + * @return \Venus\lib\Date |
|
74 | + */ |
|
75 | + public static function getMonthInWord(string $sMonth, string $sLanguage = 'fr') : Date |
|
76 | + { |
|
77 | + if ($sLanguage == 'fr') { |
|
78 | + |
|
79 | + if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } |
|
80 | + else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } |
|
81 | + else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } |
|
82 | + else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } |
|
83 | + else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } |
|
84 | + else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } |
|
85 | + else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } |
|
86 | + else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } |
|
87 | + else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } |
|
88 | + else if ($sMonth == 10) { return 'Octobre'; } |
|
89 | + else if ($sMonth == 11) { return 'Novembre'; } |
|
90 | + else if ($sMonth == 12) { return 'Décembre'; } |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * set name of image |
|
96 | + * |
|
97 | + * @access public |
|
98 | + * @param mixed $sDay number of day |
|
99 | + * @param string $sLanguage language |
|
100 | + * @return \Venus\lib\Date |
|
101 | + */ |
|
102 | + public static function getDayInWord(string $sDay, string $sLanguage = 'fr') : Date |
|
103 | + { |
|
104 | + if ($sLanguage == 'fr') { |
|
105 | + |
|
106 | + if ($sDay == 0) { return 'dimanche'; } |
|
107 | + else if ($sDay == 1) { return 'lundi'; } |
|
108 | + else if ($sDay == 2) { return 'mardi'; } |
|
109 | + else if ($sDay == 3) { return 'mercredi'; } |
|
110 | + else if ($sDay == 4) { return 'jeudi'; } |
|
111 | + else if ($sDay == 5) { return 'vendredi'; } |
|
112 | + else if ($sDay == 6) { return 'samedi'; } |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * get age by date |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @param unknown $sBirthday |
|
121 | + * @return int |
|
122 | + */ |
|
123 | + public static function getAgeByDate(string $sBirthday) : int |
|
124 | + { |
|
125 | + list($iYear, $iMonth, $iDay) = preg_split('/[-.]/', $sBirthday); |
|
126 | + |
|
127 | + $aToday = array(); |
|
128 | + $aToday['mois'] = date('n'); |
|
129 | + $aToday['jour'] = date('j'); |
|
130 | + $aToday['annee'] = date('Y'); |
|
131 | + |
|
132 | + $iYears = $aToday['annee'] - $iYear; |
|
133 | + |
|
134 | + if ($aToday['mois'] <= $iMonth) { |
|
135 | + |
|
136 | + if ($iMonth == $aToday['mois']) { |
|
137 | + |
|
138 | + if ($iDay > $aToday['jour']) { $iYears--; } |
|
139 | + } |
|
140 | + else { |
|
141 | + |
|
142 | + $iYears--; |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + return $iYears; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * set name of image |
|
151 | + * |
|
152 | + * @access public |
|
153 | + * @param int $iWeek number of week |
|
154 | + * @param int $iYear year |
|
155 | + * @return \Venus\lib\Date |
|
156 | + */ |
|
157 | + public static function getMiddleWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : array |
|
158 | + { |
|
159 | + $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
160 | + |
|
161 | + if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
|
162 | + else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
163 | + |
|
164 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
165 | + else { $iWeekInSeconds = 0; } |
|
166 | + |
|
167 | + if (date('N') > 2) { |
|
168 | + |
|
169 | + $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift + 172800; |
|
170 | + $iTimestampLastDay = $iTimestamp + 604800; |
|
171 | + } |
|
172 | + else { |
|
173 | + |
|
174 | + $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift - 432000; |
|
175 | + $iTimestampLastDay = $iTimestamp + 604800; |
|
176 | + } |
|
177 | + |
|
178 | + $aDates = array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay)); |
|
179 | + |
|
180 | + if (preg_replace('/^([0-9]+)-[0-9]+-[0-9]+$/', '$1', $aDates[0]) != date('Y')) { |
|
181 | + |
|
182 | + $aDates[0] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', date('Y').'$1', $aDates[0]); |
|
183 | + $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y')+1).'$1', $aDates[1]); |
|
184 | + } |
|
185 | + |
|
186 | + return $aDates; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * set name of image |
|
191 | + * |
|
192 | + * @access public |
|
193 | + * @return array |
|
194 | + */ |
|
195 | + public static function getActualMiddleWeek() : array |
|
196 | + { |
|
197 | + return self::getMiddleWeek(date('W'), date('Y')); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * get time of kind "X hour ago" |
|
202 | + * |
|
203 | + * @access public |
|
204 | + * @param string $sDateTime datetime to convert |
|
205 | + * @param string $sLanguage language |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + public static function getTimeAgoInString(string $sDateTime, string $sLanguage = 'fr') : string |
|
209 | + { |
|
210 | + if ($sLanguage == 'fr') { |
|
211 | + |
|
212 | + $sStartReturn = 'Il y a'; |
|
213 | + $sEndReturn = ''; |
|
214 | + $sMinutes = 'minute(s) '; |
|
215 | + $sHours = 'heure(s) '; |
|
216 | + $sDays = 'jour(s) '; |
|
217 | + $sMonths = 'mois '; |
|
218 | + $sYears = 'mois '; |
|
219 | + } |
|
220 | + |
|
221 | + $oDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $sDateTime); |
|
222 | + $iTimeStamp = time() - $oDateTime->getTimestamp(); |
|
223 | + |
|
224 | + if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; } |
|
225 | + if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; } |
|
226 | + if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; } |
|
227 | + if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } |
|
228 | + else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
229 | + } |
|
230 | 230 | } |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public static function getWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : Date |
43 | 43 | { |
44 | - $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
44 | + $iFirstDayInYear = date("N", mktime(0, 0, 0, 1, 1, $iYear)); |
|
45 | 45 | |
46 | 46 | if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
47 | 47 | |
48 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; } |
|
48 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek - 1) * 604800; } else { $iWeekInSeconds = 0; } |
|
49 | 49 | |
50 | 50 | $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift; |
51 | 51 | $iTimestampLastDay = mktime(0, 0, 0, 1, 6, $iYear) + $iWeekInSeconds + $iShift + 604800; |
@@ -156,12 +156,12 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public static function getMiddleWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : array |
158 | 158 | { |
159 | - $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
159 | + $iFirstDayInYear = date("N", mktime(0, 0, 0, 1, 1, $iYear)); |
|
160 | 160 | |
161 | 161 | if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
162 | 162 | else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
163 | 163 | |
164 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
164 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek - 1) * 604800; } |
|
165 | 165 | else { $iWeekInSeconds = 0; } |
166 | 166 | |
167 | 167 | if (date('N') > 2) { |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | if (preg_replace('/^([0-9]+)-[0-9]+-[0-9]+$/', '$1', $aDates[0]) != date('Y')) { |
181 | 181 | |
182 | 182 | $aDates[0] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', date('Y').'$1', $aDates[0]); |
183 | - $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y')+1).'$1', $aDates[1]); |
|
183 | + $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y') + 1).'$1', $aDates[1]); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | return $aDates; |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | $oDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $sDateTime); |
222 | 222 | $iTimeStamp = time() - $oDateTime->getTimestamp(); |
223 | 223 | |
224 | - if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; } |
|
225 | - if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; } |
|
226 | - if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; } |
|
227 | - if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } |
|
228 | - else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
224 | + if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp / 60).' '.$sMinutes.$sEndReturn; } |
|
225 | + if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp / 3600).' '.$sHours.$sEndReturn; } |
|
226 | + if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp / 86400).' '.$sDays.$sEndReturn; } |
|
227 | + if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp / 2592000).' '.$sMonths.$sEndReturn; } |
|
228 | + else { return $sStartReturn.' '.(int)($iTimeStamp / 31536000).' '.$sYears.$sEndReturn; } |
|
229 | 229 | } |
230 | 230 | } |
@@ -76,18 +76,7 @@ discard block |
||
76 | 76 | { |
77 | 77 | if ($sLanguage == 'fr') { |
78 | 78 | |
79 | - if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } |
|
80 | - else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } |
|
81 | - else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } |
|
82 | - else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } |
|
83 | - else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } |
|
84 | - else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } |
|
85 | - else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } |
|
86 | - else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } |
|
87 | - else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } |
|
88 | - else if ($sMonth == 10) { return 'Octobre'; } |
|
89 | - else if ($sMonth == 11) { return 'Novembre'; } |
|
90 | - else if ($sMonth == 12) { return 'Décembre'; } |
|
79 | + if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } else if ($sMonth == 10) { return 'Octobre'; } else if ($sMonth == 11) { return 'Novembre'; } else if ($sMonth == 12) { return 'Décembre'; } |
|
91 | 80 | } |
92 | 81 | } |
93 | 82 | |
@@ -103,13 +92,7 @@ discard block |
||
103 | 92 | { |
104 | 93 | if ($sLanguage == 'fr') { |
105 | 94 | |
106 | - if ($sDay == 0) { return 'dimanche'; } |
|
107 | - else if ($sDay == 1) { return 'lundi'; } |
|
108 | - else if ($sDay == 2) { return 'mardi'; } |
|
109 | - else if ($sDay == 3) { return 'mercredi'; } |
|
110 | - else if ($sDay == 4) { return 'jeudi'; } |
|
111 | - else if ($sDay == 5) { return 'vendredi'; } |
|
112 | - else if ($sDay == 6) { return 'samedi'; } |
|
95 | + if ($sDay == 0) { return 'dimanche'; } else if ($sDay == 1) { return 'lundi'; } else if ($sDay == 2) { return 'mardi'; } else if ($sDay == 3) { return 'mercredi'; } else if ($sDay == 4) { return 'jeudi'; } else if ($sDay == 5) { return 'vendredi'; } else if ($sDay == 6) { return 'samedi'; } |
|
113 | 96 | } |
114 | 97 | } |
115 | 98 | |
@@ -136,8 +119,7 @@ discard block |
||
136 | 119 | if ($iMonth == $aToday['mois']) { |
137 | 120 | |
138 | 121 | if ($iDay > $aToday['jour']) { $iYears--; } |
139 | - } |
|
140 | - else { |
|
122 | + } else { |
|
141 | 123 | |
142 | 124 | $iYears--; |
143 | 125 | } |
@@ -158,18 +140,15 @@ discard block |
||
158 | 140 | { |
159 | 141 | $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
160 | 142 | |
161 | - if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
|
162 | - else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
143 | + if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
163 | 144 | |
164 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
165 | - else { $iWeekInSeconds = 0; } |
|
145 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; } |
|
166 | 146 | |
167 | 147 | if (date('N') > 2) { |
168 | 148 | |
169 | 149 | $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift + 172800; |
170 | 150 | $iTimestampLastDay = $iTimestamp + 604800; |
171 | - } |
|
172 | - else { |
|
151 | + } else { |
|
173 | 152 | |
174 | 153 | $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift - 432000; |
175 | 154 | $iTimestampLastDay = $iTimestamp + 604800; |
@@ -224,7 +203,6 @@ discard block |
||
224 | 203 | if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; } |
225 | 204 | if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; } |
226 | 205 | if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; } |
227 | - if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } |
|
228 | - else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
206 | + if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
229 | 207 | } |
230 | 208 | } |
@@ -60,406 +60,406 @@ |
||
60 | 60 | */ |
61 | 61 | class Form |
62 | 62 | { |
63 | - /** |
|
64 | - * Elements of the form |
|
65 | - * |
|
66 | - * @access private |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - private $_aElement = array(); |
|
70 | - |
|
71 | - /** |
|
72 | - * Increment for form |
|
73 | - * |
|
74 | - * @access private |
|
75 | - * @var int |
|
76 | - */ |
|
77 | - private static $_iFormIncrement = 0; |
|
78 | - |
|
79 | - /** |
|
80 | - * number of form |
|
81 | - * |
|
82 | - * @access private |
|
83 | - * @var int |
|
84 | - */ |
|
85 | - private $_iFormNumber = 0; |
|
86 | - |
|
87 | - /** |
|
88 | - * Separator between fields of form |
|
89 | - * |
|
90 | - * @access private |
|
91 | - * @var string |
|
92 | - */ |
|
93 | - private $_sSeparator = '<br/>'; |
|
94 | - |
|
95 | - /** |
|
96 | - * The entity to save with the formular |
|
97 | - * |
|
98 | - * @access private |
|
99 | - * @var string |
|
100 | - */ |
|
101 | - private $_sSynchronizeEntity = null; |
|
102 | - |
|
103 | - /** |
|
104 | - * The id of entity |
|
105 | - * |
|
106 | - * @access private |
|
107 | - * @var int |
|
108 | - */ |
|
109 | - private $_iIdEntity = null; |
|
110 | - |
|
111 | - /** |
|
112 | - * The entity to save with the formular |
|
113 | - * |
|
114 | - * @access private |
|
115 | - * @var int |
|
116 | - */ |
|
117 | - private $_iIdEntityCreated = null; |
|
118 | - |
|
119 | - /** |
|
120 | - * constructor that it increment (static) for all use |
|
121 | - * |
|
122 | - * @access public |
|
123 | - */ |
|
124 | - public function __construct() |
|
125 | - { |
|
126 | - self::$_iFormIncrement++; |
|
127 | - $this->_iFormNumber = self::$_iFormIncrement; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * add an element in the form |
|
132 | - * |
|
133 | - * @access public |
|
134 | - * @param string $sName name |
|
135 | - * @param string|\Venus\lib\Form $mType type of field |
|
136 | - * @param string $sLabel label of field |
|
137 | - * @param mixed $mValue value of field |
|
138 | - * @parma mixed $mOptions options (for select) |
|
139 | - * @return \Venus\lib\Form |
|
140 | - */ |
|
141 | - public function add($sName, $mType, $sLabel = null, $mValue = null, $mOptions = null) |
|
142 | - { |
|
143 | - if ($mType instanceof Container) { |
|
144 | - |
|
145 | - $this->_aElement[$sName] = $mType; |
|
146 | - } else if ($mType === 'text' || $mType === 'submit' || $mType === 'password' || $mType === 'file' || $mType === 'tel' |
|
147 | - || $mType === 'url' || $mType === 'email' || $mType === 'search' || $mType === 'date' || $mType === 'time' |
|
148 | - || $mType === 'datetime' || $mType === 'month' || $mType === 'week' || $mType === 'number' || $mType === 'range' |
|
149 | - || $mType === 'color') { |
|
150 | - |
|
151 | - $this->_aElement[$sName] = new Input($sName, $mType, $sLabel, $mValue); |
|
152 | - } elseif ($mType === 'textarea') { |
|
153 | - |
|
154 | - $this->_aElement[$sName] = new Textarea($sName, $sLabel, $mValue); |
|
155 | - } else if ($mType === 'select') { |
|
156 | - |
|
157 | - $this->_aElement[$sName] = new Select($sName, $mOptions, $sLabel, $mValue); |
|
158 | - } else if ($mType === 'label') { |
|
159 | - |
|
160 | - $this->_aElement[$sName] = new Label($sName); |
|
161 | - } else if ($mType === 'list_checkbox') { |
|
162 | - |
|
163 | - $i = 0; |
|
164 | - |
|
165 | - $this->_aElement[$sName.'_'.$i++] = new Label($sLabel); |
|
166 | - |
|
167 | - foreach ($mValue as $mKey => $sValue) { |
|
168 | - |
|
169 | - $this->_aElement[$sName.'_'.$i++] = new Checkbox($sName, $sValue, $mKey, $mOptions); |
|
170 | - } |
|
171 | - } else if ($mType === 'checkbox') { |
|
172 | - |
|
173 | - $this->_aElement[$sName] = new Checkbox($sName, $sLabel, $mValue, $mOptions); |
|
174 | - } else if ($mType === 'radio') { |
|
175 | - |
|
176 | - $this->_aElement[$sName.rand(100000, 999999)] = new Radio($sName, $sLabel, $mValue, $mOptions); |
|
177 | - } else if ($mType === 'date') { |
|
178 | - |
|
179 | - $aDay = array(); |
|
180 | - |
|
181 | - for ($i = 1; $i <= 31; $i++) { |
|
182 | - |
|
183 | - if ($i < 10) { $aDay['0'.$i] = '0'.$i; } |
|
184 | - else { $aDay[$i] = $i; } |
|
185 | - } |
|
186 | - |
|
187 | - $this->_aElement[$sName.'_day'] = new Select($sName, $aDay); |
|
188 | - |
|
189 | - $aMonth = array( |
|
190 | - '01' => 'Jan', |
|
191 | - '02' => 'Feb', |
|
192 | - '03' => 'Mar', |
|
193 | - '04' => 'Apr', |
|
194 | - '05' => 'May', |
|
195 | - '06' => 'Jun', |
|
196 | - '07' => 'Jui', |
|
197 | - '08' => 'Aug', |
|
198 | - '09' => 'Sep', |
|
199 | - '10' => 'Oct', |
|
200 | - '11' => 'Nov', |
|
201 | - '12' => 'Dec', |
|
202 | - ); |
|
203 | - |
|
204 | - $this->_aElement[$sName.'_month'] = new Select($sName, $aMonth); |
|
205 | - |
|
206 | - $aYear = array(); |
|
207 | - |
|
208 | - for ($i = 1900; $i <= 2013; $i++) { |
|
209 | - |
|
210 | - $aYear[$i] = $i; |
|
211 | - } |
|
212 | - |
|
213 | - $this->_aElement[$sName.'_year'] = new Select($sName, $aMonth); |
|
214 | - } |
|
215 | - |
|
216 | - return $this; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * get id entity created by the formular |
|
221 | - * |
|
222 | - * @access public |
|
223 | - * @return int |
|
224 | - */ |
|
225 | - public function getIdEntityCreated() : int |
|
226 | - { |
|
227 | - return $this->_iIdEntityCreated; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * set id entity created by the formular |
|
232 | - * |
|
233 | - * @access public |
|
234 | - * @param int $iIdEntityCreated |
|
235 | - * @return Form |
|
236 | - */ |
|
237 | - public function setIdEntityCreated(int $iIdEntityCreated) : Form |
|
238 | - { |
|
239 | - $this->_iIdEntityCreated = $iIdEntityCreated; |
|
240 | - return $this; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * get form number |
|
245 | - * |
|
246 | - * @access public |
|
247 | - * @return int |
|
248 | - */ |
|
249 | - public function getFormNumber() : int |
|
250 | - { |
|
251 | - return $this->_iFormNumber; |
|
252 | - } |
|
63 | + /** |
|
64 | + * Elements of the form |
|
65 | + * |
|
66 | + * @access private |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + private $_aElement = array(); |
|
70 | + |
|
71 | + /** |
|
72 | + * Increment for form |
|
73 | + * |
|
74 | + * @access private |
|
75 | + * @var int |
|
76 | + */ |
|
77 | + private static $_iFormIncrement = 0; |
|
78 | + |
|
79 | + /** |
|
80 | + * number of form |
|
81 | + * |
|
82 | + * @access private |
|
83 | + * @var int |
|
84 | + */ |
|
85 | + private $_iFormNumber = 0; |
|
86 | + |
|
87 | + /** |
|
88 | + * Separator between fields of form |
|
89 | + * |
|
90 | + * @access private |
|
91 | + * @var string |
|
92 | + */ |
|
93 | + private $_sSeparator = '<br/>'; |
|
94 | + |
|
95 | + /** |
|
96 | + * The entity to save with the formular |
|
97 | + * |
|
98 | + * @access private |
|
99 | + * @var string |
|
100 | + */ |
|
101 | + private $_sSynchronizeEntity = null; |
|
102 | + |
|
103 | + /** |
|
104 | + * The id of entity |
|
105 | + * |
|
106 | + * @access private |
|
107 | + * @var int |
|
108 | + */ |
|
109 | + private $_iIdEntity = null; |
|
110 | + |
|
111 | + /** |
|
112 | + * The entity to save with the formular |
|
113 | + * |
|
114 | + * @access private |
|
115 | + * @var int |
|
116 | + */ |
|
117 | + private $_iIdEntityCreated = null; |
|
118 | + |
|
119 | + /** |
|
120 | + * constructor that it increment (static) for all use |
|
121 | + * |
|
122 | + * @access public |
|
123 | + */ |
|
124 | + public function __construct() |
|
125 | + { |
|
126 | + self::$_iFormIncrement++; |
|
127 | + $this->_iFormNumber = self::$_iFormIncrement; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * add an element in the form |
|
132 | + * |
|
133 | + * @access public |
|
134 | + * @param string $sName name |
|
135 | + * @param string|\Venus\lib\Form $mType type of field |
|
136 | + * @param string $sLabel label of field |
|
137 | + * @param mixed $mValue value of field |
|
138 | + * @parma mixed $mOptions options (for select) |
|
139 | + * @return \Venus\lib\Form |
|
140 | + */ |
|
141 | + public function add($sName, $mType, $sLabel = null, $mValue = null, $mOptions = null) |
|
142 | + { |
|
143 | + if ($mType instanceof Container) { |
|
144 | + |
|
145 | + $this->_aElement[$sName] = $mType; |
|
146 | + } else if ($mType === 'text' || $mType === 'submit' || $mType === 'password' || $mType === 'file' || $mType === 'tel' |
|
147 | + || $mType === 'url' || $mType === 'email' || $mType === 'search' || $mType === 'date' || $mType === 'time' |
|
148 | + || $mType === 'datetime' || $mType === 'month' || $mType === 'week' || $mType === 'number' || $mType === 'range' |
|
149 | + || $mType === 'color') { |
|
150 | + |
|
151 | + $this->_aElement[$sName] = new Input($sName, $mType, $sLabel, $mValue); |
|
152 | + } elseif ($mType === 'textarea') { |
|
153 | + |
|
154 | + $this->_aElement[$sName] = new Textarea($sName, $sLabel, $mValue); |
|
155 | + } else if ($mType === 'select') { |
|
156 | + |
|
157 | + $this->_aElement[$sName] = new Select($sName, $mOptions, $sLabel, $mValue); |
|
158 | + } else if ($mType === 'label') { |
|
159 | + |
|
160 | + $this->_aElement[$sName] = new Label($sName); |
|
161 | + } else if ($mType === 'list_checkbox') { |
|
162 | + |
|
163 | + $i = 0; |
|
164 | + |
|
165 | + $this->_aElement[$sName.'_'.$i++] = new Label($sLabel); |
|
166 | + |
|
167 | + foreach ($mValue as $mKey => $sValue) { |
|
168 | + |
|
169 | + $this->_aElement[$sName.'_'.$i++] = new Checkbox($sName, $sValue, $mKey, $mOptions); |
|
170 | + } |
|
171 | + } else if ($mType === 'checkbox') { |
|
172 | + |
|
173 | + $this->_aElement[$sName] = new Checkbox($sName, $sLabel, $mValue, $mOptions); |
|
174 | + } else if ($mType === 'radio') { |
|
175 | + |
|
176 | + $this->_aElement[$sName.rand(100000, 999999)] = new Radio($sName, $sLabel, $mValue, $mOptions); |
|
177 | + } else if ($mType === 'date') { |
|
178 | + |
|
179 | + $aDay = array(); |
|
180 | + |
|
181 | + for ($i = 1; $i <= 31; $i++) { |
|
182 | + |
|
183 | + if ($i < 10) { $aDay['0'.$i] = '0'.$i; } |
|
184 | + else { $aDay[$i] = $i; } |
|
185 | + } |
|
186 | + |
|
187 | + $this->_aElement[$sName.'_day'] = new Select($sName, $aDay); |
|
188 | + |
|
189 | + $aMonth = array( |
|
190 | + '01' => 'Jan', |
|
191 | + '02' => 'Feb', |
|
192 | + '03' => 'Mar', |
|
193 | + '04' => 'Apr', |
|
194 | + '05' => 'May', |
|
195 | + '06' => 'Jun', |
|
196 | + '07' => 'Jui', |
|
197 | + '08' => 'Aug', |
|
198 | + '09' => 'Sep', |
|
199 | + '10' => 'Oct', |
|
200 | + '11' => 'Nov', |
|
201 | + '12' => 'Dec', |
|
202 | + ); |
|
203 | + |
|
204 | + $this->_aElement[$sName.'_month'] = new Select($sName, $aMonth); |
|
205 | + |
|
206 | + $aYear = array(); |
|
207 | + |
|
208 | + for ($i = 1900; $i <= 2013; $i++) { |
|
209 | + |
|
210 | + $aYear[$i] = $i; |
|
211 | + } |
|
212 | + |
|
213 | + $this->_aElement[$sName.'_year'] = new Select($sName, $aMonth); |
|
214 | + } |
|
215 | + |
|
216 | + return $this; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * get id entity created by the formular |
|
221 | + * |
|
222 | + * @access public |
|
223 | + * @return int |
|
224 | + */ |
|
225 | + public function getIdEntityCreated() : int |
|
226 | + { |
|
227 | + return $this->_iIdEntityCreated; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * set id entity created by the formular |
|
232 | + * |
|
233 | + * @access public |
|
234 | + * @param int $iIdEntityCreated |
|
235 | + * @return Form |
|
236 | + */ |
|
237 | + public function setIdEntityCreated(int $iIdEntityCreated) : Form |
|
238 | + { |
|
239 | + $this->_iIdEntityCreated = $iIdEntityCreated; |
|
240 | + return $this; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * get form number |
|
245 | + * |
|
246 | + * @access public |
|
247 | + * @return int |
|
248 | + */ |
|
249 | + public function getFormNumber() : int |
|
250 | + { |
|
251 | + return $this->_iFormNumber; |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * set id entity created by the formular |
|
256 | - * |
|
257 | - * @access public |
|
258 | - * @param int $iFormNumber |
|
259 | - * @return Form |
|
260 | - */ |
|
261 | - public function setFormNumber(int $iFormNumber) : Form |
|
262 | - { |
|
263 | - $this->_iFormNumber = $iFormNumber; |
|
264 | - return $this; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * get global form |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @return \Venus\lib\Form\Container |
|
272 | - */ |
|
273 | - public function getForm() |
|
274 | - { |
|
275 | - $oForm = $this->getFormInObject(); |
|
276 | - |
|
277 | - $sFormContent = $oForm->start; |
|
278 | - |
|
279 | - foreach ($oForm->form as $sValue) { |
|
280 | - |
|
281 | - $sFormContent .= $sValue.$this->_sSeparator; |
|
282 | - } |
|
283 | - |
|
284 | - $sFormContent .= $oForm->end; |
|
285 | - |
|
286 | - $oContainer = new Container; |
|
287 | - $oContainer->setView($sFormContent) |
|
288 | - ->setForm($this); |
|
289 | - |
|
290 | - return $oContainer; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * get global object form |
|
296 | - * |
|
297 | - * @access public |
|
298 | - * @return \stdClass |
|
299 | - */ |
|
300 | - public function getFormInObject() |
|
301 | - { |
|
302 | - if ($this->_iIdEntity > 0 && $this->_sSynchronizeEntity !== null && count($_POST) < 1) { |
|
303 | - |
|
304 | - $sModelName = str_replace('Entity', 'Model', $this->_sSynchronizeEntity); |
|
305 | - $oModel = new $sModelName; |
|
306 | - |
|
307 | - $oEntity = new $this->_sSynchronizeEntity; |
|
308 | - $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
309 | - $sMethodName = 'findOneBy'.$sPrimaryKey; |
|
310 | - $oCompleteEntity = call_user_func_array(array(&$oModel, $sMethodName), array($this->_iIdEntity)); |
|
311 | - |
|
312 | - if (is_object($oCompleteEntity)) { |
|
313 | - |
|
314 | - foreach ($this->_aElement as $sKey => $sValue) { |
|
315 | - |
|
316 | - if ($sValue instanceof \Venus\lib\Form\Radio) { |
|
317 | - |
|
318 | - $sExKey = $sKey; |
|
319 | - $sKey = substr($sKey, 0, -6); |
|
320 | - } |
|
321 | - |
|
322 | - if ($sValue instanceof Form) { |
|
323 | - |
|
324 | - ; |
|
325 | - } else { |
|
326 | - |
|
327 | - $sMethodNameInEntity = 'get_'.$sKey; |
|
328 | - $mValue = $oCompleteEntity->$sMethodNameInEntity(); |
|
329 | - |
|
330 | - if ($sValue instanceof \Venus\lib\Form\Radio && method_exists($this->_aElement[$sExKey], 'setValueChecked')) { |
|
331 | - |
|
332 | - $this->_aElement[$sExKey]->setValueChecked($mValue); |
|
333 | - } else if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) { |
|
334 | - |
|
335 | - $this->_aElement[$sKey]->setValue($mValue); |
|
336 | - } |
|
337 | - } |
|
338 | - } |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - $oForm = new \StdClass(); |
|
343 | - $oForm->start = '<form name="form'.$this->_iFormNumber.'" method="post"><input type="hidden" value="1" name="validform'.$this->_iFormNumber.'">'; |
|
344 | - $oForm->form = array(); |
|
345 | - |
|
346 | - foreach ($this->_aElement as $sKey => $sValue) { |
|
347 | - |
|
348 | - if ($sValue instanceof Container) { |
|
349 | - |
|
350 | - $oForm->form[$sKey] = $sValue; |
|
351 | - } else { |
|
352 | - |
|
353 | - $oForm->form[$sKey] = $sValue->fetch(); |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - $oForm->end = '</form>'; |
|
358 | - |
|
359 | - return $oForm; |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * get an element of formular |
|
364 | - * |
|
365 | - * @access public |
|
366 | - * @param string $sName name |
|
367 | - * @return object |
|
368 | - */ |
|
369 | - public function get($sName) |
|
370 | - { |
|
371 | - return $this->_aElement[$sName]; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * get the form separator |
|
376 | - * |
|
377 | - * @access public |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function getSeparator() |
|
381 | - { |
|
382 | - return $this->_sSeparator; |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * set the form separator |
|
387 | - * |
|
388 | - * @access public |
|
389 | - * @param string $sSeparator separator between the fields |
|
390 | - * @return \Venus\lib\Form |
|
391 | - */ |
|
392 | - public function setSeparator($sSeparator) |
|
393 | - { |
|
394 | - $this->_sSeparator = $sSeparator; |
|
395 | - return $this; |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * set the entity to synchronize with the formular |
|
400 | - * |
|
401 | - * @access public |
|
402 | - * @param $sSynchronizeEntity |
|
403 | - * @param int $iId id of the primary key |
|
404 | - * @return Form |
|
405 | - * @internal param string $sSeparator separator between the fields |
|
406 | - */ |
|
407 | - public function synchronizeEntity($sSynchronizeEntity, $iId = null) |
|
408 | - { |
|
409 | - if ($iId !== null) { $this->_iIdEntity = $iId; } |
|
410 | - |
|
411 | - $this->_sSynchronizeEntity = $sSynchronizeEntity; |
|
412 | - return $this; |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * add constraint |
|
417 | - * |
|
418 | - * @access public |
|
419 | - * @param string $sName field name |
|
420 | - * @param object $oConstraint constraint on the field |
|
421 | - * @return \Venus\lib\Form |
|
422 | - */ |
|
423 | - public function addConstraint($sName, $oConstraint) |
|
424 | - { |
|
425 | - if ($this->_aElement[$sName] instanceof Input || $this->_aElement[$sName] instanceof Textarea) { |
|
426 | - |
|
427 | - $this->_aElement[$sName]->setConstraint($oConstraint); |
|
428 | - } |
|
429 | - |
|
430 | - return $this; |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * get all elements |
|
435 | - * |
|
436 | - * @access public |
|
437 | - * @return array |
|
438 | - */ |
|
439 | - public function getElement() { |
|
440 | - |
|
441 | - return $this->_aElement; |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * get all elements |
|
446 | - * |
|
447 | - * @access public |
|
448 | - * @return int |
|
449 | - */ |
|
450 | - public function getIdEntity() { |
|
451 | - |
|
452 | - return $this->_iIdEntity; |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * get all elements |
|
457 | - * |
|
458 | - * @access public |
|
459 | - * @return string |
|
460 | - */ |
|
461 | - public function getSynchronizeEntity() { |
|
462 | - |
|
463 | - return $this->_sSynchronizeEntity; |
|
464 | - } |
|
254 | + /** |
|
255 | + * set id entity created by the formular |
|
256 | + * |
|
257 | + * @access public |
|
258 | + * @param int $iFormNumber |
|
259 | + * @return Form |
|
260 | + */ |
|
261 | + public function setFormNumber(int $iFormNumber) : Form |
|
262 | + { |
|
263 | + $this->_iFormNumber = $iFormNumber; |
|
264 | + return $this; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * get global form |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @return \Venus\lib\Form\Container |
|
272 | + */ |
|
273 | + public function getForm() |
|
274 | + { |
|
275 | + $oForm = $this->getFormInObject(); |
|
276 | + |
|
277 | + $sFormContent = $oForm->start; |
|
278 | + |
|
279 | + foreach ($oForm->form as $sValue) { |
|
280 | + |
|
281 | + $sFormContent .= $sValue.$this->_sSeparator; |
|
282 | + } |
|
283 | + |
|
284 | + $sFormContent .= $oForm->end; |
|
285 | + |
|
286 | + $oContainer = new Container; |
|
287 | + $oContainer->setView($sFormContent) |
|
288 | + ->setForm($this); |
|
289 | + |
|
290 | + return $oContainer; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * get global object form |
|
296 | + * |
|
297 | + * @access public |
|
298 | + * @return \stdClass |
|
299 | + */ |
|
300 | + public function getFormInObject() |
|
301 | + { |
|
302 | + if ($this->_iIdEntity > 0 && $this->_sSynchronizeEntity !== null && count($_POST) < 1) { |
|
303 | + |
|
304 | + $sModelName = str_replace('Entity', 'Model', $this->_sSynchronizeEntity); |
|
305 | + $oModel = new $sModelName; |
|
306 | + |
|
307 | + $oEntity = new $this->_sSynchronizeEntity; |
|
308 | + $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
309 | + $sMethodName = 'findOneBy'.$sPrimaryKey; |
|
310 | + $oCompleteEntity = call_user_func_array(array(&$oModel, $sMethodName), array($this->_iIdEntity)); |
|
311 | + |
|
312 | + if (is_object($oCompleteEntity)) { |
|
313 | + |
|
314 | + foreach ($this->_aElement as $sKey => $sValue) { |
|
315 | + |
|
316 | + if ($sValue instanceof \Venus\lib\Form\Radio) { |
|
317 | + |
|
318 | + $sExKey = $sKey; |
|
319 | + $sKey = substr($sKey, 0, -6); |
|
320 | + } |
|
321 | + |
|
322 | + if ($sValue instanceof Form) { |
|
323 | + |
|
324 | + ; |
|
325 | + } else { |
|
326 | + |
|
327 | + $sMethodNameInEntity = 'get_'.$sKey; |
|
328 | + $mValue = $oCompleteEntity->$sMethodNameInEntity(); |
|
329 | + |
|
330 | + if ($sValue instanceof \Venus\lib\Form\Radio && method_exists($this->_aElement[$sExKey], 'setValueChecked')) { |
|
331 | + |
|
332 | + $this->_aElement[$sExKey]->setValueChecked($mValue); |
|
333 | + } else if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) { |
|
334 | + |
|
335 | + $this->_aElement[$sKey]->setValue($mValue); |
|
336 | + } |
|
337 | + } |
|
338 | + } |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + $oForm = new \StdClass(); |
|
343 | + $oForm->start = '<form name="form'.$this->_iFormNumber.'" method="post"><input type="hidden" value="1" name="validform'.$this->_iFormNumber.'">'; |
|
344 | + $oForm->form = array(); |
|
345 | + |
|
346 | + foreach ($this->_aElement as $sKey => $sValue) { |
|
347 | + |
|
348 | + if ($sValue instanceof Container) { |
|
349 | + |
|
350 | + $oForm->form[$sKey] = $sValue; |
|
351 | + } else { |
|
352 | + |
|
353 | + $oForm->form[$sKey] = $sValue->fetch(); |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + $oForm->end = '</form>'; |
|
358 | + |
|
359 | + return $oForm; |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * get an element of formular |
|
364 | + * |
|
365 | + * @access public |
|
366 | + * @param string $sName name |
|
367 | + * @return object |
|
368 | + */ |
|
369 | + public function get($sName) |
|
370 | + { |
|
371 | + return $this->_aElement[$sName]; |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * get the form separator |
|
376 | + * |
|
377 | + * @access public |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function getSeparator() |
|
381 | + { |
|
382 | + return $this->_sSeparator; |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * set the form separator |
|
387 | + * |
|
388 | + * @access public |
|
389 | + * @param string $sSeparator separator between the fields |
|
390 | + * @return \Venus\lib\Form |
|
391 | + */ |
|
392 | + public function setSeparator($sSeparator) |
|
393 | + { |
|
394 | + $this->_sSeparator = $sSeparator; |
|
395 | + return $this; |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * set the entity to synchronize with the formular |
|
400 | + * |
|
401 | + * @access public |
|
402 | + * @param $sSynchronizeEntity |
|
403 | + * @param int $iId id of the primary key |
|
404 | + * @return Form |
|
405 | + * @internal param string $sSeparator separator between the fields |
|
406 | + */ |
|
407 | + public function synchronizeEntity($sSynchronizeEntity, $iId = null) |
|
408 | + { |
|
409 | + if ($iId !== null) { $this->_iIdEntity = $iId; } |
|
410 | + |
|
411 | + $this->_sSynchronizeEntity = $sSynchronizeEntity; |
|
412 | + return $this; |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * add constraint |
|
417 | + * |
|
418 | + * @access public |
|
419 | + * @param string $sName field name |
|
420 | + * @param object $oConstraint constraint on the field |
|
421 | + * @return \Venus\lib\Form |
|
422 | + */ |
|
423 | + public function addConstraint($sName, $oConstraint) |
|
424 | + { |
|
425 | + if ($this->_aElement[$sName] instanceof Input || $this->_aElement[$sName] instanceof Textarea) { |
|
426 | + |
|
427 | + $this->_aElement[$sName]->setConstraint($oConstraint); |
|
428 | + } |
|
429 | + |
|
430 | + return $this; |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * get all elements |
|
435 | + * |
|
436 | + * @access public |
|
437 | + * @return array |
|
438 | + */ |
|
439 | + public function getElement() { |
|
440 | + |
|
441 | + return $this->_aElement; |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * get all elements |
|
446 | + * |
|
447 | + * @access public |
|
448 | + * @return int |
|
449 | + */ |
|
450 | + public function getIdEntity() { |
|
451 | + |
|
452 | + return $this->_iIdEntity; |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * get all elements |
|
457 | + * |
|
458 | + * @access public |
|
459 | + * @return string |
|
460 | + */ |
|
461 | + public function getSynchronizeEntity() { |
|
462 | + |
|
463 | + return $this->_sSynchronizeEntity; |
|
464 | + } |
|
465 | 465 | } |
@@ -180,8 +180,7 @@ |
||
180 | 180 | |
181 | 181 | for ($i = 1; $i <= 31; $i++) { |
182 | 182 | |
183 | - if ($i < 10) { $aDay['0'.$i] = '0'.$i; } |
|
184 | - else { $aDay[$i] = $i; } |
|
183 | + if ($i < 10) { $aDay['0'.$i] = '0'.$i; } else { $aDay[$i] = $i; } |
|
185 | 184 | } |
186 | 185 | |
187 | 186 | $this->_aElement[$sName.'_day'] = new Select($sName, $aDay); |
@@ -30,69 +30,69 @@ |
||
30 | 30 | */ |
31 | 31 | class Mock implements CacheInterface |
32 | 32 | { |
33 | - /** |
|
34 | - * get a value |
|
35 | - * |
|
36 | - * @access public |
|
37 | - * @param string $sName name of the session |
|
38 | - * @param int $iFlags flags |
|
39 | - * @param int $iTimeout expiration of cache |
|
40 | - * @return boolean |
|
41 | - */ |
|
42 | - public function get(string $sName, int&$iFlags = null, int $iTimeout = 0) |
|
43 | - { |
|
44 | - return false; |
|
45 | - } |
|
33 | + /** |
|
34 | + * get a value |
|
35 | + * |
|
36 | + * @access public |
|
37 | + * @param string $sName name of the session |
|
38 | + * @param int $iFlags flags |
|
39 | + * @param int $iTimeout expiration of cache |
|
40 | + * @return boolean |
|
41 | + */ |
|
42 | + public function get(string $sName, int&$iFlags = null, int $iTimeout = 0) |
|
43 | + { |
|
44 | + return false; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * set a value |
|
49 | - * |
|
50 | - * @access public |
|
51 | - * @param string $sName name of the session |
|
52 | - * @param mixed $mValue value of this sesion var |
|
53 | - * @param int $iFlag unused |
|
54 | - * @param int $iExpire expiration of cache |
|
55 | - * @return boolean |
|
56 | - */ |
|
57 | - public function set(string $sName, $mValue, int $iFlag = 0, int $iExpire = false) |
|
58 | - { |
|
59 | - return true; |
|
60 | - } |
|
47 | + /** |
|
48 | + * set a value |
|
49 | + * |
|
50 | + * @access public |
|
51 | + * @param string $sName name of the session |
|
52 | + * @param mixed $mValue value of this sesion var |
|
53 | + * @param int $iFlag unused |
|
54 | + * @param int $iExpire expiration of cache |
|
55 | + * @return boolean |
|
56 | + */ |
|
57 | + public function set(string $sName, $mValue, int $iFlag = 0, int $iExpire = false) |
|
58 | + { |
|
59 | + return true; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * flush the cache |
|
64 | - * |
|
65 | - * @access public |
|
66 | - * @return boolean |
|
67 | - */ |
|
68 | - public function flush() |
|
69 | - { |
|
70 | - return false; |
|
71 | - } |
|
62 | + /** |
|
63 | + * flush the cache |
|
64 | + * |
|
65 | + * @access public |
|
66 | + * @return boolean |
|
67 | + */ |
|
68 | + public function flush() |
|
69 | + { |
|
70 | + return false; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * delete a value |
|
75 | - * |
|
76 | - * @access public |
|
77 | - * @param string $sName name of the session |
|
78 | - * @return boolean |
|
79 | - */ |
|
80 | - public function delete(string $sName) |
|
81 | - { |
|
82 | - return false; |
|
83 | - } |
|
73 | + /** |
|
74 | + * delete a value |
|
75 | + * |
|
76 | + * @access public |
|
77 | + * @param string $sName name of the session |
|
78 | + * @return boolean |
|
79 | + */ |
|
80 | + public function delete(string $sName) |
|
81 | + { |
|
82 | + return false; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * add |
|
87 | - * |
|
88 | - * @access public |
|
89 | - * @param string $sName name of the session |
|
90 | - * @param mixed $mValue value of this sesion var |
|
91 | - * @param int $iExpire expiration of cache |
|
92 | - * @return boolean |
|
93 | - */ |
|
94 | - public function add($sName, $mValue, $iExpire = false) |
|
95 | - { |
|
96 | - return true; |
|
97 | - } |
|
85 | + /** |
|
86 | + * add |
|
87 | + * |
|
88 | + * @access public |
|
89 | + * @param string $sName name of the session |
|
90 | + * @param mixed $mValue value of this sesion var |
|
91 | + * @param int $iExpire expiration of cache |
|
92 | + * @return boolean |
|
93 | + */ |
|
94 | + public function add($sName, $mValue, $iExpire = false) |
|
95 | + { |
|
96 | + return true; |
|
97 | + } |
|
98 | 98 | } |
@@ -30,125 +30,125 @@ |
||
30 | 30 | */ |
31 | 31 | class File implements CacheInterface |
32 | 32 | { |
33 | - /** |
|
34 | - * var containe this folder of cache |
|
35 | - * |
|
36 | - * @access private |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $_sFolder = ''; |
|
40 | - |
|
41 | - /** |
|
42 | - * constructor |
|
43 | - * |
|
44 | - * @access public |
|
45 | - */ |
|
46 | - public function __construct() |
|
47 | - { |
|
48 | - $this->_sFolder = str_replace('bundles'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Cache', CACHE_DIR, __DIR__).DIRECTORY_SEPARATOR; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * set a value |
|
53 | - * |
|
54 | - * @access public |
|
55 | - * @param string $sName name of the session |
|
56 | - * @param mixed $mValue value of this sesion var |
|
57 | - * @param int $iFlag flags |
|
58 | - * @param int $iExpire expiration of cache |
|
59 | - * @return \Venus\lib\Cache\File |
|
60 | - */ |
|
61 | - public function set(string $sName, $mValue, int $iFlag, int $iExpire) |
|
62 | - { |
|
63 | - file_put_contents($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac', serialize($mValue)); |
|
64 | - return $this; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * get a value |
|
69 | - * |
|
70 | - * @access public |
|
71 | - * @param string $sName name of the session |
|
72 | - * @param int $iFlags flags |
|
73 | - * @param int $iTimeout expiration of cache |
|
74 | - * @return mixed |
|
75 | - */ |
|
76 | - public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
|
77 | - { |
|
78 | - if ($iTimeout > 0 && file_exists($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac') |
|
79 | - && time() - filemtime($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac') > $iTimeout) { |
|
80 | - |
|
81 | - unlink($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac'); |
|
82 | - } |
|
83 | - |
|
84 | - if (file_exists($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac')) { |
|
85 | - |
|
86 | - return unserialize(file_get_contents($this->_sFolder . $this->_getSubDirectory($sName) . md5($sName) . '.fil.cac')); |
|
87 | - } else { |
|
88 | - |
|
89 | - return false; |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * delete a value |
|
95 | - * |
|
96 | - * @access public |
|
97 | - * @param string $sName name of the session |
|
98 | - * @return mixed |
|
99 | - */ |
|
100 | - public function delete(string $sName) |
|
101 | - { |
|
102 | - return unlink($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac'); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * flush the cache |
|
107 | - * |
|
108 | - * @access public |
|
109 | - * @param string $sName name of the session |
|
110 | - * @return mixed |
|
111 | - */ |
|
112 | - public function flush() |
|
113 | - { |
|
114 | - $this->_removeDirectory($this->_sFolder); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * |
|
119 | - * |
|
120 | - * @access public |
|
121 | - * @param string $sName name of the session |
|
122 | - * @return mixed |
|
123 | - */ |
|
124 | - private function _getSubDirectory($sName) |
|
125 | - { |
|
126 | - if (!file_exists($this->_sFolder.substr(md5($sName), 0, 2).DIRECTORY_SEPARATOR.substr(md5($sName), 2, 2))) { |
|
127 | - |
|
128 | - mkdir($this->_sFolder.substr(md5($sName), 0, 2).DIRECTORY_SEPARATOR.substr(md5($sName), 2, 2), 0777, true); |
|
129 | - } |
|
130 | - |
|
131 | - return substr(md5($sName), 0, 2).DIRECTORY_SEPARATOR.substr(md5($sName), 2, 2).DIRECTORY_SEPARATOR; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * remove a directory recursivly |
|
136 | - * |
|
137 | - * @access private |
|
138 | - * @param string $sName nom du répertoire |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - private function _removeDirectory($sName) |
|
142 | - { |
|
143 | - if ($rDirectory = opendir($sName)) { |
|
144 | - |
|
145 | - while (($sFile = readdir($rDirectory)) !== false) { |
|
146 | - |
|
147 | - if ($sFile > '0' && filetype($sName.$sFile) == "file") { unlink($sName.$sFile); } elseif ($sFile > '0' && filetype($sName.$sFile) == "dir") { remove_dir($sName.$sFile."\\"); } |
|
148 | - } |
|
149 | - |
|
150 | - closedir($rDirectory); |
|
151 | - rmdir($sName); |
|
152 | - } |
|
153 | - } |
|
33 | + /** |
|
34 | + * var containe this folder of cache |
|
35 | + * |
|
36 | + * @access private |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $_sFolder = ''; |
|
40 | + |
|
41 | + /** |
|
42 | + * constructor |
|
43 | + * |
|
44 | + * @access public |
|
45 | + */ |
|
46 | + public function __construct() |
|
47 | + { |
|
48 | + $this->_sFolder = str_replace('bundles'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Cache', CACHE_DIR, __DIR__).DIRECTORY_SEPARATOR; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * set a value |
|
53 | + * |
|
54 | + * @access public |
|
55 | + * @param string $sName name of the session |
|
56 | + * @param mixed $mValue value of this sesion var |
|
57 | + * @param int $iFlag flags |
|
58 | + * @param int $iExpire expiration of cache |
|
59 | + * @return \Venus\lib\Cache\File |
|
60 | + */ |
|
61 | + public function set(string $sName, $mValue, int $iFlag, int $iExpire) |
|
62 | + { |
|
63 | + file_put_contents($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac', serialize($mValue)); |
|
64 | + return $this; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * get a value |
|
69 | + * |
|
70 | + * @access public |
|
71 | + * @param string $sName name of the session |
|
72 | + * @param int $iFlags flags |
|
73 | + * @param int $iTimeout expiration of cache |
|
74 | + * @return mixed |
|
75 | + */ |
|
76 | + public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
|
77 | + { |
|
78 | + if ($iTimeout > 0 && file_exists($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac') |
|
79 | + && time() - filemtime($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac') > $iTimeout) { |
|
80 | + |
|
81 | + unlink($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac'); |
|
82 | + } |
|
83 | + |
|
84 | + if (file_exists($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac')) { |
|
85 | + |
|
86 | + return unserialize(file_get_contents($this->_sFolder . $this->_getSubDirectory($sName) . md5($sName) . '.fil.cac')); |
|
87 | + } else { |
|
88 | + |
|
89 | + return false; |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * delete a value |
|
95 | + * |
|
96 | + * @access public |
|
97 | + * @param string $sName name of the session |
|
98 | + * @return mixed |
|
99 | + */ |
|
100 | + public function delete(string $sName) |
|
101 | + { |
|
102 | + return unlink($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac'); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * flush the cache |
|
107 | + * |
|
108 | + * @access public |
|
109 | + * @param string $sName name of the session |
|
110 | + * @return mixed |
|
111 | + */ |
|
112 | + public function flush() |
|
113 | + { |
|
114 | + $this->_removeDirectory($this->_sFolder); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * |
|
119 | + * |
|
120 | + * @access public |
|
121 | + * @param string $sName name of the session |
|
122 | + * @return mixed |
|
123 | + */ |
|
124 | + private function _getSubDirectory($sName) |
|
125 | + { |
|
126 | + if (!file_exists($this->_sFolder.substr(md5($sName), 0, 2).DIRECTORY_SEPARATOR.substr(md5($sName), 2, 2))) { |
|
127 | + |
|
128 | + mkdir($this->_sFolder.substr(md5($sName), 0, 2).DIRECTORY_SEPARATOR.substr(md5($sName), 2, 2), 0777, true); |
|
129 | + } |
|
130 | + |
|
131 | + return substr(md5($sName), 0, 2).DIRECTORY_SEPARATOR.substr(md5($sName), 2, 2).DIRECTORY_SEPARATOR; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * remove a directory recursivly |
|
136 | + * |
|
137 | + * @access private |
|
138 | + * @param string $sName nom du répertoire |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + private function _removeDirectory($sName) |
|
142 | + { |
|
143 | + if ($rDirectory = opendir($sName)) { |
|
144 | + |
|
145 | + while (($sFile = readdir($rDirectory)) !== false) { |
|
146 | + |
|
147 | + if ($sFile > '0' && filetype($sName.$sFile) == "file") { unlink($sName.$sFile); } elseif ($sFile > '0' && filetype($sName.$sFile) == "dir") { remove_dir($sName.$sFile."\\"); } |
|
148 | + } |
|
149 | + |
|
150 | + closedir($rDirectory); |
|
151 | + rmdir($sName); |
|
152 | + } |
|
153 | + } |
|
154 | 154 | } |
@@ -34,418 +34,418 @@ |
||
34 | 34 | */ |
35 | 35 | class Debug extends AbstractLogger |
36 | 36 | { |
37 | - /** |
|
38 | - * variable to activate or not the debug |
|
39 | - * @var boolean |
|
40 | - */ |
|
41 | - private static $_bActivateDebug = false; |
|
42 | - |
|
43 | - /** |
|
44 | - * variable to activate or not the error |
|
45 | - * @var boolean |
|
46 | - */ |
|
47 | - private static $_bActivateError = false; |
|
48 | - |
|
49 | - /** |
|
50 | - * variable to activate or not the exception |
|
51 | - * @var boolean |
|
52 | - */ |
|
53 | - private static $_bActivateException = false; |
|
54 | - |
|
55 | - /** |
|
56 | - * variable to activate or not the debug |
|
57 | - * @var boolean |
|
58 | - */ |
|
59 | - private static $_sFileLog = null; |
|
60 | - |
|
61 | - /** |
|
62 | - * first or not activation |
|
63 | - * @var boolean |
|
64 | - */ |
|
65 | - private static $_bFirstActivation = true; |
|
66 | - |
|
67 | - /** |
|
68 | - * kind of report log |
|
69 | - * @var string error_log|screen|all |
|
70 | - */ |
|
71 | - private static $_sKindOfReportLog = 'error_log'; |
|
72 | - |
|
73 | - /** |
|
74 | - * instance of logger |
|
75 | - * @var \Venus\lib\Debug |
|
76 | - */ |
|
77 | - private static $_oInstance; |
|
37 | + /** |
|
38 | + * variable to activate or not the debug |
|
39 | + * @var boolean |
|
40 | + */ |
|
41 | + private static $_bActivateDebug = false; |
|
42 | + |
|
43 | + /** |
|
44 | + * variable to activate or not the error |
|
45 | + * @var boolean |
|
46 | + */ |
|
47 | + private static $_bActivateError = false; |
|
48 | + |
|
49 | + /** |
|
50 | + * variable to activate or not the exception |
|
51 | + * @var boolean |
|
52 | + */ |
|
53 | + private static $_bActivateException = false; |
|
54 | + |
|
55 | + /** |
|
56 | + * variable to activate or not the debug |
|
57 | + * @var boolean |
|
58 | + */ |
|
59 | + private static $_sFileLog = null; |
|
60 | + |
|
61 | + /** |
|
62 | + * first or not activation |
|
63 | + * @var boolean |
|
64 | + */ |
|
65 | + private static $_bFirstActivation = true; |
|
66 | + |
|
67 | + /** |
|
68 | + * kind of report log |
|
69 | + * @var string error_log|screen|all |
|
70 | + */ |
|
71 | + private static $_sKindOfReportLog = 'error_log'; |
|
72 | + |
|
73 | + /** |
|
74 | + * instance of logger |
|
75 | + * @var \Venus\lib\Debug |
|
76 | + */ |
|
77 | + private static $_oInstance; |
|
78 | 78 | |
79 | - /** |
|
80 | - * Send back the isntance or create it |
|
81 | - * |
|
82 | - * @access public |
|
83 | - */ |
|
84 | - public static function getInstance() : Debug |
|
85 | - { |
|
86 | - if (!(self::$_oInstance instanceof self)) { self::$_oInstance = new self(); } |
|
79 | + /** |
|
80 | + * Send back the isntance or create it |
|
81 | + * |
|
82 | + * @access public |
|
83 | + */ |
|
84 | + public static function getInstance() : Debug |
|
85 | + { |
|
86 | + if (!(self::$_oInstance instanceof self)) { self::$_oInstance = new self(); } |
|
87 | 87 | |
88 | - return self::$_oInstance; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * activate debug |
|
93 | - * |
|
94 | - * @access public |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - public static function activateDebug() |
|
98 | - { |
|
99 | - if (self::$_bFirstActivation === true) { |
|
100 | - |
|
101 | - self::_setFileNameInErrorFile(); |
|
102 | - self::$_bFirstActivation = false; |
|
103 | - } |
|
104 | - |
|
105 | - self::_initLogFile(); |
|
106 | - self::$_bActivateDebug = true; |
|
107 | - self::activateError(E_ALL); |
|
108 | - self::activateException(E_ALL); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * activate debug |
|
113 | - * |
|
114 | - * @access public |
|
115 | - * @return void |
|
116 | - */ |
|
117 | - public static function deactivateDebug() |
|
118 | - { |
|
119 | - self::$_bActivateDebug = false; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * check if debug is activate or not |
|
124 | - * |
|
125 | - * @access public |
|
126 | - * @return boolean |
|
127 | - */ |
|
128 | - public static function isDebug() : bool |
|
129 | - { |
|
130 | - return self::$_bActivateDebug; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * activate error reporting |
|
135 | - * |
|
136 | - * @access public |
|
137 | - * @param int $iLevel level of error |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - public static function activateError($iLevel) |
|
141 | - { |
|
142 | - if (self::$_bFirstActivation === true) { |
|
143 | - |
|
144 | - self::_setFileNameInErrorFile(); |
|
145 | - self::$_bFirstActivation = false; |
|
146 | - } |
|
147 | - |
|
148 | - self::_initLogFile(); |
|
149 | - self::$_bActivateError = true; |
|
150 | - |
|
151 | - error_reporting($iLevel); |
|
152 | - |
|
153 | - set_error_handler(function ($iErrNo, $sErrStr, $sErrFile, $iErrLine) |
|
154 | - { |
|
155 | - $aContext = array('file' => $sErrFile, 'line' => $iErrLine); |
|
156 | - |
|
157 | - $sType = self::getTranslateErrorCode($iErrNo); |
|
158 | - |
|
159 | - self::getInstance()->$sType($sErrStr, $aContext); |
|
160 | - |
|
161 | - return true; |
|
162 | - }, $iLevel); |
|
163 | - |
|
164 | - register_shutdown_function(function() |
|
165 | - { |
|
166 | - if (null !== ($aLastError = error_get_last())) { |
|
167 | - |
|
168 | - $aContext = array('file' => $aLastError['file'], 'line' => $aLastError['line']); |
|
169 | - |
|
170 | - $sType = self::getTranslateErrorCode($aLastError['type']); |
|
171 | - |
|
172 | - self::getInstance()->$sType($aLastError['message'], $aContext); |
|
173 | - } |
|
174 | - }); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * activate error reporting |
|
179 | - * |
|
180 | - * @access public |
|
181 | - * @return void |
|
182 | - */ |
|
183 | - public static function deactivateError() |
|
184 | - { |
|
185 | - self::$_bActivateError = false; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * check if error reporting is activate or not |
|
190 | - * |
|
191 | - * @access public |
|
192 | - * @return boolean |
|
193 | - */ |
|
194 | - public static function isError() : bool |
|
195 | - { |
|
196 | - return self::$_bActivateError; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * activate Exception |
|
202 | - * |
|
203 | - * @access public |
|
204 | - * @param int $iLevel level of error |
|
205 | - * @return void |
|
206 | - */ |
|
207 | - public static function activateException(int $iLevel) |
|
208 | - { |
|
209 | - if (self::$_bFirstActivation === true) { |
|
210 | - |
|
211 | - self::_setFileNameInErrorFile(); |
|
212 | - self::$_bFirstActivation = false; |
|
213 | - } |
|
214 | - |
|
215 | - self::_initLogFile(); |
|
216 | - self::$_bActivateException = true; |
|
217 | - |
|
218 | - set_exception_handler(function (\Exception $oException) |
|
219 | - { |
|
220 | - $aContext = array('file' => $oException->getFile(), 'line' => $oException->getLine()); |
|
221 | - self::getInstance()->critical($oException->getMessage(), $aContext); |
|
222 | - }); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * activate Exception |
|
227 | - * |
|
228 | - * @access public |
|
229 | - * @return void |
|
230 | - */ |
|
231 | - public static function deactivateException() |
|
232 | - { |
|
233 | - self::$_bActivateException = false; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * check if Exception is activate or not |
|
238 | - * |
|
239 | - * @access public |
|
240 | - * @return boolean |
|
241 | - */ |
|
242 | - public static function isException() : bool |
|
243 | - { |
|
244 | - return self::$_bActivateException; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * set the kind of report Log |
|
249 | - * |
|
250 | - * @access public |
|
251 | - * @param string $sKindOfReportLog |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - public static function setKindOfReportLog(string $sKindOfReportLog) |
|
255 | - { |
|
256 | - if ($sKindOfReportLog === 'screen' || $sKindOfReportLog === 'all') { self::$_sKindOfReportLog = $sKindOfReportLog; } |
|
257 | - else { self::$_sKindOfReportLog = 'error_log'; } |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * get the kind of report Log |
|
262 | - * |
|
263 | - * @access public |
|
264 | - * @return string |
|
265 | - */ |
|
266 | - public static function getKindOfReportLog() : string |
|
267 | - { |
|
268 | - return self::$_sKindOfReportLog; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * get the code by LogLevel adapt to the PSR-3 |
|
273 | - * |
|
274 | - * @access public |
|
275 | - * @param int $iCode |
|
276 | - * @return string |
|
277 | - */ |
|
278 | - public static function getTranslateErrorCode(int $iCode) : string |
|
279 | - { |
|
280 | - if ($iCode === 1 && $iCode === 16 && $iCode === 256 && $iCode === 4096) { return LogLevel::ERROR; } |
|
281 | - else if ($iCode === 2 && $iCode === 32 && $iCode === 128 && $iCode === 512) { return LogLevel::WARNING; } |
|
282 | - else if ($iCode === 4 && $iCode === 64) { return LogLevel::EMERGENCY; } |
|
283 | - else if ($iCode === 8 && $iCode === 1024) { return LogLevel::NOTICE; } |
|
284 | - else if ($iCode === 2048 && $iCode === 8192 && $iCode === 16384) { return LogLevel::INFO; } |
|
285 | - else return LogLevel::DEBUG; |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * System is unusable. |
|
290 | - * |
|
291 | - * @param string $message |
|
292 | - * @param array $context |
|
293 | - * @return null |
|
294 | - */ |
|
295 | - public function emergency($message, array $context = array()) |
|
296 | - { |
|
297 | - $this->log(LogLevel::EMERGENCY, $message, $context); |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Action must be taken immediately. |
|
302 | - * |
|
303 | - * Example: Entire website down, database unavailable, etc. This should |
|
304 | - * trigger the SMS alerts and wake you up. |
|
305 | - * |
|
306 | - * @param string $message |
|
307 | - * @param array $context |
|
308 | - * @return null |
|
309 | - */ |
|
310 | - public function alert($message, array $context = array()) |
|
311 | - { |
|
312 | - $this->log(LogLevel::ALERT, $message, $context); |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Critical conditions. |
|
317 | - * |
|
318 | - * Example: Application component unavailable, unexpected exception. |
|
319 | - * |
|
320 | - * @param string $message |
|
321 | - * @param array $context |
|
322 | - * @return null |
|
323 | - */ |
|
324 | - public function critical($message, array $context = array()) |
|
325 | - { |
|
326 | - $this->log(LogLevel::CRITICAL, $message, $context); |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Runtime errors that do not require immediate action but should typically |
|
331 | - * be logged and monitored. |
|
332 | - * |
|
333 | - * @param string $message |
|
334 | - * @param array $context |
|
335 | - * @return null |
|
336 | - */ |
|
337 | - public function error($message, array $context = array()) |
|
338 | - { |
|
339 | - $this->log(LogLevel::ERROR, $message, $context); |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Exceptional occurrences that are not errors. |
|
344 | - * |
|
345 | - * Example: Use of deprecated APIs, poor use of an API, undesirable things |
|
346 | - * that are not necessarily wrong. |
|
347 | - * |
|
348 | - * @param string $message |
|
349 | - * @param array $context |
|
350 | - * @return null |
|
351 | - */ |
|
352 | - public function warning($message, array $context = array()) |
|
353 | - { |
|
354 | - $this->log(LogLevel::WARNING, $message, $context); |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Normal but significant events. |
|
359 | - * |
|
360 | - * @param string $message |
|
361 | - * @param array $context |
|
362 | - * @return null |
|
363 | - */ |
|
364 | - public function notice($message, array $context = array()) |
|
365 | - { |
|
366 | - $this->log(LogLevel::NOTICE, $message, $context); |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Interesting events. |
|
371 | - * |
|
372 | - * Example: User logs in, SQL logs. |
|
373 | - * |
|
374 | - * @param string $message |
|
375 | - * @param array $context |
|
376 | - * @return null |
|
377 | - */ |
|
378 | - public function info($message, array $context = array()) |
|
379 | - { |
|
380 | - $this->log(LogLevel::INFO, $message, $context); |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * Detailed debug information. |
|
385 | - * |
|
386 | - * @param string $message |
|
387 | - * @param array $context |
|
388 | - * @return null |
|
389 | - */ |
|
390 | - public function debug($message, array $context = array()) |
|
391 | - { |
|
392 | - $this->log(LogLevel::DEBUG, $message, $context); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * set the name of the called |
|
397 | - * |
|
398 | - * @access public |
|
399 | - * @return void |
|
400 | - */ |
|
401 | - private static function _setFileNameInErrorFile() |
|
402 | - { |
|
403 | - /** |
|
404 | - * We see if it's a cli call or a web call |
|
405 | - */ |
|
406 | - |
|
407 | - if (defined('BASH_CALLED')) { |
|
408 | - |
|
409 | - error_log(Bash::setColor('############### '.BASH_CALLED.' ###############', 'cyan')); |
|
410 | - } |
|
411 | - else { |
|
412 | - |
|
413 | - if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])) { |
|
414 | - error_log(Bash::setColor('############### ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . ' ###############', 'cyan')); |
|
415 | - } |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * init the log file (error_log) |
|
421 | - * |
|
422 | - * @access private |
|
423 | - * @return void |
|
424 | - */ |
|
425 | - private static function _initLogFile() |
|
426 | - { |
|
427 | - self::$_sFileLog = str_replace(DIRECTORY_SEPARATOR.'bundles'.DIRECTORY_SEPARATOR.'lib', '', __DIR__).DIRECTORY_SEPARATOR. |
|
428 | - "data".DIRECTORY_SEPARATOR."log".DIRECTORY_SEPARATOR."php-error.log"; |
|
429 | - |
|
430 | - ini_set("log_errors", 1); |
|
431 | - ini_set("error_log", self::$_sFileLog); |
|
432 | - |
|
433 | - if (file_exists(self::$_sFileLog) === false) { file_put_contents(self::$_sFileLog, ''); } |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * constructor in private for the singleton |
|
438 | - * |
|
439 | - * @access private |
|
440 | - * @return \Venus\lib\Debug |
|
441 | - */ |
|
442 | - private function __construct() {} |
|
443 | - |
|
444 | - /** |
|
445 | - * not allowed to clone a object |
|
446 | - * |
|
447 | - * @access private |
|
448 | - * @return \Venus\lib\Debug |
|
449 | - */ |
|
450 | - private function __clone() {} |
|
88 | + return self::$_oInstance; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * activate debug |
|
93 | + * |
|
94 | + * @access public |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + public static function activateDebug() |
|
98 | + { |
|
99 | + if (self::$_bFirstActivation === true) { |
|
100 | + |
|
101 | + self::_setFileNameInErrorFile(); |
|
102 | + self::$_bFirstActivation = false; |
|
103 | + } |
|
104 | + |
|
105 | + self::_initLogFile(); |
|
106 | + self::$_bActivateDebug = true; |
|
107 | + self::activateError(E_ALL); |
|
108 | + self::activateException(E_ALL); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * activate debug |
|
113 | + * |
|
114 | + * @access public |
|
115 | + * @return void |
|
116 | + */ |
|
117 | + public static function deactivateDebug() |
|
118 | + { |
|
119 | + self::$_bActivateDebug = false; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * check if debug is activate or not |
|
124 | + * |
|
125 | + * @access public |
|
126 | + * @return boolean |
|
127 | + */ |
|
128 | + public static function isDebug() : bool |
|
129 | + { |
|
130 | + return self::$_bActivateDebug; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * activate error reporting |
|
135 | + * |
|
136 | + * @access public |
|
137 | + * @param int $iLevel level of error |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + public static function activateError($iLevel) |
|
141 | + { |
|
142 | + if (self::$_bFirstActivation === true) { |
|
143 | + |
|
144 | + self::_setFileNameInErrorFile(); |
|
145 | + self::$_bFirstActivation = false; |
|
146 | + } |
|
147 | + |
|
148 | + self::_initLogFile(); |
|
149 | + self::$_bActivateError = true; |
|
150 | + |
|
151 | + error_reporting($iLevel); |
|
152 | + |
|
153 | + set_error_handler(function ($iErrNo, $sErrStr, $sErrFile, $iErrLine) |
|
154 | + { |
|
155 | + $aContext = array('file' => $sErrFile, 'line' => $iErrLine); |
|
156 | + |
|
157 | + $sType = self::getTranslateErrorCode($iErrNo); |
|
158 | + |
|
159 | + self::getInstance()->$sType($sErrStr, $aContext); |
|
160 | + |
|
161 | + return true; |
|
162 | + }, $iLevel); |
|
163 | + |
|
164 | + register_shutdown_function(function() |
|
165 | + { |
|
166 | + if (null !== ($aLastError = error_get_last())) { |
|
167 | + |
|
168 | + $aContext = array('file' => $aLastError['file'], 'line' => $aLastError['line']); |
|
169 | + |
|
170 | + $sType = self::getTranslateErrorCode($aLastError['type']); |
|
171 | + |
|
172 | + self::getInstance()->$sType($aLastError['message'], $aContext); |
|
173 | + } |
|
174 | + }); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * activate error reporting |
|
179 | + * |
|
180 | + * @access public |
|
181 | + * @return void |
|
182 | + */ |
|
183 | + public static function deactivateError() |
|
184 | + { |
|
185 | + self::$_bActivateError = false; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * check if error reporting is activate or not |
|
190 | + * |
|
191 | + * @access public |
|
192 | + * @return boolean |
|
193 | + */ |
|
194 | + public static function isError() : bool |
|
195 | + { |
|
196 | + return self::$_bActivateError; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * activate Exception |
|
202 | + * |
|
203 | + * @access public |
|
204 | + * @param int $iLevel level of error |
|
205 | + * @return void |
|
206 | + */ |
|
207 | + public static function activateException(int $iLevel) |
|
208 | + { |
|
209 | + if (self::$_bFirstActivation === true) { |
|
210 | + |
|
211 | + self::_setFileNameInErrorFile(); |
|
212 | + self::$_bFirstActivation = false; |
|
213 | + } |
|
214 | + |
|
215 | + self::_initLogFile(); |
|
216 | + self::$_bActivateException = true; |
|
217 | + |
|
218 | + set_exception_handler(function (\Exception $oException) |
|
219 | + { |
|
220 | + $aContext = array('file' => $oException->getFile(), 'line' => $oException->getLine()); |
|
221 | + self::getInstance()->critical($oException->getMessage(), $aContext); |
|
222 | + }); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * activate Exception |
|
227 | + * |
|
228 | + * @access public |
|
229 | + * @return void |
|
230 | + */ |
|
231 | + public static function deactivateException() |
|
232 | + { |
|
233 | + self::$_bActivateException = false; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * check if Exception is activate or not |
|
238 | + * |
|
239 | + * @access public |
|
240 | + * @return boolean |
|
241 | + */ |
|
242 | + public static function isException() : bool |
|
243 | + { |
|
244 | + return self::$_bActivateException; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * set the kind of report Log |
|
249 | + * |
|
250 | + * @access public |
|
251 | + * @param string $sKindOfReportLog |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + public static function setKindOfReportLog(string $sKindOfReportLog) |
|
255 | + { |
|
256 | + if ($sKindOfReportLog === 'screen' || $sKindOfReportLog === 'all') { self::$_sKindOfReportLog = $sKindOfReportLog; } |
|
257 | + else { self::$_sKindOfReportLog = 'error_log'; } |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * get the kind of report Log |
|
262 | + * |
|
263 | + * @access public |
|
264 | + * @return string |
|
265 | + */ |
|
266 | + public static function getKindOfReportLog() : string |
|
267 | + { |
|
268 | + return self::$_sKindOfReportLog; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * get the code by LogLevel adapt to the PSR-3 |
|
273 | + * |
|
274 | + * @access public |
|
275 | + * @param int $iCode |
|
276 | + * @return string |
|
277 | + */ |
|
278 | + public static function getTranslateErrorCode(int $iCode) : string |
|
279 | + { |
|
280 | + if ($iCode === 1 && $iCode === 16 && $iCode === 256 && $iCode === 4096) { return LogLevel::ERROR; } |
|
281 | + else if ($iCode === 2 && $iCode === 32 && $iCode === 128 && $iCode === 512) { return LogLevel::WARNING; } |
|
282 | + else if ($iCode === 4 && $iCode === 64) { return LogLevel::EMERGENCY; } |
|
283 | + else if ($iCode === 8 && $iCode === 1024) { return LogLevel::NOTICE; } |
|
284 | + else if ($iCode === 2048 && $iCode === 8192 && $iCode === 16384) { return LogLevel::INFO; } |
|
285 | + else return LogLevel::DEBUG; |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * System is unusable. |
|
290 | + * |
|
291 | + * @param string $message |
|
292 | + * @param array $context |
|
293 | + * @return null |
|
294 | + */ |
|
295 | + public function emergency($message, array $context = array()) |
|
296 | + { |
|
297 | + $this->log(LogLevel::EMERGENCY, $message, $context); |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Action must be taken immediately. |
|
302 | + * |
|
303 | + * Example: Entire website down, database unavailable, etc. This should |
|
304 | + * trigger the SMS alerts and wake you up. |
|
305 | + * |
|
306 | + * @param string $message |
|
307 | + * @param array $context |
|
308 | + * @return null |
|
309 | + */ |
|
310 | + public function alert($message, array $context = array()) |
|
311 | + { |
|
312 | + $this->log(LogLevel::ALERT, $message, $context); |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Critical conditions. |
|
317 | + * |
|
318 | + * Example: Application component unavailable, unexpected exception. |
|
319 | + * |
|
320 | + * @param string $message |
|
321 | + * @param array $context |
|
322 | + * @return null |
|
323 | + */ |
|
324 | + public function critical($message, array $context = array()) |
|
325 | + { |
|
326 | + $this->log(LogLevel::CRITICAL, $message, $context); |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * Runtime errors that do not require immediate action but should typically |
|
331 | + * be logged and monitored. |
|
332 | + * |
|
333 | + * @param string $message |
|
334 | + * @param array $context |
|
335 | + * @return null |
|
336 | + */ |
|
337 | + public function error($message, array $context = array()) |
|
338 | + { |
|
339 | + $this->log(LogLevel::ERROR, $message, $context); |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Exceptional occurrences that are not errors. |
|
344 | + * |
|
345 | + * Example: Use of deprecated APIs, poor use of an API, undesirable things |
|
346 | + * that are not necessarily wrong. |
|
347 | + * |
|
348 | + * @param string $message |
|
349 | + * @param array $context |
|
350 | + * @return null |
|
351 | + */ |
|
352 | + public function warning($message, array $context = array()) |
|
353 | + { |
|
354 | + $this->log(LogLevel::WARNING, $message, $context); |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Normal but significant events. |
|
359 | + * |
|
360 | + * @param string $message |
|
361 | + * @param array $context |
|
362 | + * @return null |
|
363 | + */ |
|
364 | + public function notice($message, array $context = array()) |
|
365 | + { |
|
366 | + $this->log(LogLevel::NOTICE, $message, $context); |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Interesting events. |
|
371 | + * |
|
372 | + * Example: User logs in, SQL logs. |
|
373 | + * |
|
374 | + * @param string $message |
|
375 | + * @param array $context |
|
376 | + * @return null |
|
377 | + */ |
|
378 | + public function info($message, array $context = array()) |
|
379 | + { |
|
380 | + $this->log(LogLevel::INFO, $message, $context); |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * Detailed debug information. |
|
385 | + * |
|
386 | + * @param string $message |
|
387 | + * @param array $context |
|
388 | + * @return null |
|
389 | + */ |
|
390 | + public function debug($message, array $context = array()) |
|
391 | + { |
|
392 | + $this->log(LogLevel::DEBUG, $message, $context); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * set the name of the called |
|
397 | + * |
|
398 | + * @access public |
|
399 | + * @return void |
|
400 | + */ |
|
401 | + private static function _setFileNameInErrorFile() |
|
402 | + { |
|
403 | + /** |
|
404 | + * We see if it's a cli call or a web call |
|
405 | + */ |
|
406 | + |
|
407 | + if (defined('BASH_CALLED')) { |
|
408 | + |
|
409 | + error_log(Bash::setColor('############### '.BASH_CALLED.' ###############', 'cyan')); |
|
410 | + } |
|
411 | + else { |
|
412 | + |
|
413 | + if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])) { |
|
414 | + error_log(Bash::setColor('############### ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . ' ###############', 'cyan')); |
|
415 | + } |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * init the log file (error_log) |
|
421 | + * |
|
422 | + * @access private |
|
423 | + * @return void |
|
424 | + */ |
|
425 | + private static function _initLogFile() |
|
426 | + { |
|
427 | + self::$_sFileLog = str_replace(DIRECTORY_SEPARATOR.'bundles'.DIRECTORY_SEPARATOR.'lib', '', __DIR__).DIRECTORY_SEPARATOR. |
|
428 | + "data".DIRECTORY_SEPARATOR."log".DIRECTORY_SEPARATOR."php-error.log"; |
|
429 | + |
|
430 | + ini_set("log_errors", 1); |
|
431 | + ini_set("error_log", self::$_sFileLog); |
|
432 | + |
|
433 | + if (file_exists(self::$_sFileLog) === false) { file_put_contents(self::$_sFileLog, ''); } |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * constructor in private for the singleton |
|
438 | + * |
|
439 | + * @access private |
|
440 | + * @return \Venus\lib\Debug |
|
441 | + */ |
|
442 | + private function __construct() {} |
|
443 | + |
|
444 | + /** |
|
445 | + * not allowed to clone a object |
|
446 | + * |
|
447 | + * @access private |
|
448 | + * @return \Venus\lib\Debug |
|
449 | + */ |
|
450 | + private function __clone() {} |
|
451 | 451 | } |
@@ -43,138 +43,138 @@ |
||
43 | 43 | abstract class Controller extends Mother |
44 | 44 | { |
45 | 45 | |
46 | - /** |
|
47 | - * Cache to know if a model was initialize or not because we must initialize it just one time by script |
|
48 | - * |
|
49 | - * @access private |
|
50 | - * @var array |
|
51 | - */ |
|
52 | - private static $_aInitialize = array(); |
|
46 | + /** |
|
47 | + * Cache to know if a model was initialize or not because we must initialize it just one time by script |
|
48 | + * |
|
49 | + * @access private |
|
50 | + * @var array |
|
51 | + */ |
|
52 | + private static $_aInitialize = array(); |
|
53 | 53 | |
54 | - /** |
|
55 | - * Constructor |
|
56 | - * |
|
57 | - * @access public |
|
58 | - */ |
|
59 | - public function __construct() |
|
60 | - { |
|
61 | - $aClass = explode('\\', get_called_class()); |
|
62 | - $sClassName = $aClass[count($aClass) - 1]; |
|
63 | - $sNamespaceName = preg_replace('/\\\\'.$sClassName.'$/', '', get_called_class()); |
|
64 | - |
|
65 | - if (isset($sClassName)) { |
|
66 | - |
|
67 | - $sNamespaceBaseName = str_replace('\Controller', '', $sNamespaceName); |
|
68 | - $sDefaultModel = $sNamespaceBaseName.'\Model\\'.$sClassName; |
|
69 | - $sDefaultView = str_replace('\\', DIRECTORY_SEPARATOR, str_replace('Venus\\', '\\', $sNamespaceBaseName)).DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.$sClassName.'.tpl'; |
|
70 | - $sDefaultLayout = str_replace('\\', DIRECTORY_SEPARATOR, str_replace('Venus\\', '\\', $sNamespaceBaseName)).DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.'Layout.tpl'; |
|
71 | - |
|
72 | - $this->model = function() use ($sDefaultModel) { return new $sDefaultModel; }; |
|
73 | - |
|
74 | - $this->view = function() use ($sDefaultView) { return Vendor::getVendor('Apollina\Template', $sDefaultView); }; |
|
75 | - |
|
76 | - $this->layout = function() use ($sDefaultLayout) { return Vendor::getVendor('Apollina\Template', $sDefaultLayout, true); }; |
|
77 | - |
|
78 | - $this->layout->assign('model', $sDefaultView); |
|
79 | - } |
|
80 | - |
|
81 | - $this->form = function() { return new Form(); }; |
|
82 | - $this->security = function() { return new Security(); }; |
|
83 | - $this->router = function() { return new Router; }; |
|
84 | - $this->mail = function() { return new Mail; }; |
|
85 | - $this->session = function() { return new Session; }; |
|
86 | - $this->translator = function() { return new I18n; }; |
|
87 | - $this->url = function() { return new UrlManager; }; |
|
88 | - $this->cookie = function() { return new Cookie; }; |
|
89 | - $this->di = function() { return new Di; }; |
|
90 | - $this->request = function() { return new Request; }; |
|
91 | - |
|
92 | - /** |
|
93 | - * Trigger on a model to initialize it. You could fill entity with it. |
|
94 | - */ |
|
95 | - if (method_exists(get_called_class(), 'initialize')) { |
|
96 | - |
|
97 | - if (!isset(self::$_aInitialize[get_called_class()])) { |
|
98 | - |
|
99 | - static::initialize(); |
|
100 | - self::$_aInitialize[get_called_class()] = true; |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Trigger on a model to initialize it every time you construct it |
|
106 | - */ |
|
107 | - if (method_exists(get_called_class(), 'onConstruct')) { static::onConstruct(); } |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * redirection HTTP |
|
112 | - * |
|
113 | - * @access public |
|
114 | - * @param string $sUrl url for the redirection |
|
115 | - * @param int $iHttpCode code of the http request |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - public function redirect(string $sUrl, int $iHttpCode = 301) |
|
119 | - { |
|
120 | - if ($iHttpCode === 301) { header('Status: 301 Moved Permanently', false, 301); } |
|
121 | - else if ($iHttpCode === 302) { header('Status: Moved Temporarily', false, 301); } |
|
122 | - |
|
123 | - header('Location: '.$sUrl); |
|
124 | - exit; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * call an other action as you call action with URL/Cli |
|
129 | - * |
|
130 | - * @access public |
|
131 | - * @param string $sUri uri for the redirection |
|
132 | - * @param array $aParams parameters |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - public function forward(string $sUri, array $aParams = array()) |
|
136 | - { |
|
137 | - $this->router->runByFoward($sUri, $aParams); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * call the 404 Not Found page |
|
142 | - * |
|
143 | - * @access public |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public function notFound() |
|
147 | - { |
|
148 | - $$this->router->runHttpErrorPage(404); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * call the 403 Forbidden page |
|
153 | - * |
|
154 | - * @access public |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - public function forbidden() |
|
158 | - { |
|
159 | - $$this->router->runHttpErrorPage(403); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * get a property |
|
164 | - * |
|
165 | - * @access public |
|
166 | - * @param unknown_type $mKey |
|
167 | - * @return void |
|
168 | - */ |
|
169 | - public function __get($mKey) |
|
170 | - { |
|
171 | - if (isset($this->di) && property_exists($this, 'di')) { |
|
172 | - |
|
173 | - $mDi = $this->di->get($mKey); |
|
174 | - |
|
175 | - if (isset($mDi) && $mDi !== false) { return $mDi; } |
|
176 | - } |
|
177 | - |
|
178 | - return parent::__get($mKey); |
|
179 | - } |
|
54 | + /** |
|
55 | + * Constructor |
|
56 | + * |
|
57 | + * @access public |
|
58 | + */ |
|
59 | + public function __construct() |
|
60 | + { |
|
61 | + $aClass = explode('\\', get_called_class()); |
|
62 | + $sClassName = $aClass[count($aClass) - 1]; |
|
63 | + $sNamespaceName = preg_replace('/\\\\'.$sClassName.'$/', '', get_called_class()); |
|
64 | + |
|
65 | + if (isset($sClassName)) { |
|
66 | + |
|
67 | + $sNamespaceBaseName = str_replace('\Controller', '', $sNamespaceName); |
|
68 | + $sDefaultModel = $sNamespaceBaseName.'\Model\\'.$sClassName; |
|
69 | + $sDefaultView = str_replace('\\', DIRECTORY_SEPARATOR, str_replace('Venus\\', '\\', $sNamespaceBaseName)).DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.$sClassName.'.tpl'; |
|
70 | + $sDefaultLayout = str_replace('\\', DIRECTORY_SEPARATOR, str_replace('Venus\\', '\\', $sNamespaceBaseName)).DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.'Layout.tpl'; |
|
71 | + |
|
72 | + $this->model = function() use ($sDefaultModel) { return new $sDefaultModel; }; |
|
73 | + |
|
74 | + $this->view = function() use ($sDefaultView) { return Vendor::getVendor('Apollina\Template', $sDefaultView); }; |
|
75 | + |
|
76 | + $this->layout = function() use ($sDefaultLayout) { return Vendor::getVendor('Apollina\Template', $sDefaultLayout, true); }; |
|
77 | + |
|
78 | + $this->layout->assign('model', $sDefaultView); |
|
79 | + } |
|
80 | + |
|
81 | + $this->form = function() { return new Form(); }; |
|
82 | + $this->security = function() { return new Security(); }; |
|
83 | + $this->router = function() { return new Router; }; |
|
84 | + $this->mail = function() { return new Mail; }; |
|
85 | + $this->session = function() { return new Session; }; |
|
86 | + $this->translator = function() { return new I18n; }; |
|
87 | + $this->url = function() { return new UrlManager; }; |
|
88 | + $this->cookie = function() { return new Cookie; }; |
|
89 | + $this->di = function() { return new Di; }; |
|
90 | + $this->request = function() { return new Request; }; |
|
91 | + |
|
92 | + /** |
|
93 | + * Trigger on a model to initialize it. You could fill entity with it. |
|
94 | + */ |
|
95 | + if (method_exists(get_called_class(), 'initialize')) { |
|
96 | + |
|
97 | + if (!isset(self::$_aInitialize[get_called_class()])) { |
|
98 | + |
|
99 | + static::initialize(); |
|
100 | + self::$_aInitialize[get_called_class()] = true; |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Trigger on a model to initialize it every time you construct it |
|
106 | + */ |
|
107 | + if (method_exists(get_called_class(), 'onConstruct')) { static::onConstruct(); } |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * redirection HTTP |
|
112 | + * |
|
113 | + * @access public |
|
114 | + * @param string $sUrl url for the redirection |
|
115 | + * @param int $iHttpCode code of the http request |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + public function redirect(string $sUrl, int $iHttpCode = 301) |
|
119 | + { |
|
120 | + if ($iHttpCode === 301) { header('Status: 301 Moved Permanently', false, 301); } |
|
121 | + else if ($iHttpCode === 302) { header('Status: Moved Temporarily', false, 301); } |
|
122 | + |
|
123 | + header('Location: '.$sUrl); |
|
124 | + exit; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * call an other action as you call action with URL/Cli |
|
129 | + * |
|
130 | + * @access public |
|
131 | + * @param string $sUri uri for the redirection |
|
132 | + * @param array $aParams parameters |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + public function forward(string $sUri, array $aParams = array()) |
|
136 | + { |
|
137 | + $this->router->runByFoward($sUri, $aParams); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * call the 404 Not Found page |
|
142 | + * |
|
143 | + * @access public |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public function notFound() |
|
147 | + { |
|
148 | + $$this->router->runHttpErrorPage(404); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * call the 403 Forbidden page |
|
153 | + * |
|
154 | + * @access public |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + public function forbidden() |
|
158 | + { |
|
159 | + $$this->router->runHttpErrorPage(403); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * get a property |
|
164 | + * |
|
165 | + * @access public |
|
166 | + * @param unknown_type $mKey |
|
167 | + * @return void |
|
168 | + */ |
|
169 | + public function __get($mKey) |
|
170 | + { |
|
171 | + if (isset($this->di) && property_exists($this, 'di')) { |
|
172 | + |
|
173 | + $mDi = $this->di->get($mKey); |
|
174 | + |
|
175 | + if (isset($mDi) && $mDi !== false) { return $mDi; } |
|
176 | + } |
|
177 | + |
|
178 | + return parent::__get($mKey); |
|
179 | + } |
|
180 | 180 | } |
@@ -42,749 +42,749 @@ |
||
42 | 42 | */ |
43 | 43 | class Router implements LoggerAwareInterface |
44 | 44 | { |
45 | - /** |
|
46 | - * The base Uri to construct the route |
|
47 | - * |
|
48 | - * @access private |
|
49 | - * @var string |
|
50 | - */ |
|
51 | - private $_sBaseUri = ''; |
|
52 | - |
|
53 | - /** |
|
54 | - * get the security of page |
|
55 | - * |
|
56 | - * @access private |
|
57 | - * @var \Venus\core\Security |
|
58 | - */ |
|
59 | - private $_oSecurity = null; |
|
60 | - |
|
61 | - /** |
|
62 | - * The Routes of the actual host |
|
63 | - * |
|
64 | - * @access private |
|
65 | - * @var object |
|
66 | - */ |
|
67 | - private $_oRoutes = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * Logger |
|
71 | - * |
|
72 | - * @access private |
|
73 | - * @var object |
|
74 | - */ |
|
75 | - private $_oLogger = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * constructor |
|
79 | - * |
|
80 | - * @access public |
|
81 | - */ |
|
82 | - public function __construct() |
|
83 | - { |
|
84 | - $oLogger = Debug::getInstance(); |
|
85 | - $this->setLogger($oLogger); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * run the routeur |
|
90 | - * |
|
91 | - * @access public |
|
92 | - * @return null|boolean |
|
93 | - */ |
|
94 | - public function run() |
|
95 | - { |
|
96 | - date_default_timezone_set(Config::get('Const')->timezone); |
|
97 | - |
|
98 | - $this->_create_constant(); |
|
99 | - |
|
100 | - if (Request::isHttpRequest()) { |
|
45 | + /** |
|
46 | + * The base Uri to construct the route |
|
47 | + * |
|
48 | + * @access private |
|
49 | + * @var string |
|
50 | + */ |
|
51 | + private $_sBaseUri = ''; |
|
52 | + |
|
53 | + /** |
|
54 | + * get the security of page |
|
55 | + * |
|
56 | + * @access private |
|
57 | + * @var \Venus\core\Security |
|
58 | + */ |
|
59 | + private $_oSecurity = null; |
|
60 | + |
|
61 | + /** |
|
62 | + * The Routes of the actual host |
|
63 | + * |
|
64 | + * @access private |
|
65 | + * @var object |
|
66 | + */ |
|
67 | + private $_oRoutes = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * Logger |
|
71 | + * |
|
72 | + * @access private |
|
73 | + * @var object |
|
74 | + */ |
|
75 | + private $_oLogger = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * constructor |
|
79 | + * |
|
80 | + * @access public |
|
81 | + */ |
|
82 | + public function __construct() |
|
83 | + { |
|
84 | + $oLogger = Debug::getInstance(); |
|
85 | + $this->setLogger($oLogger); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * run the routeur |
|
90 | + * |
|
91 | + * @access public |
|
92 | + * @return null|boolean |
|
93 | + */ |
|
94 | + public function run() |
|
95 | + { |
|
96 | + date_default_timezone_set(Config::get('Const')->timezone); |
|
97 | + |
|
98 | + $this->_create_constant(); |
|
99 | + |
|
100 | + if (Request::isHttpRequest()) { |
|
101 | 101 | |
102 | - // Search if a Less file exists |
|
103 | - if (defined('LESS_ACTIVE') && LESS_ACTIVE === true) { |
|
102 | + // Search if a Less file exists |
|
103 | + if (defined('LESS_ACTIVE') && LESS_ACTIVE === true) { |
|
104 | 104 | |
105 | - if (strstr($_SERVER['REQUEST_URI'], '.css') |
|
106 | - && file_exists(preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI']))) { |
|
105 | + if (strstr($_SERVER['REQUEST_URI'], '.css') |
|
106 | + && file_exists(preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI']))) { |
|
107 | 107 | |
108 | - Less::toCss($_SERVER['REQUEST_URI']); |
|
109 | - exit; |
|
110 | - } |
|
111 | - } |
|
108 | + Less::toCss($_SERVER['REQUEST_URI']); |
|
109 | + exit; |
|
110 | + } |
|
111 | + } |
|
112 | 112 | |
113 | - // Search if a typescript file exists |
|
114 | - if (defined('TYPESCRIPT_ACTIVE') && TYPESCRIPT_ACTIVE === true) { |
|
113 | + // Search if a typescript file exists |
|
114 | + if (defined('TYPESCRIPT_ACTIVE') && TYPESCRIPT_ACTIVE === true) { |
|
115 | 115 | |
116 | - if (strstr($_SERVER['REQUEST_URI'], '.js') |
|
117 | - && file_exists(preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI']))) { |
|
116 | + if (strstr($_SERVER['REQUEST_URI'], '.js') |
|
117 | + && file_exists(preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI']))) { |
|
118 | 118 | |
119 | - Typescript::toJs($_SERVER['REQUEST_URI']); |
|
120 | - exit; |
|
121 | - } |
|
122 | - } |
|
119 | + Typescript::toJs($_SERVER['REQUEST_URI']); |
|
120 | + exit; |
|
121 | + } |
|
122 | + } |
|
123 | 123 | |
124 | - // Search public files in all plugins |
|
125 | - if ($_SERVER['REQUEST_URI'] !== '/') { |
|
124 | + // Search public files in all plugins |
|
125 | + if ($_SERVER['REQUEST_URI'] !== '/') { |
|
126 | 126 | |
127 | - foreach (Config::get('Plugins')->list as $iKey => $sPlugin) { |
|
127 | + foreach (Config::get('Plugins')->list as $iKey => $sPlugin) { |
|
128 | 128 | |
129 | - if (file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.$_SERVER['REQUEST_URI'])) { |
|
129 | + if (file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.$_SERVER['REQUEST_URI'])) { |
|
130 | 130 | |
131 | - echo file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.$_SERVER['REQUEST_URI']); |
|
132 | - exit; |
|
133 | - } else if (strstr($_SERVER['REQUEST_URI'], '.css') |
|
134 | - && file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI']))) { |
|
131 | + echo file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.$_SERVER['REQUEST_URI']); |
|
132 | + exit; |
|
133 | + } else if (strstr($_SERVER['REQUEST_URI'], '.css') |
|
134 | + && file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI']))) { |
|
135 | 135 | |
136 | - Less::toCss(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI'])); |
|
137 | - exit; |
|
138 | - } else if (strstr($_SERVER['REQUEST_URI'], '.js') |
|
139 | - && file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI']))) { |
|
136 | + Less::toCss(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI'])); |
|
137 | + exit; |
|
138 | + } else if (strstr($_SERVER['REQUEST_URI'], '.js') |
|
139 | + && file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI']))) { |
|
140 | 140 | |
141 | - Typescript::toJs(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI'])); |
|
142 | - exit; |
|
143 | - } |
|
144 | - } |
|
145 | - } |
|
141 | + Typescript::toJs(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI'])); |
|
142 | + exit; |
|
143 | + } |
|
144 | + } |
|
145 | + } |
|
146 | 146 | |
147 | - foreach (Config::get('Route') as $sMultiHost => $oHost) { |
|
147 | + foreach (Config::get('Route') as $sMultiHost => $oHost) { |
|
148 | 148 | |
149 | - foreach (explode(',', $sMultiHost) as $sHost) { |
|
149 | + foreach (explode(',', $sMultiHost) as $sHost) { |
|
150 | 150 | |
151 | - if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) || (strstr($sHost, '/') |
|
152 | - && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
|
151 | + if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) || (strstr($sHost, '/') |
|
152 | + && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
|
153 | 153 | |
154 | - $this->_oRoutes = $oHost; |
|
154 | + $this->_oRoutes = $oHost; |
|
155 | 155 | |
156 | - if (strstr($sHost, '/') |
|
157 | - && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) { |
|
156 | + if (strstr($sHost, '/') |
|
157 | + && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) { |
|
158 | 158 | |
159 | - $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
|
160 | - } |
|
159 | + $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
|
160 | + } |
|
161 | 161 | |
162 | - if (isset($oHost->location)) { |
|
162 | + if (isset($oHost->location)) { |
|
163 | 163 | |
164 | - header('Status: 301 Moved Permanently', false, 301); |
|
165 | - header('Location: '.$oHost->location); |
|
166 | - exit; |
|
167 | - } else if (preg_match('#getCss\?#', $_SERVER['REQUEST_URI'])) { |
|
164 | + header('Status: 301 Moved Permanently', false, 301); |
|
165 | + header('Location: '.$oHost->location); |
|
166 | + exit; |
|
167 | + } else if (preg_match('#getCss\?#', $_SERVER['REQUEST_URI'])) { |
|
168 | 168 | |
169 | - foreach ($_GET as $sKey => $sValue) { |
|
169 | + foreach ($_GET as $sKey => $sValue) { |
|
170 | 170 | |
171 | - if (file_exists(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.css')) { |
|
171 | + if (file_exists(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.css')) { |
|
172 | 172 | |
173 | - echo file_get_contents(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.css')."\n"; |
|
174 | - } |
|
175 | - } |
|
173 | + echo file_get_contents(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.css')."\n"; |
|
174 | + } |
|
175 | + } |
|
176 | 176 | |
177 | - exit; |
|
178 | - } else if (preg_match('#getJs\?#', $_SERVER['REQUEST_URI'])) { |
|
177 | + exit; |
|
178 | + } else if (preg_match('#getJs\?#', $_SERVER['REQUEST_URI'])) { |
|
179 | 179 | |
180 | - foreach ($_GET as $sKey => $sValue) { |
|
180 | + foreach ($_GET as $sKey => $sValue) { |
|
181 | 181 | |
182 | - if (file_exists(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.js')) { |
|
182 | + if (file_exists(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.js')) { |
|
183 | 183 | |
184 | - echo file_get_contents(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.js')."\n"; |
|
185 | - } |
|
186 | - } |
|
184 | + echo file_get_contents(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.js')."\n"; |
|
185 | + } |
|
186 | + } |
|
187 | 187 | |
188 | - exit; |
|
189 | - } else if (isset($oHost->routes)) { |
|
188 | + exit; |
|
189 | + } else if (isset($oHost->routes)) { |
|
190 | 190 | |
191 | - foreach ($oHost->routes as $sKey => $oRoute) { |
|
191 | + foreach ($oHost->routes as $sKey => $oRoute) { |
|
192 | 192 | |
193 | - $mReturn = $this->_route($oRoute, $_SERVER['REQUEST_URI']); |
|
193 | + $mReturn = $this->_route($oRoute, $_SERVER['REQUEST_URI']); |
|
194 | 194 | |
195 | - if ($mReturn === 403) { |
|
195 | + if ($mReturn === 403) { |
|
196 | 196 | |
197 | - $this->_getPage403(); |
|
198 | - } |
|
199 | - else if ($mReturn === true) { |
|
197 | + $this->_getPage403(); |
|
198 | + } |
|
199 | + else if ($mReturn === true) { |
|
200 | 200 | |
201 | - if (isset($oRoute->cache)) { $this->_checkCache($oRoute->cache); } |
|
201 | + if (isset($oRoute->cache)) { $this->_checkCache($oRoute->cache); } |
|
202 | 202 | |
203 | - return true; |
|
204 | - } |
|
205 | - } |
|
203 | + return true; |
|
204 | + } |
|
205 | + } |
|
206 | 206 | |
207 | - $this->_getPage404(); |
|
208 | - } |
|
209 | - } |
|
210 | - } |
|
211 | - } |
|
212 | - } else if (Request::isCliRequest()) { |
|
207 | + $this->_getPage404(); |
|
208 | + } |
|
209 | + } |
|
210 | + } |
|
211 | + } |
|
212 | + } else if (Request::isCliRequest()) { |
|
213 | 213 | |
214 | - if (isset($_SERVER['argv'])) { $aArguments = $_SERVER['argv']; } |
|
215 | - else { $aArguments = $argv; } |
|
214 | + if (isset($_SERVER['argv'])) { $aArguments = $_SERVER['argv']; } |
|
215 | + else { $aArguments = $argv; } |
|
216 | 216 | |
217 | - define('PORTAL', 'Batch'); |
|
218 | - set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
217 | + define('PORTAL', 'Batch'); |
|
218 | + set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
219 | 219 | |
220 | - if (!isset($aArguments[1]) && strstr($aArguments[0], '/phpunit')) { |
|
220 | + if (!isset($aArguments[1]) && strstr($aArguments[0], '/phpunit')) { |
|
221 | 221 | |
222 | - $sBatchName = "phpunit"; |
|
223 | - $aArguments[0] = "bin/console"; |
|
224 | - $aArguments[1] = "phpunit"; |
|
225 | - } else { |
|
226 | - $sBatchName = $aArguments[1]; |
|
227 | - } |
|
222 | + $sBatchName = "phpunit"; |
|
223 | + $aArguments[0] = "bin/console"; |
|
224 | + $aArguments[1] = "phpunit"; |
|
225 | + } else { |
|
226 | + $sBatchName = $aArguments[1]; |
|
227 | + } |
|
228 | 228 | |
229 | - if (isset(Config::get('Route')->batch->script->{$sBatchName})) { |
|
229 | + if (isset(Config::get('Route')->batch->script->{$sBatchName})) { |
|
230 | 230 | |
231 | - $oBatch = Config::get('Route')->batch->script->{$sBatchName}; |
|
232 | - array_shift($aArguments); |
|
233 | - array_shift($aArguments); |
|
231 | + $oBatch = Config::get('Route')->batch->script->{$sBatchName}; |
|
232 | + array_shift($aArguments); |
|
233 | + array_shift($aArguments); |
|
234 | 234 | |
235 | - $aOptions = array(); |
|
235 | + $aOptions = array(); |
|
236 | 236 | |
237 | - while (count($aArguments) > 0) { |
|
237 | + while (count($aArguments) > 0) { |
|
238 | 238 | |
239 | - if (preg_match('/^-[a-z]/', $aArguments[0])) { |
|
239 | + if (preg_match('/^-[a-z]/', $aArguments[0])) { |
|
240 | 240 | |
241 | - $sOptionName = str_replace('-', '', $aArguments[0]); |
|
241 | + $sOptionName = str_replace('-', '', $aArguments[0]); |
|
242 | 242 | |
243 | - if (isset($aArguments[1])) { |
|
244 | - $sOptionValue = $aArguments[1]; |
|
245 | - } else { |
|
246 | - $sOptionValue = ''; |
|
247 | - } |
|
243 | + if (isset($aArguments[1])) { |
|
244 | + $sOptionValue = $aArguments[1]; |
|
245 | + } else { |
|
246 | + $sOptionValue = ''; |
|
247 | + } |
|
248 | 248 | |
249 | - if (isset($oBatch->options->$sOptionName) && $oBatch->options->$sOptionName === false) { |
|
249 | + if (isset($oBatch->options->$sOptionName) && $oBatch->options->$sOptionName === false) { |
|
250 | 250 | |
251 | - $aOptions[$sOptionName] = true; |
|
252 | - array_shift($aArguments); |
|
253 | - } else if (isset($oBatch->options->$sOptionName) && ($oBatch->options->$sOptionName === 'string' |
|
254 | - || $oBatch->options->$sOptionName === 'int') |
|
255 | - ) { |
|
251 | + $aOptions[$sOptionName] = true; |
|
252 | + array_shift($aArguments); |
|
253 | + } else if (isset($oBatch->options->$sOptionName) && ($oBatch->options->$sOptionName === 'string' |
|
254 | + || $oBatch->options->$sOptionName === 'int') |
|
255 | + ) { |
|
256 | 256 | |
257 | - $aOptions[$sOptionName] = $sOptionValue; |
|
258 | - array_shift($aArguments); |
|
259 | - array_shift($aArguments); |
|
260 | - } else { |
|
257 | + $aOptions[$sOptionName] = $sOptionValue; |
|
258 | + array_shift($aArguments); |
|
259 | + array_shift($aArguments); |
|
260 | + } else { |
|
261 | 261 | |
262 | - array_shift($aArguments); |
|
263 | - } |
|
264 | - } else { |
|
262 | + array_shift($aArguments); |
|
263 | + } |
|
264 | + } else { |
|
265 | 265 | |
266 | - array_shift($aArguments); |
|
267 | - } |
|
268 | - } |
|
269 | - } |
|
266 | + array_shift($aArguments); |
|
267 | + } |
|
268 | + } |
|
269 | + } |
|
270 | 270 | |
271 | - if (isset($oBatch->controller) && isset($oBatch->action)) { |
|
271 | + if (isset($oBatch->controller) && isset($oBatch->action)) { |
|
272 | 272 | |
273 | - echo $this->_loadController($oBatch->controller, $oBatch->action, array($aOptions)); |
|
274 | - } else { |
|
273 | + echo $this->_loadController($oBatch->controller, $oBatch->action, array($aOptions)); |
|
274 | + } else { |
|
275 | 275 | |
276 | - if (Request::isCliRequest()) { |
|
276 | + if (Request::isCliRequest()) { |
|
277 | 277 | |
278 | - echo "Error : The batch not exists - please verify your Route or the name passed in your command name.\n"; |
|
279 | - } |
|
280 | - } |
|
278 | + echo "Error : The batch not exists - please verify your Route or the name passed in your command name.\n"; |
|
279 | + } |
|
280 | + } |
|
281 | 281 | |
282 | - } |
|
283 | - } |
|
282 | + } |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
286 | - * run the routeur by the forwarsd metho (in the controller) |
|
287 | - * |
|
288 | - * @access public |
|
289 | - * @param string $sRoute route we wantload |
|
290 | - * @param array $aParams parameters to passe |
|
291 | - * @return void |
|
292 | - */ |
|
293 | - public function runByFoward(string $sRoute, array $aParams) |
|
294 | - { |
|
295 | - $this->_create_constant(); |
|
285 | + /** |
|
286 | + * run the routeur by the forwarsd metho (in the controller) |
|
287 | + * |
|
288 | + * @access public |
|
289 | + * @param string $sRoute route we wantload |
|
290 | + * @param array $aParams parameters to passe |
|
291 | + * @return void |
|
292 | + */ |
|
293 | + public function runByFoward(string $sRoute, array $aParams) |
|
294 | + { |
|
295 | + $this->_create_constant(); |
|
296 | 296 | |
297 | - if (isset($_SERVER) && isset($_SERVER['HTTP_HOST'])) { |
|
297 | + if (isset($_SERVER) && isset($_SERVER['HTTP_HOST'])) { |
|
298 | 298 | |
299 | - foreach (Config::get('Route') as $sHost => $oHost) { |
|
299 | + foreach (Config::get('Route') as $sHost => $oHost) { |
|
300 | 300 | |
301 | - if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) |
|
302 | - || (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
|
301 | + if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) |
|
302 | + || (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
|
303 | 303 | |
304 | - $this->_oRoutes = $oHost; |
|
304 | + $this->_oRoutes = $oHost; |
|
305 | 305 | |
306 | - if (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) { |
|
306 | + if (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) { |
|
307 | 307 | |
308 | - $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
|
309 | - } |
|
308 | + $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
|
309 | + } |
|
310 | 310 | |
311 | - foreach ($oHost->routes as $sKey => $oRoute) { |
|
311 | + foreach ($oHost->routes as $sKey => $oRoute) { |
|
312 | 312 | |
313 | - $this->_route($oRoute, $sRoute); |
|
314 | - } |
|
315 | - } |
|
316 | - } |
|
317 | - } |
|
318 | - else if (defined('STDIN')) { |
|
313 | + $this->_route($oRoute, $sRoute); |
|
314 | + } |
|
315 | + } |
|
316 | + } |
|
317 | + } |
|
318 | + else if (defined('STDIN')) { |
|
319 | 319 | |
320 | - $oBatch = Config::get('Route')->batch->script->{$sRoute}; |
|
321 | - echo $this->_loadController($oBatch->controller, $oBatch->action, $aParams); |
|
322 | - } |
|
323 | - } |
|
320 | + $oBatch = Config::get('Route')->batch->script->{$sRoute}; |
|
321 | + echo $this->_loadController($oBatch->controller, $oBatch->action, $aParams); |
|
322 | + } |
|
323 | + } |
|
324 | 324 | |
325 | - /** |
|
326 | - * run the error http page |
|
327 | - * |
|
328 | - * @access public |
|
329 | - * @param int iError http error |
|
330 | - * @return void |
|
331 | - */ |
|
332 | - public function runHttpErrorPage(int $iError) |
|
333 | - { |
|
334 | - $this->_create_constant(); |
|
325 | + /** |
|
326 | + * run the error http page |
|
327 | + * |
|
328 | + * @access public |
|
329 | + * @param int iError http error |
|
330 | + * @return void |
|
331 | + */ |
|
332 | + public function runHttpErrorPage(int $iError) |
|
333 | + { |
|
334 | + $this->_create_constant(); |
|
335 | 335 | |
336 | - if (isset($_SERVER) && isset($_SERVER['HTTP_HOST'])) { |
|
336 | + if (isset($_SERVER) && isset($_SERVER['HTTP_HOST'])) { |
|
337 | 337 | |
338 | - foreach (Config::get('Route') as $sHost => $oHost) { |
|
338 | + foreach (Config::get('Route') as $sHost => $oHost) { |
|
339 | 339 | |
340 | - if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) |
|
341 | - || (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
|
340 | + if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) |
|
341 | + || (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
|
342 | 342 | |
343 | - $this->_oRoutes = $oHost->routes; |
|
343 | + $this->_oRoutes = $oHost->routes; |
|
344 | 344 | |
345 | - if (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) { |
|
345 | + if (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) { |
|
346 | 346 | |
347 | - $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
|
348 | - } |
|
347 | + $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
|
348 | + } |
|
349 | 349 | |
350 | - $sHttpErrorPageName = '_getPage'.iError; |
|
351 | - $this->$sHttpErrorPageName(); |
|
352 | - } |
|
353 | - } |
|
354 | - } |
|
355 | - } |
|
350 | + $sHttpErrorPageName = '_getPage'.iError; |
|
351 | + $this->$sHttpErrorPageName(); |
|
352 | + } |
|
353 | + } |
|
354 | + } |
|
355 | + } |
|
356 | 356 | |
357 | - /** |
|
358 | - * load a route |
|
359 | - * |
|
360 | - * @access private |
|
361 | - * @param \stdClass $oRoute one route |
|
362 | - * @param string $RequestUri URI |
|
363 | - * @return void |
|
364 | - */ |
|
365 | - private function _route(\stdClass $oRoute, string $RequestUri) |
|
366 | - { |
|
367 | - $sCharset = 'UTF-8'; |
|
357 | + /** |
|
358 | + * load a route |
|
359 | + * |
|
360 | + * @access private |
|
361 | + * @param \stdClass $oRoute one route |
|
362 | + * @param string $RequestUri URI |
|
363 | + * @return void |
|
364 | + */ |
|
365 | + private function _route(\stdClass $oRoute, string $RequestUri) |
|
366 | + { |
|
367 | + $sCharset = 'UTF-8'; |
|
368 | 368 | |
369 | - if (isset($oRoute->route)) { |
|
369 | + if (isset($oRoute->route)) { |
|
370 | 370 | |
371 | - $sRoute = str_replace("*", ".*", $oRoute->route); |
|
371 | + $sRoute = str_replace("*", ".*", $oRoute->route); |
|
372 | 372 | |
373 | - $sFinalRoute = preg_replace_callback( |
|
374 | - '|\[/{0,1}:([a-zA-Z_]+)\]|', |
|
375 | - function($aMatches) use ($oRoute) { |
|
376 | - return "/{0,1}(?P<".$aMatches[1].">".$oRoute->constraints->{$aMatches[1]}.")"; |
|
377 | - }, |
|
378 | - $sRoute |
|
379 | - ); |
|
380 | - } |
|
381 | - else { |
|
373 | + $sFinalRoute = preg_replace_callback( |
|
374 | + '|\[/{0,1}:([a-zA-Z_]+)\]|', |
|
375 | + function($aMatches) use ($oRoute) { |
|
376 | + return "/{0,1}(?P<".$aMatches[1].">".$oRoute->constraints->{$aMatches[1]}.")"; |
|
377 | + }, |
|
378 | + $sRoute |
|
379 | + ); |
|
380 | + } |
|
381 | + else { |
|
382 | 382 | |
383 | - $sFinalRoute = '.*'; |
|
384 | - } |
|
383 | + $sFinalRoute = '.*'; |
|
384 | + } |
|
385 | 385 | |
386 | - $RequestUri = preg_replace('/^([^?]+)\?.*$/', '$1', $RequestUri); |
|
387 | - $RequestUri = preg_replace('#^'.$this->_sBaseUri.'#', '', $RequestUri); |
|
386 | + $RequestUri = preg_replace('/^([^?]+)\?.*$/', '$1', $RequestUri); |
|
387 | + $RequestUri = preg_replace('#^'.$this->_sBaseUri.'#', '', $RequestUri); |
|
388 | 388 | |
389 | - if (preg_match('#^'.$sFinalRoute.'$#', $RequestUri, $aMatch)) { |
|
389 | + if (preg_match('#^'.$sFinalRoute.'$#', $RequestUri, $aMatch)) { |
|
390 | 390 | |
391 | - if (isset($oRoute->location)) { |
|
391 | + if (isset($oRoute->location)) { |
|
392 | 392 | |
393 | - $aParamEntries = array(); |
|
393 | + $aParamEntries = array(); |
|
394 | 394 | |
395 | - foreach ($oRoute->constraints as $sName => $sType) { |
|
395 | + foreach ($oRoute->constraints as $sName => $sType) { |
|
396 | 396 | |
397 | - if (isset($aMatch[$sName])) { |
|
397 | + if (isset($aMatch[$sName])) { |
|
398 | 398 | |
399 | - $aParamEntries[$sName] = $aMatch[$sName]; |
|
400 | - } |
|
401 | - } |
|
399 | + $aParamEntries[$sName] = $aMatch[$sName]; |
|
400 | + } |
|
401 | + } |
|
402 | 402 | |
403 | - $oUrlManager = new UrlManager; |
|
404 | - header('Status: 301 Moved Permanently', false, 301); |
|
405 | - header('Location: '.$oUrlManager->getUrl($oRoute->location, $aParamEntries)); |
|
406 | - exit; |
|
407 | - } |
|
403 | + $oUrlManager = new UrlManager; |
|
404 | + header('Status: 301 Moved Permanently', false, 301); |
|
405 | + header('Location: '.$oUrlManager->getUrl($oRoute->location, $aParamEntries)); |
|
406 | + exit; |
|
407 | + } |
|
408 | 408 | |
409 | - $this->_oSecurity = new Security; |
|
409 | + $this->_oSecurity = new Security; |
|
410 | 410 | |
411 | - if (!$this->_oSecurity->checkSecurity() !== null) { return 403; } |
|
411 | + if (!$this->_oSecurity->checkSecurity() !== null) { return 403; } |
|
412 | 412 | |
413 | - // create the $_GET by the URL |
|
413 | + // create the $_GET by the URL |
|
414 | 414 | |
415 | - foreach ($aMatch as $mKey => $sResults) { |
|
415 | + foreach ($aMatch as $mKey => $sResults) { |
|
416 | 416 | |
417 | - if (is_string($mKey)) { |
|
417 | + if (is_string($mKey)) { |
|
418 | 418 | |
419 | - $_GET[$mKey] = $sResults; |
|
420 | - } |
|
421 | - } |
|
419 | + $_GET[$mKey] = $sResults; |
|
420 | + } |
|
421 | + } |
|
422 | 422 | |
423 | - if (isset($oRoute->methods) && $oRoute->methods != $_SERVER['REQUEST_METHOD']) { return false; } |
|
423 | + if (isset($oRoute->methods) && $oRoute->methods != $_SERVER['REQUEST_METHOD']) { return false; } |
|
424 | 424 | |
425 | - if (isset($oRoute->schemes) && $oRoute->schemes == 'https' && !Request::isHttpsRequest()) { return false; } |
|
425 | + if (isset($oRoute->schemes) && $oRoute->schemes == 'https' && !Request::isHttpsRequest()) { return false; } |
|
426 | 426 | |
427 | - if (isset($oRoute->cache) && isset($oRoute->cache->max_age) && !isset($_GET['flush'])) { |
|
427 | + if (isset($oRoute->cache) && isset($oRoute->cache->max_age) && !isset($_GET['flush'])) { |
|
428 | 428 | |
429 | - $oMobileDetect = new \Mobile_Detect; |
|
429 | + $oMobileDetect = new \Mobile_Detect; |
|
430 | 430 | |
431 | - if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } |
|
432 | - else { $sCacheExt = ''; } |
|
431 | + if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } |
|
432 | + else { $sCacheExt = ''; } |
|
433 | 433 | |
434 | - $mCacheReturn = Cache::get($RequestUri.$sCacheExt, $oRoute->cache->max_age); |
|
434 | + $mCacheReturn = Cache::get($RequestUri.$sCacheExt, $oRoute->cache->max_age); |
|
435 | 435 | |
436 | - if ($mCacheReturn && count($_POST) < 1) { |
|
436 | + if ($mCacheReturn && count($_POST) < 1) { |
|
437 | 437 | |
438 | - echo $mCacheReturn; |
|
439 | - return true; |
|
440 | - } |
|
441 | - } |
|
438 | + echo $mCacheReturn; |
|
439 | + return true; |
|
440 | + } |
|
441 | + } |
|
442 | 442 | |
443 | - if (isset($oRoute->cache)) { $this->_checkCache($oRoute->cache); } |
|
443 | + if (isset($oRoute->cache)) { $this->_checkCache($oRoute->cache); } |
|
444 | 444 | |
445 | - if (isset($oRoute->controller)) { |
|
445 | + if (isset($oRoute->controller)) { |
|
446 | 446 | |
447 | - define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->controller)); |
|
448 | - set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
447 | + define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->controller)); |
|
448 | + set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
449 | 449 | |
450 | - if (isset($oRoute->content_type)) { |
|
450 | + if (isset($oRoute->content_type)) { |
|
451 | 451 | |
452 | - if ($oRoute->content_type == 'json') { |
|
452 | + if ($oRoute->content_type == 'json') { |
|
453 | 453 | |
454 | - header('Content-type: application/json; charset='.$sCharset.''); |
|
455 | - } else if ($oRoute->content_type == 'html') { |
|
454 | + header('Content-type: application/json; charset='.$sCharset.''); |
|
455 | + } else if ($oRoute->content_type == 'html') { |
|
456 | 456 | |
457 | - header('Content-type: text/html; charset='.$sCharset.''); |
|
458 | - } else if ($oRoute->content_type == 'jpeg') { |
|
457 | + header('Content-type: text/html; charset='.$sCharset.''); |
|
458 | + } else if ($oRoute->content_type == 'jpeg') { |
|
459 | 459 | |
460 | - header('Content-type: image/jpeg'); |
|
461 | - } |
|
462 | - } |
|
463 | - else { |
|
460 | + header('Content-type: image/jpeg'); |
|
461 | + } |
|
462 | + } |
|
463 | + else { |
|
464 | 464 | |
465 | - header('Content-type: text/html; charset='.$sCharset.''); |
|
466 | - } |
|
465 | + header('Content-type: text/html; charset='.$sCharset.''); |
|
466 | + } |
|
467 | 467 | |
468 | - $sControllerName = $oRoute->controller; |
|
469 | - $sActionName = $oRoute->action; |
|
468 | + $sControllerName = $oRoute->controller; |
|
469 | + $sActionName = $oRoute->action; |
|
470 | 470 | |
471 | - $oController = new $sControllerName; |
|
471 | + $oController = new $sControllerName; |
|
472 | 472 | |
473 | - $aEntries = array(); |
|
473 | + $aEntries = array(); |
|
474 | 474 | |
475 | - if (isset($oRoute->constraints) && is_object($oRoute->constraints)) { |
|
475 | + if (isset($oRoute->constraints) && is_object($oRoute->constraints)) { |
|
476 | 476 | |
477 | - $mReturn = null; |
|
477 | + $mReturn = null; |
|
478 | 478 | |
479 | - foreach ($oRoute->constraints as $sName => $sType) { |
|
479 | + foreach ($oRoute->constraints as $sName => $sType) { |
|
480 | 480 | |
481 | - if (isset($_GET[$sName]) && $_GET[$sName] != '') { |
|
481 | + if (isset($_GET[$sName]) && $_GET[$sName] != '') { |
|
482 | 482 | |
483 | - $aEntries[] = $_GET[$sName]; |
|
484 | - } else if (isset($oRoute->defaults_constraints) && is_object($oRoute->defaults_constraints) |
|
485 | - && isset($oRoute->defaults_constraints->{$sName})) { |
|
483 | + $aEntries[] = $_GET[$sName]; |
|
484 | + } else if (isset($oRoute->defaults_constraints) && is_object($oRoute->defaults_constraints) |
|
485 | + && isset($oRoute->defaults_constraints->{$sName})) { |
|
486 | 486 | |
487 | - $aEntries[] = $oRoute->defaults_constraints->{$sName}; |
|
488 | - } else if (isset($_GET[$sName])) { |
|
487 | + $aEntries[] = $oRoute->defaults_constraints->{$sName}; |
|
488 | + } else if (isset($_GET[$sName])) { |
|
489 | 489 | |
490 | - $aEntries[] = $_GET[$sName]; |
|
491 | - } else if (preg_match('/'.$sType.'/', '')) { |
|
490 | + $aEntries[] = $_GET[$sName]; |
|
491 | + } else if (preg_match('/'.$sType.'/', '')) { |
|
492 | 492 | |
493 | - $aEntries[] = ''; |
|
494 | - } else { |
|
493 | + $aEntries[] = ''; |
|
494 | + } else { |
|
495 | 495 | |
496 | - $this->_oLogger->warning('Error: Parameter '.$sName.' not exists!'); |
|
497 | - break; |
|
498 | - } |
|
499 | - } |
|
496 | + $this->_oLogger->warning('Error: Parameter '.$sName.' not exists!'); |
|
497 | + break; |
|
498 | + } |
|
499 | + } |
|
500 | 500 | |
501 | - if ($mReturn === null) { |
|
501 | + if ($mReturn === null) { |
|
502 | 502 | |
503 | - $mReturn = $this->_loadController($oController, $sActionName, $aEntries); |
|
503 | + $mReturn = $this->_loadController($oController, $sActionName, $aEntries); |
|
504 | 504 | |
505 | - } |
|
506 | - } |
|
507 | - else { |
|
505 | + } |
|
506 | + } |
|
507 | + else { |
|
508 | 508 | |
509 | - $mReturn = $this->_loadController($oController, $sActionName, $aEntries); |
|
510 | - } |
|
509 | + $mReturn = $this->_loadController($oController, $sActionName, $aEntries); |
|
510 | + } |
|
511 | 511 | |
512 | - if (isset($oRoute->content_type)) { |
|
512 | + if (isset($oRoute->content_type)) { |
|
513 | 513 | |
514 | - if ($oRoute->content_type === 'json') { |
|
514 | + if ($oRoute->content_type === 'json') { |
|
515 | 515 | |
516 | - $mReturn = json_encode($mReturn, JSON_PRETTY_PRINT); |
|
517 | - } |
|
518 | - } |
|
519 | - } |
|
520 | - else if (isset($oRoute->template) && isset($oRoute->layout) && $oRoute->layout === true) { |
|
516 | + $mReturn = json_encode($mReturn, JSON_PRETTY_PRINT); |
|
517 | + } |
|
518 | + } |
|
519 | + } |
|
520 | + else if (isset($oRoute->template) && isset($oRoute->layout) && $oRoute->layout === true) { |
|
521 | 521 | |
522 | - define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->template)); |
|
523 | - set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
522 | + define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->template)); |
|
523 | + set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
524 | 524 | |
525 | - $oLayout = Vendor::getVendor('Apollina\Template', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.'Layout.tpl'); |
|
525 | + $oLayout = Vendor::getVendor('Apollina\Template', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.'Layout.tpl'); |
|
526 | 526 | |
527 | - if (isset($oRoute->vars)) { |
|
527 | + if (isset($oRoute->vars)) { |
|
528 | 528 | |
529 | - foreach ($oRoute->vars as $sKey => $mValue) { |
|
529 | + foreach ($oRoute->vars as $sKey => $mValue) { |
|
530 | 530 | |
531 | - $oLayout->assign($sKey, $mValue); |
|
532 | - } |
|
533 | - } |
|
531 | + $oLayout->assign($sKey, $mValue); |
|
532 | + } |
|
533 | + } |
|
534 | 534 | |
535 | - $mReturn = $oLayout->assign('model', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.$oRoute->template.'.tpl') |
|
536 | - ->fetch(); |
|
537 | - } |
|
538 | - else if (isset($oRoute->template)) { |
|
535 | + $mReturn = $oLayout->assign('model', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.$oRoute->template.'.tpl') |
|
536 | + ->fetch(); |
|
537 | + } |
|
538 | + else if (isset($oRoute->template)) { |
|
539 | 539 | |
540 | - define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->template)); |
|
541 | - set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
540 | + define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->template)); |
|
541 | + set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
542 | 542 | |
543 | - $oTemplate = Vendor::getVendor('Apollina\Template', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.$oRoute->template.'.tpl'); |
|
543 | + $oTemplate = Vendor::getVendor('Apollina\Template', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.$oRoute->template.'.tpl'); |
|
544 | 544 | |
545 | - if (isset($oRoute->vars)) { |
|
545 | + if (isset($oRoute->vars)) { |
|
546 | 546 | |
547 | - foreach ($oRoute->vars as $sKey => $mValue) { |
|
547 | + foreach ($oRoute->vars as $sKey => $mValue) { |
|
548 | 548 | |
549 | - $oTemplate->assign($sKey, $mValue); |
|
550 | - } |
|
551 | - } |
|
549 | + $oTemplate->assign($sKey, $mValue); |
|
550 | + } |
|
551 | + } |
|
552 | 552 | |
553 | - $mReturn = $oTemplate->fetch(); |
|
554 | - } |
|
553 | + $mReturn = $oTemplate->fetch(); |
|
554 | + } |
|
555 | 555 | |
556 | - // management of return or cache of it |
|
556 | + // management of return or cache of it |
|
557 | 557 | |
558 | - if (isset($oRoute->cache) && isset($oRoute->cache->max_age) && $mReturn) { |
|
558 | + if (isset($oRoute->cache) && isset($oRoute->cache->max_age) && $mReturn) { |
|
559 | 559 | |
560 | - $oMobileDetect = new \Mobile_Detect; |
|
560 | + $oMobileDetect = new \Mobile_Detect; |
|
561 | 561 | |
562 | - if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } |
|
563 | - else { $sCacheExt = ''; } |
|
562 | + if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } |
|
563 | + else { $sCacheExt = ''; } |
|
564 | 564 | |
565 | - if (defined('COMPRESS_HTML') && COMPRESS_HTML) { |
|
565 | + if (defined('COMPRESS_HTML') && COMPRESS_HTML) { |
|
566 | 566 | |
567 | - $mReturn = str_replace(array("\t", "\r", " "), array("", "", " "), $mReturn); |
|
568 | - } |
|
567 | + $mReturn = str_replace(array("\t", "\r", " "), array("", "", " "), $mReturn); |
|
568 | + } |
|
569 | 569 | |
570 | - Cache::set($RequestUri.$sCacheExt, $mReturn, $oRoute->cache->max_age); |
|
571 | - } |
|
570 | + Cache::set($RequestUri.$sCacheExt, $mReturn, $oRoute->cache->max_age); |
|
571 | + } |
|
572 | 572 | |
573 | - if ($mReturn) { |
|
573 | + if ($mReturn) { |
|
574 | 574 | |
575 | - echo $mReturn; |
|
576 | - return true; |
|
577 | - } |
|
578 | - } |
|
579 | - } |
|
575 | + echo $mReturn; |
|
576 | + return true; |
|
577 | + } |
|
578 | + } |
|
579 | + } |
|
580 | 580 | |
581 | - /** |
|
582 | - * create the constants |
|
583 | - * |
|
584 | - * @access private |
|
585 | - * @return void |
|
586 | - */ |
|
587 | - private function _create_constant() |
|
588 | - { |
|
589 | - foreach (Config::get('Const') as $sKey => $mValue) { |
|
581 | + /** |
|
582 | + * create the constants |
|
583 | + * |
|
584 | + * @access private |
|
585 | + * @return void |
|
586 | + */ |
|
587 | + private function _create_constant() |
|
588 | + { |
|
589 | + foreach (Config::get('Const') as $sKey => $mValue) { |
|
590 | 590 | |
591 | - if (is_string($mValue) || is_int($mValue) || is_float($mValue) || is_bool($mValue)) { |
|
591 | + if (is_string($mValue) || is_int($mValue) || is_float($mValue) || is_bool($mValue)) { |
|
592 | 592 | |
593 | - define(strtoupper($sKey), $mValue); |
|
594 | - } |
|
595 | - } |
|
596 | - } |
|
593 | + define(strtoupper($sKey), $mValue); |
|
594 | + } |
|
595 | + } |
|
596 | + } |
|
597 | 597 | |
598 | - /** |
|
599 | - * load the controller |
|
600 | - * |
|
601 | - * @access private |
|
602 | - * @param object $oControllerName controller name |
|
603 | - * @param string $sActionName method name |
|
604 | - * @param array $aParams parameters |
|
605 | - * @return mixed |
|
606 | - */ |
|
607 | - private function _loadController($oControllerName, string $sActionName, array $aParams = array()) |
|
608 | - { |
|
609 | - $aPhpDoc = PhpDoc::getPhpDocOfMethod($oControllerName, $sActionName); |
|
598 | + /** |
|
599 | + * load the controller |
|
600 | + * |
|
601 | + * @access private |
|
602 | + * @param object $oControllerName controller name |
|
603 | + * @param string $sActionName method name |
|
604 | + * @param array $aParams parameters |
|
605 | + * @return mixed |
|
606 | + */ |
|
607 | + private function _loadController($oControllerName, string $sActionName, array $aParams = array()) |
|
608 | + { |
|
609 | + $aPhpDoc = PhpDoc::getPhpDocOfMethod($oControllerName, $sActionName); |
|
610 | 610 | |
611 | - if (isset($aPhpDoc['Cache'])) { |
|
611 | + if (isset($aPhpDoc['Cache'])) { |
|
612 | 612 | |
613 | - if (!isset($aPhpDoc['Cache']['maxage'])) { $aPhpDoc['Cache']['maxage'] = 0; } |
|
613 | + if (!isset($aPhpDoc['Cache']['maxage'])) { $aPhpDoc['Cache']['maxage'] = 0; } |
|
614 | 614 | |
615 | - $oMobileDetect = new \Mobile_Detect; |
|
615 | + $oMobileDetect = new \Mobile_Detect; |
|
616 | 616 | |
617 | - if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } |
|
618 | - else { $sCacheExt = ''; } |
|
617 | + if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } |
|
618 | + else { $sCacheExt = ''; } |
|
619 | 619 | |
620 | - $mCacheReturn = Cache::get($sActionName.$sCacheExt, $aPhpDoc['Cache']['maxage']); |
|
620 | + $mCacheReturn = Cache::get($sActionName.$sCacheExt, $aPhpDoc['Cache']['maxage']); |
|
621 | 621 | |
622 | - if ($mCacheReturn !== false) { return $mCacheReturn; } |
|
623 | - } |
|
622 | + if ($mCacheReturn !== false) { return $mCacheReturn; } |
|
623 | + } |
|
624 | 624 | |
625 | - if (isset($aPhpDoc['Secure'])) { |
|
625 | + if (isset($aPhpDoc['Secure'])) { |
|
626 | 626 | |
627 | - if (isset($aPhpDoc['Secure']['roles']) && $this->_oSecurity->getUserRole() != $aPhpDoc['Secure']['roles']) { |
|
627 | + if (isset($aPhpDoc['Secure']['roles']) && $this->_oSecurity->getUserRole() != $aPhpDoc['Secure']['roles']) { |
|
628 | 628 | |
629 | - $this->_getPage403(); |
|
630 | - } |
|
631 | - } |
|
629 | + $this->_getPage403(); |
|
630 | + } |
|
631 | + } |
|
632 | 632 | |
633 | - $oController = new $oControllerName; |
|
633 | + $oController = new $oControllerName; |
|
634 | 634 | |
635 | - ob_start(); |
|
635 | + ob_start(); |
|
636 | 636 | |
637 | - if (!defined('PORTAL')) { define('PORTAL', 'Batch'); } |
|
637 | + if (!defined('PORTAL')) { define('PORTAL', 'Batch'); } |
|
638 | 638 | |
639 | - if (method_exists($oController, 'beforeExecuteRoute')) { |
|
639 | + if (method_exists($oController, 'beforeExecuteRoute')) { |
|
640 | 640 | |
641 | - call_user_func_array(array($oController, 'beforeExecuteRoute'), array()); |
|
642 | - } |
|
641 | + call_user_func_array(array($oController, 'beforeExecuteRoute'), array()); |
|
642 | + } |
|
643 | 643 | |
644 | - $mReturnController = call_user_func_array(array($oController, $sActionName), $aParams); |
|
644 | + $mReturnController = call_user_func_array(array($oController, $sActionName), $aParams); |
|
645 | 645 | |
646 | - if (method_exists($oController, 'afterExecuteRoute')) { |
|
646 | + if (method_exists($oController, 'afterExecuteRoute')) { |
|
647 | 647 | |
648 | - call_user_func_array(array($oController, 'afterExecuteRoute'), array()); |
|
649 | - } |
|
648 | + call_user_func_array(array($oController, 'afterExecuteRoute'), array()); |
|
649 | + } |
|
650 | 650 | |
651 | - $mReturn = ob_get_clean(); |
|
651 | + $mReturn = ob_get_clean(); |
|
652 | 652 | |
653 | - if ($mReturn == '') { $mReturn = $mReturnController; } |
|
653 | + if ($mReturn == '') { $mReturn = $mReturnController; } |
|
654 | 654 | |
655 | - if (isset($aPhpDoc['Cache'])) { |
|
655 | + if (isset($aPhpDoc['Cache'])) { |
|
656 | 656 | |
657 | - $oMobileDetect = new \Mobile_Detect; |
|
657 | + $oMobileDetect = new \Mobile_Detect; |
|
658 | 658 | |
659 | - if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } |
|
660 | - else { $sCacheExt = ''; } |
|
659 | + if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } |
|
660 | + else { $sCacheExt = ''; } |
|
661 | 661 | |
662 | - if (defined('COMPRESS_HTML') && COMPRESS_HTML) { |
|
662 | + if (defined('COMPRESS_HTML') && COMPRESS_HTML) { |
|
663 | 663 | |
664 | - $mReturn = str_replace(array("\t", "\r", " "), array("", "", "", " "), $mReturn); |
|
665 | - } |
|
664 | + $mReturn = str_replace(array("\t", "\r", " "), array("", "", "", " "), $mReturn); |
|
665 | + } |
|
666 | 666 | |
667 | - Cache::set($sActionName.$sCacheExt, $mReturn, $aPhpDoc['Cache']['maxage']); |
|
668 | - } |
|
667 | + Cache::set($sActionName.$sCacheExt, $mReturn, $aPhpDoc['Cache']['maxage']); |
|
668 | + } |
|
669 | 669 | |
670 | - return $mReturn; |
|
671 | - } |
|
670 | + return $mReturn; |
|
671 | + } |
|
672 | 672 | |
673 | - /** |
|
674 | - * get the page 403 |
|
675 | - * |
|
676 | - * @access private |
|
677 | - * @return void |
|
678 | - */ |
|
679 | - private function _getPage403() |
|
680 | - { |
|
681 | - header("HTTP/1.0 403 Forbidden"); |
|
673 | + /** |
|
674 | + * get the page 403 |
|
675 | + * |
|
676 | + * @access private |
|
677 | + * @return void |
|
678 | + */ |
|
679 | + private function _getPage403() |
|
680 | + { |
|
681 | + header("HTTP/1.0 403 Forbidden"); |
|
682 | 682 | |
683 | - if (isset($this->_oRoutes->e403)) { |
|
683 | + if (isset($this->_oRoutes->e403)) { |
|
684 | 684 | |
685 | - $this->_oRoutes->e403->route = '/'; |
|
686 | - $_SERVER['REQUEST_URI'] = '/'; |
|
687 | - $this->_route($this->_oRoutes->e403, $_SERVER['REQUEST_URI']); |
|
688 | - } |
|
685 | + $this->_oRoutes->e403->route = '/'; |
|
686 | + $_SERVER['REQUEST_URI'] = '/'; |
|
687 | + $this->_route($this->_oRoutes->e403, $_SERVER['REQUEST_URI']); |
|
688 | + } |
|
689 | 689 | |
690 | - exit; |
|
691 | - } |
|
690 | + exit; |
|
691 | + } |
|
692 | 692 | |
693 | - /** |
|
694 | - * get the page 404 |
|
695 | - * |
|
696 | - * @access private |
|
697 | - * @return void |
|
698 | - */ |
|
699 | - private function _getPage404() |
|
700 | - { |
|
701 | - header("HTTP/1.0 404 Not Found"); |
|
693 | + /** |
|
694 | + * get the page 404 |
|
695 | + * |
|
696 | + * @access private |
|
697 | + * @return void |
|
698 | + */ |
|
699 | + private function _getPage404() |
|
700 | + { |
|
701 | + header("HTTP/1.0 404 Not Found"); |
|
702 | 702 | |
703 | - if (isset($this->_oRoutes->e404)) { |
|
703 | + if (isset($this->_oRoutes->e404)) { |
|
704 | 704 | |
705 | - $this->_oRoutes->e404->route = '/'; |
|
706 | - $_SERVER['REQUEST_URI'] = '/'; |
|
707 | - $this->_route($this->_oRoutes->e404, $_SERVER['REQUEST_URI']); |
|
708 | - } |
|
705 | + $this->_oRoutes->e404->route = '/'; |
|
706 | + $_SERVER['REQUEST_URI'] = '/'; |
|
707 | + $this->_route($this->_oRoutes->e404, $_SERVER['REQUEST_URI']); |
|
708 | + } |
|
709 | 709 | |
710 | - exit; |
|
711 | - } |
|
710 | + exit; |
|
711 | + } |
|
712 | 712 | |
713 | - /** |
|
714 | - * check the cache - just if it's not yet defined |
|
715 | - * |
|
716 | - * @access private |
|
717 | - * @param \stdClass $oCache object of cache configuration |
|
718 | - * @return void |
|
719 | - */ |
|
720 | - private function _checkCache(\stdClass $oCache) |
|
721 | - { |
|
722 | - /** |
|
723 | - * cache-control http |
|
724 | - */ |
|
713 | + /** |
|
714 | + * check the cache - just if it's not yet defined |
|
715 | + * |
|
716 | + * @access private |
|
717 | + * @param \stdClass $oCache object of cache configuration |
|
718 | + * @return void |
|
719 | + */ |
|
720 | + private function _checkCache(\stdClass $oCache) |
|
721 | + { |
|
722 | + /** |
|
723 | + * cache-control http |
|
724 | + */ |
|
725 | 725 | |
726 | - $sHearderValidity = false; |
|
727 | - $sHeader = "Cache-Control:"; |
|
726 | + $sHearderValidity = false; |
|
727 | + $sHeader = "Cache-Control:"; |
|
728 | 728 | |
729 | - if (isset($oCache->visibility) && ($oCache->visibility = 'public' || $oCache->visibility = 'private')) { |
|
729 | + if (isset($oCache->visibility) && ($oCache->visibility = 'public' || $oCache->visibility = 'private')) { |
|
730 | 730 | |
731 | - $sHearderValidity = true; |
|
732 | - $sHeader .= " ".$oCache->visibility.","; |
|
733 | - } |
|
731 | + $sHearderValidity = true; |
|
732 | + $sHeader .= " ".$oCache->visibility.","; |
|
733 | + } |
|
734 | 734 | |
735 | - if (isset($oCache->max_age)) { |
|
735 | + if (isset($oCache->max_age)) { |
|
736 | 736 | |
737 | - $sHearderValidity = true; |
|
738 | - $sHeader .= " maxage=".$oCache->max_age.","; |
|
739 | - } |
|
737 | + $sHearderValidity = true; |
|
738 | + $sHeader .= " maxage=".$oCache->max_age.","; |
|
739 | + } |
|
740 | 740 | |
741 | - if (isset($oCache->must_revalidate) && $oCache->must_revalidate === true) { |
|
741 | + if (isset($oCache->must_revalidate) && $oCache->must_revalidate === true) { |
|
742 | 742 | |
743 | - $sHearderValidity = true; |
|
744 | - $sHeader .= " must-revalidate,"; |
|
745 | - } |
|
743 | + $sHearderValidity = true; |
|
744 | + $sHeader .= " must-revalidate,"; |
|
745 | + } |
|
746 | 746 | |
747 | - if ($sHearderValidity === true) { |
|
747 | + if ($sHearderValidity === true) { |
|
748 | 748 | |
749 | - $sHeader = substr($sHeader, 0, -1); |
|
749 | + $sHeader = substr($sHeader, 0, -1); |
|
750 | 750 | |
751 | - if (!headers_sent()) { header($sHeader); } |
|
752 | - } |
|
751 | + if (!headers_sent()) { header($sHeader); } |
|
752 | + } |
|
753 | 753 | |
754 | - /** |
|
755 | - * ETag http |
|
756 | - */ |
|
754 | + /** |
|
755 | + * ETag http |
|
756 | + */ |
|
757 | 757 | |
758 | - if (isset($oCache->ETag)) { header("ETag: \"".$oCache->ETag."\""); } |
|
758 | + if (isset($oCache->ETag)) { header("ETag: \"".$oCache->ETag."\""); } |
|
759 | 759 | |
760 | - /** |
|
761 | - * expire |
|
762 | - */ |
|
760 | + /** |
|
761 | + * expire |
|
762 | + */ |
|
763 | 763 | |
764 | - if (isset($oCache->max_age)) { if (!headers_sent()) { header('Expires: '.gmdate('D, d M Y H:i:s', time() + $oCache->max_age).' GMT'); } } |
|
764 | + if (isset($oCache->max_age)) { if (!headers_sent()) { header('Expires: '.gmdate('D, d M Y H:i:s', time() + $oCache->max_age).' GMT'); } } |
|
765 | 765 | |
766 | - /** |
|
767 | - * Last-Modified http |
|
768 | - */ |
|
766 | + /** |
|
767 | + * Last-Modified http |
|
768 | + */ |
|
769 | 769 | |
770 | - if (isset($oCache->last_modified)) { if (!headers_sent()) { header('Last-Modified: '.gmdate('D, d M Y H:i:s', time() + $oCache->last_modified).' GMT'); } } |
|
770 | + if (isset($oCache->last_modified)) { if (!headers_sent()) { header('Last-Modified: '.gmdate('D, d M Y H:i:s', time() + $oCache->last_modified).' GMT'); } } |
|
771 | 771 | |
772 | - /** |
|
773 | - * vary http |
|
774 | - */ |
|
772 | + /** |
|
773 | + * vary http |
|
774 | + */ |
|
775 | 775 | |
776 | - if (isset($oCache->vary)) { header('Vary: '.$oCache->vary); } |
|
777 | - } |
|
776 | + if (isset($oCache->vary)) { header('Vary: '.$oCache->vary); } |
|
777 | + } |
|
778 | 778 | |
779 | - /** |
|
780 | - * Sets a logger instance on the object |
|
781 | - * |
|
782 | - * @access private |
|
783 | - * @param LoggerInterface $logger |
|
784 | - * @return null |
|
785 | - */ |
|
786 | - public function setLogger(LoggerInterface $logger) { |
|
779 | + /** |
|
780 | + * Sets a logger instance on the object |
|
781 | + * |
|
782 | + * @access private |
|
783 | + * @param LoggerInterface $logger |
|
784 | + * @return null |
|
785 | + */ |
|
786 | + public function setLogger(LoggerInterface $logger) { |
|
787 | 787 | |
788 | - $this->_oLogger = $logger; |
|
789 | - } |
|
788 | + $this->_oLogger = $logger; |
|
789 | + } |
|
790 | 790 | } |