@@ -1,90 +1,90 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 26 | - class DatabaseQueryRunner{ |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | + class DatabaseQueryRunner{ |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | - * The logger instance |
|
| 30 | - * @var object |
|
| 31 | - */ |
|
| 29 | + * The logger instance |
|
| 30 | + * @var object |
|
| 31 | + */ |
|
| 32 | 32 | private $logger = null; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * The last query result |
|
| 36 | - * @var object |
|
| 37 | - */ |
|
| 38 | - private $queryResult = null; |
|
| 34 | + /** |
|
| 35 | + * The last query result |
|
| 36 | + * @var object |
|
| 37 | + */ |
|
| 38 | + private $queryResult = null; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * The benchmark instance |
|
| 42 | - * @var object |
|
| 43 | - */ |
|
| 40 | + /** |
|
| 41 | + * The benchmark instance |
|
| 42 | + * @var object |
|
| 43 | + */ |
|
| 44 | 44 | private $benchmarkInstance = null; |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | - * The SQL query statment to execute |
|
| 48 | - * @var string |
|
| 49 | - */ |
|
| 47 | + * The SQL query statment to execute |
|
| 48 | + * @var string |
|
| 49 | + */ |
|
| 50 | 50 | private $query = null; |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | - * Indicate if we need return result as list (boolean) |
|
| 53 | + * Indicate if we need return result as list (boolean) |
|
| 54 | 54 | * or the data used to replace the placeholder (array) |
| 55 | - * @var array|boolean |
|
| 56 | - */ |
|
| 57 | - private $returnAsList = true; |
|
| 55 | + * @var array|boolean |
|
| 56 | + */ |
|
| 57 | + private $returnAsList = true; |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Indicate if we need return result as array or not |
|
| 62 | - * @var boolean |
|
| 63 | - */ |
|
| 64 | - private $returnAsArray = true; |
|
| 60 | + /** |
|
| 61 | + * Indicate if we need return result as array or not |
|
| 62 | + * @var boolean |
|
| 63 | + */ |
|
| 64 | + private $returnAsArray = true; |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * The last PDOStatment instance |
|
| 68 | - * @var object |
|
| 69 | - */ |
|
| 70 | - private $pdoStatment = null; |
|
| 66 | + /** |
|
| 67 | + * The last PDOStatment instance |
|
| 68 | + * @var object |
|
| 69 | + */ |
|
| 70 | + private $pdoStatment = null; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * The error returned for the last query |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - private $error = null; |
|
| 72 | + /** |
|
| 73 | + * The error returned for the last query |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + private $error = null; |
|
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * The PDO instance |
| 80 | 80 | * @var object |
| 81 | - */ |
|
| 81 | + */ |
|
| 82 | 82 | private $pdo = null; |
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * The database driver name used |
| 86 | 86 | * @var string |
| 87 | - */ |
|
| 87 | + */ |
|
| 88 | 88 | private $driver = null; |
| 89 | 89 | |
| 90 | 90 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){ |
| 100 | 100 | if (is_object($pdo)){ |
| 101 | - $this->pdo = $pdo; |
|
| 101 | + $this->pdo = $pdo; |
|
| 102 | 102 | } |
| 103 | 103 | $this->query = $query; |
| 104 | 104 | $this->returnAsList = $returnAsList; |
@@ -116,10 +116,10 @@ discard block |
||
| 116 | 116 | //reset instance |
| 117 | 117 | $this->reset(); |
| 118 | 118 | |
| 119 | - //for database query execution time |
|
| 119 | + //for database query execution time |
|
| 120 | 120 | $benchmarkMarkerKey = $this->getBenchmarkKey(); |
| 121 | 121 | if (! is_object($this->benchmarkInstance)){ |
| 122 | - $this->benchmarkInstance = & class_loader('Benchmark'); |
|
| 122 | + $this->benchmarkInstance = & class_loader('Benchmark'); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $this->logger->info('Execute SQL query [' . $this->query . ']'); |
@@ -132,101 +132,101 @@ discard block |
||
| 132 | 132 | $responseTime = $this->benchmarkInstance->elapsedTime( |
| 133 | 133 | 'DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', |
| 134 | 134 | 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')' |
| 135 | - ); |
|
| 136 | - //TODO use the configuration value for the high response time currently is 1 second |
|
| 135 | + ); |
|
| 136 | + //TODO use the configuration value for the high response time currently is 1 second |
|
| 137 | 137 | if ($responseTime >= 1 ){ |
| 138 | 138 | $this->logger->warning( |
| 139 | 139 | 'High response time while processing database query [' . $this->query . ']. |
| 140 | 140 | The response time is [' .$responseTime. '] sec.' |
| 141 | - ); |
|
| 141 | + ); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | if ($this->pdoStatment !== false){ |
| 145 | - $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false; |
|
| 146 | - if($isSqlSELECTQuery){ |
|
| 147 | - $this->setResultForSelect(); |
|
| 148 | - } |
|
| 149 | - else{ |
|
| 150 | - $this->setResultForNonSelect(); |
|
| 151 | - } |
|
| 152 | - return $this->queryResult; |
|
| 145 | + $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false; |
|
| 146 | + if($isSqlSELECTQuery){ |
|
| 147 | + $this->setResultForSelect(); |
|
| 148 | + } |
|
| 149 | + else{ |
|
| 150 | + $this->setResultForNonSelect(); |
|
| 151 | + } |
|
| 152 | + return $this->queryResult; |
|
| 153 | 153 | } |
| 154 | 154 | $this->setQueryRunnerError(); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * Return the result for SELECT query |
|
| 159 | - * @see DatabaseQueryRunner::execute |
|
| 160 | - */ |
|
| 157 | + /** |
|
| 158 | + * Return the result for SELECT query |
|
| 159 | + * @see DatabaseQueryRunner::execute |
|
| 160 | + */ |
|
| 161 | 161 | protected function setResultForSelect(){ |
| 162 | - //if need return all result like list of record |
|
| 163 | - $result = null; |
|
| 164 | - $numRows = 0; |
|
| 165 | - $fetchMode = PDO::FETCH_OBJ; |
|
| 166 | - if($this->returnAsArray){ |
|
| 162 | + //if need return all result like list of record |
|
| 163 | + $result = null; |
|
| 164 | + $numRows = 0; |
|
| 165 | + $fetchMode = PDO::FETCH_OBJ; |
|
| 166 | + if($this->returnAsArray){ |
|
| 167 | 167 | $fetchMode = PDO::FETCH_ASSOC; |
| 168 | - } |
|
| 169 | - if ($this->returnAsList){ |
|
| 170 | - $result = $this->pdoStatment->fetchAll($fetchMode); |
|
| 171 | - } |
|
| 172 | - else{ |
|
| 173 | - $result = $this->pdoStatment->fetch($fetchMode); |
|
| 174 | - } |
|
| 175 | - //Sqlite and pgsql always return 0 when using rowCount() |
|
| 176 | - if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
| 168 | + } |
|
| 169 | + if ($this->returnAsList){ |
|
| 170 | + $result = $this->pdoStatment->fetchAll($fetchMode); |
|
| 171 | + } |
|
| 172 | + else{ |
|
| 173 | + $result = $this->pdoStatment->fetch($fetchMode); |
|
| 174 | + } |
|
| 175 | + //Sqlite and pgsql always return 0 when using rowCount() |
|
| 176 | + if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
| 177 | 177 | $numRows = count($result); |
| 178 | - } |
|
| 179 | - else{ |
|
| 178 | + } |
|
| 179 | + else{ |
|
| 180 | 180 | $numRows = $this->pdoStatment->rowCount(); |
| 181 | - } |
|
| 182 | - if(! is_object($this->queryResult)){ |
|
| 183 | - $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
|
| 184 | - } |
|
| 185 | - $this->queryResult->setResult($result); |
|
| 186 | - $this->queryResult->setNumRows($numRows); |
|
| 181 | + } |
|
| 182 | + if(! is_object($this->queryResult)){ |
|
| 183 | + $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
|
| 184 | + } |
|
| 185 | + $this->queryResult->setResult($result); |
|
| 186 | + $this->queryResult->setNumRows($numRows); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
| 190 | - * Return the result for non SELECT query |
|
| 191 | - * @see DatabaseQueryRunner::execute |
|
| 192 | - */ |
|
| 190 | + * Return the result for non SELECT query |
|
| 191 | + * @see DatabaseQueryRunner::execute |
|
| 192 | + */ |
|
| 193 | 193 | protected function setResultForNonSelect(){ |
| 194 | - //Sqlite and pgsql always return 0 when using rowCount() |
|
| 195 | - $result = false; |
|
| 196 | - $numRows = 0; |
|
| 197 | - if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
| 194 | + //Sqlite and pgsql always return 0 when using rowCount() |
|
| 195 | + $result = false; |
|
| 196 | + $numRows = 0; |
|
| 197 | + if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
| 198 | 198 | $result = true; //to test the result for the query like UPDATE, INSERT, DELETE |
| 199 | 199 | $numRows = 1; //TODO use the correct method to get the exact affected row |
| 200 | - } |
|
| 201 | - else{ |
|
| 202 | - //to test the result for the query like UPDATE, INSERT, DELETE |
|
| 203 | - $result = $this->pdoStatment->rowCount() >= 0; |
|
| 204 | - $numRows = $this->pdoStatment->rowCount(); |
|
| 205 | - } |
|
| 206 | - if(! is_object($this->queryResult)){ |
|
| 207 | - $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
|
| 208 | - } |
|
| 209 | - $this->queryResult->setResult($result); |
|
| 210 | - $this->queryResult->setNumRows($numRows); |
|
| 200 | + } |
|
| 201 | + else{ |
|
| 202 | + //to test the result for the query like UPDATE, INSERT, DELETE |
|
| 203 | + $result = $this->pdoStatment->rowCount() >= 0; |
|
| 204 | + $numRows = $this->pdoStatment->rowCount(); |
|
| 205 | + } |
|
| 206 | + if(! is_object($this->queryResult)){ |
|
| 207 | + $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
|
| 208 | + } |
|
| 209 | + $this->queryResult->setResult($result); |
|
| 210 | + $this->queryResult->setNumRows($numRows); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | |
| 214 | - /** |
|
| 214 | + /** |
|
| 215 | 215 | * Return the benchmark instance |
| 216 | 216 | * @return Benchmark |
| 217 | 217 | */ |
| 218 | 218 | public function getBenchmark(){ |
| 219 | - return $this->benchmarkInstance; |
|
| 219 | + return $this->benchmarkInstance; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | 223 | * Set the benchmark instance |
| 224 | 224 | * @param Benchmark $benchmark the benchmark object |
| 225 | - * @return object DatabaseQueryRunner |
|
| 225 | + * @return object DatabaseQueryRunner |
|
| 226 | 226 | */ |
| 227 | 227 | public function setBenchmark($benchmark){ |
| 228 | - $this->benchmarkInstance = $benchmark; |
|
| 229 | - return $this; |
|
| 228 | + $this->benchmarkInstance = $benchmark; |
|
| 229 | + return $this; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -235,18 +235,18 @@ discard block |
||
| 235 | 235 | * @return object DatabaseQueryResult |
| 236 | 236 | */ |
| 237 | 237 | public function getQueryResult(){ |
| 238 | - return $this->queryResult; |
|
| 238 | + return $this->queryResult; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
| 242 | 242 | * Set the database query result instance |
| 243 | 243 | * @param object $queryResult the query result |
| 244 | 244 | * |
| 245 | - * @return object DatabaseQueryRunner |
|
| 245 | + * @return object DatabaseQueryRunner |
|
| 246 | 246 | */ |
| 247 | 247 | public function setQueryResult(DatabaseQueryResult $queryResult){ |
| 248 | - $this->queryResult = $queryResult; |
|
| 249 | - return $this; |
|
| 248 | + $this->queryResult = $queryResult; |
|
| 249 | + return $this; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -254,17 +254,17 @@ discard block |
||
| 254 | 254 | * @return Log |
| 255 | 255 | */ |
| 256 | 256 | public function getLogger(){ |
| 257 | - return $this->logger; |
|
| 257 | + return $this->logger; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
| 261 | 261 | * Set the log instance |
| 262 | 262 | * @param Log $logger the log object |
| 263 | - * @return object DatabaseQueryRunner |
|
| 263 | + * @return object DatabaseQueryRunner |
|
| 264 | 264 | */ |
| 265 | 265 | public function setLogger($logger){ |
| 266 | - $this->logger = $logger; |
|
| 267 | - return $this; |
|
| 266 | + $this->logger = $logger; |
|
| 267 | + return $this; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * @return string |
| 273 | 273 | */ |
| 274 | 274 | public function getQuery(){ |
| 275 | - return $this->query; |
|
| 275 | + return $this->query; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -281,8 +281,8 @@ discard block |
||
| 281 | 281 | * @return object DatabaseQueryRunner |
| 282 | 282 | */ |
| 283 | 283 | public function setQuery($query){ |
| 284 | - $this->query = $query; |
|
| 285 | - return $this; |
|
| 284 | + $this->query = $query; |
|
| 285 | + return $this; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -291,8 +291,8 @@ discard block |
||
| 291 | 291 | * @return object DatabaseQueryRunner |
| 292 | 292 | */ |
| 293 | 293 | public function setReturnType($returnType){ |
| 294 | - $this->returnAsList = $returnType; |
|
| 295 | - return $this; |
|
| 294 | + $this->returnAsList = $returnType; |
|
| 295 | + return $this; |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -301,8 +301,8 @@ discard block |
||
| 301 | 301 | * @return object DatabaseQueryRunner |
| 302 | 302 | */ |
| 303 | 303 | public function setReturnAsArray($status = true){ |
| 304 | - $this->returnAsArray = $status; |
|
| 305 | - return $this; |
|
| 304 | + $this->returnAsArray = $status; |
|
| 305 | + return $this; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return string |
| 311 | 311 | */ |
| 312 | 312 | public function getQueryError(){ |
| 313 | - return $this->error; |
|
| 313 | + return $this->error; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | * @return object |
| 319 | 319 | */ |
| 320 | 320 | public function getPdo(){ |
| 321 | - return $this->pdo; |
|
| 321 | + return $this->pdo; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -327,16 +327,16 @@ discard block |
||
| 327 | 327 | * @return object DatabaseQueryRunner |
| 328 | 328 | */ |
| 329 | 329 | public function setPdo(PDO $pdo = null){ |
| 330 | - $this->pdo = $pdo; |
|
| 331 | - return $this; |
|
| 330 | + $this->pdo = $pdo; |
|
| 331 | + return $this; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - /** |
|
| 335 | - * Return the database driver |
|
| 336 | - * @return string |
|
| 337 | - */ |
|
| 334 | + /** |
|
| 335 | + * Return the database driver |
|
| 336 | + * @return string |
|
| 337 | + */ |
|
| 338 | 338 | public function getDriver(){ |
| 339 | - return $this->driver; |
|
| 339 | + return $this->driver; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | * @return object DatabaseQueryRunner |
| 346 | 346 | */ |
| 347 | 347 | public function setDriver($driver){ |
| 348 | - $this->driver = $driver; |
|
| 349 | - return $this; |
|
| 348 | + $this->driver = $driver; |
|
| 349 | + return $this; |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -355,18 +355,18 @@ discard block |
||
| 355 | 355 | * @return string |
| 356 | 356 | */ |
| 357 | 357 | protected function getBenchmarkKey(){ |
| 358 | - return md5($this->query . $this->returnAsList . $this->returnAsArray); |
|
| 358 | + return md5($this->query . $this->returnAsList . $this->returnAsArray); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | 362 | * Set error for database query execution |
| 363 | 363 | */ |
| 364 | 364 | protected function setQueryRunnerError(){ |
| 365 | - $error = $this->pdo->errorInfo(); |
|
| 366 | - $this->error = isset($error[2]) ? $error[2] : ''; |
|
| 367 | - $this->logger->error('The database query execution got an error: ' . stringfy_vars($error)); |
|
| 368 | - //show error message |
|
| 369 | - show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error'); |
|
| 365 | + $error = $this->pdo->errorInfo(); |
|
| 366 | + $this->error = isset($error[2]) ? $error[2] : ''; |
|
| 367 | + $this->logger->error('The database query execution got an error: ' . stringfy_vars($error)); |
|
| 368 | + //show error message |
|
| 369 | + show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error'); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -374,19 +374,19 @@ discard block |
||
| 374 | 374 | * @param object $logger the Log instance if not null |
| 375 | 375 | */ |
| 376 | 376 | protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
| 377 | - if ($logger !== null){ |
|
| 377 | + if ($logger !== null){ |
|
| 378 | 378 | $this->logger = $logger; |
| 379 | - } |
|
| 380 | - else{ |
|
| 381 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 382 | - $this->logger->setLogger('Library::DatabaseQueryRunner'); |
|
| 383 | - } |
|
| 379 | + } |
|
| 380 | + else{ |
|
| 381 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 382 | + $this->logger->setLogger('Library::DatabaseQueryRunner'); |
|
| 383 | + } |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | |
| 387 | 387 | /** |
| 388 | - * Reset the instance before run each query |
|
| 389 | - */ |
|
| 388 | + * Reset the instance before run each query |
|
| 389 | + */ |
|
| 390 | 390 | private function reset(){ |
| 391 | 391 | $this->error = null; |
| 392 | 392 | $this->pdoStatment = null; |
@@ -1,75 +1,75 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @file function_user_agent.php |
|
| 30 | - * |
|
| 31 | - * Contains most of the utility functions for agent, platform, mobile, browser, and other management. |
|
| 32 | - * |
|
| 33 | - * @package core |
|
| 34 | - * @author Tony NGUEREZA |
|
| 35 | - * @copyright Copyright (c) 2017 |
|
| 36 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 37 | - * @link http://www.iacademy.cf |
|
| 38 | - * @version 1.0.0 |
|
| 39 | - * @since 1.0.0 |
|
| 40 | - * @filesource |
|
| 41 | - */ |
|
| 28 | + /** |
|
| 29 | + * @file function_user_agent.php |
|
| 30 | + * |
|
| 31 | + * Contains most of the utility functions for agent, platform, mobile, browser, and other management. |
|
| 32 | + * |
|
| 33 | + * @package core |
|
| 34 | + * @author Tony NGUEREZA |
|
| 35 | + * @copyright Copyright (c) 2017 |
|
| 36 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 37 | + * @link http://www.iacademy.cf |
|
| 38 | + * @version 1.0.0 |
|
| 39 | + * @since 1.0.0 |
|
| 40 | + * @filesource |
|
| 41 | + */ |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - if(! function_exists('get_ip')){ |
|
| 45 | - /** |
|
| 46 | - * Retrieves the user's IP address |
|
| 47 | - * |
|
| 48 | - * This function allows to retrieve the IP address of the client |
|
| 49 | - * even if it uses a proxy, the actual IP address is retrieved. |
|
| 50 | - * |
|
| 51 | - * @return string the IP address. |
|
| 52 | - */ |
|
| 53 | - function get_ip(){ |
|
| 54 | - $ip = '127.0.0.1'; |
|
| 55 | - $ipServerVars = array( |
|
| 56 | - 'REMOTE_ADDR', |
|
| 57 | - 'HTTP_CLIENT_IP', |
|
| 58 | - 'HTTP_X_FORWARDED_FOR', |
|
| 59 | - 'HTTP_X_FORWARDED', |
|
| 60 | - 'HTTP_FORWARDED_FOR', |
|
| 61 | - 'HTTP_FORWARDED' |
|
| 62 | - ); |
|
| 63 | - foreach ($ipServerVars as $var) { |
|
| 64 | - if(isset($_SERVER[$var])){ |
|
| 65 | - $ip = $_SERVER[$var]; |
|
| 66 | - break; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - // Strip any secondary IP etc from the IP address |
|
| 70 | - if (strpos($ip, ',') > 0) { |
|
| 71 | - $ip = substr($ip, 0, strpos($ip, ',')); |
|
| 72 | - } |
|
| 73 | - return $ip; |
|
| 74 | - } |
|
| 75 | - } |
|
| 44 | + if(! function_exists('get_ip')){ |
|
| 45 | + /** |
|
| 46 | + * Retrieves the user's IP address |
|
| 47 | + * |
|
| 48 | + * This function allows to retrieve the IP address of the client |
|
| 49 | + * even if it uses a proxy, the actual IP address is retrieved. |
|
| 50 | + * |
|
| 51 | + * @return string the IP address. |
|
| 52 | + */ |
|
| 53 | + function get_ip(){ |
|
| 54 | + $ip = '127.0.0.1'; |
|
| 55 | + $ipServerVars = array( |
|
| 56 | + 'REMOTE_ADDR', |
|
| 57 | + 'HTTP_CLIENT_IP', |
|
| 58 | + 'HTTP_X_FORWARDED_FOR', |
|
| 59 | + 'HTTP_X_FORWARDED', |
|
| 60 | + 'HTTP_FORWARDED_FOR', |
|
| 61 | + 'HTTP_FORWARDED' |
|
| 62 | + ); |
|
| 63 | + foreach ($ipServerVars as $var) { |
|
| 64 | + if(isset($_SERVER[$var])){ |
|
| 65 | + $ip = $_SERVER[$var]; |
|
| 66 | + break; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + // Strip any secondary IP etc from the IP address |
|
| 70 | + if (strpos($ip, ',') > 0) { |
|
| 71 | + $ip = substr($ip, 0, strpos($ip, ',')); |
|
| 72 | + } |
|
| 73 | + return $ip; |
|
| 74 | + } |
|
| 75 | + } |
|
@@ -1,168 +1,168 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @file Assets.php |
|
| 29 | - * |
|
| 30 | - * This class contains static methods for generating static content links (images, Javascript, CSS, etc.). |
|
| 31 | - * |
|
| 32 | - * @package core |
|
| 33 | - * @author Tony NGUEREZA |
|
| 34 | - * @copyright Copyright (c) 2017 |
|
| 35 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | - * @link http://www.iacademy.cf |
|
| 37 | - * @version 1.0.0 |
|
| 38 | - * @since 1.0.0 |
|
| 39 | - * @filesource |
|
| 40 | - */ |
|
| 41 | - class Assets{ |
|
| 27 | + /** |
|
| 28 | + * @file Assets.php |
|
| 29 | + * |
|
| 30 | + * This class contains static methods for generating static content links (images, Javascript, CSS, etc.). |
|
| 31 | + * |
|
| 32 | + * @package core |
|
| 33 | + * @author Tony NGUEREZA |
|
| 34 | + * @copyright Copyright (c) 2017 |
|
| 35 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | + * @link http://www.iacademy.cf |
|
| 37 | + * @version 1.0.0 |
|
| 38 | + * @since 1.0.0 |
|
| 39 | + * @filesource |
|
| 40 | + */ |
|
| 41 | + class Assets{ |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * The logger instance |
|
| 45 | - * @var object |
|
| 46 | - */ |
|
| 47 | - private static $logger; |
|
| 43 | + /** |
|
| 44 | + * The logger instance |
|
| 45 | + * @var object |
|
| 46 | + */ |
|
| 47 | + private static $logger; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * The signleton of the logger |
|
| 51 | - * @return Object the Log instance |
|
| 52 | - */ |
|
| 53 | - private static function getLogger(){ |
|
| 54 | - if(self::$logger == null){ |
|
| 55 | - //can't assign reference to static variable |
|
| 56 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 57 | - self::$logger[0]->setLogger('Library::Assets'); |
|
| 58 | - } |
|
| 59 | - return self::$logger[0]; |
|
| 60 | - } |
|
| 49 | + /** |
|
| 50 | + * The signleton of the logger |
|
| 51 | + * @return Object the Log instance |
|
| 52 | + */ |
|
| 53 | + private static function getLogger(){ |
|
| 54 | + if(self::$logger == null){ |
|
| 55 | + //can't assign reference to static variable |
|
| 56 | + self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 57 | + self::$logger[0]->setLogger('Library::Assets'); |
|
| 58 | + } |
|
| 59 | + return self::$logger[0]; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Generate the link of the assets file. |
|
| 65 | - * |
|
| 66 | - * Generates the absolute link of a file inside ASSETS_PATH folder. |
|
| 67 | - * For example : |
|
| 68 | - * echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css |
|
| 69 | - * Note: |
|
| 70 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 71 | - * |
|
| 72 | - * @param string $asset the name of the assets file path with the extension. |
|
| 73 | - * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
|
| 74 | - */ |
|
| 75 | - public static function path($asset){ |
|
| 76 | - $logger = self::getLogger(); |
|
| 77 | - $path = ASSETS_PATH . $asset; |
|
| 63 | + /** |
|
| 64 | + * Generate the link of the assets file. |
|
| 65 | + * |
|
| 66 | + * Generates the absolute link of a file inside ASSETS_PATH folder. |
|
| 67 | + * For example : |
|
| 68 | + * echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css |
|
| 69 | + * Note: |
|
| 70 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 71 | + * |
|
| 72 | + * @param string $asset the name of the assets file path with the extension. |
|
| 73 | + * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
|
| 74 | + */ |
|
| 75 | + public static function path($asset){ |
|
| 76 | + $logger = self::getLogger(); |
|
| 77 | + $path = ASSETS_PATH . $asset; |
|
| 78 | 78 | |
| 79 | - $logger->debug('Including the Assets file [' . $path . ']'); |
|
| 80 | - //Check if the file exists |
|
| 81 | - if(file_exists($path)){ |
|
| 82 | - $logger->info('Assets file [' . $path . '] included successfully'); |
|
| 83 | - return Url::base_url($path); |
|
| 84 | - } |
|
| 85 | - $logger->warning('Assets file [' . $path . '] does not exist'); |
|
| 86 | - return null; |
|
| 87 | - } |
|
| 79 | + $logger->debug('Including the Assets file [' . $path . ']'); |
|
| 80 | + //Check if the file exists |
|
| 81 | + if(file_exists($path)){ |
|
| 82 | + $logger->info('Assets file [' . $path . '] included successfully'); |
|
| 83 | + return Url::base_url($path); |
|
| 84 | + } |
|
| 85 | + $logger->warning('Assets file [' . $path . '] does not exist'); |
|
| 86 | + return null; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Generate the link of the css file. |
|
| 91 | - * |
|
| 92 | - * Generates the absolute link of a file containing the CSS style. |
|
| 93 | - * For example : |
|
| 94 | - * echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css |
|
| 95 | - * Note: |
|
| 96 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 97 | - * |
|
| 98 | - * @param string $path the name of the css file without the extension. |
|
| 99 | - * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
|
| 100 | - */ |
|
| 101 | - public static function css($path){ |
|
| 102 | - $logger = self::getLogger(); |
|
| 103 | - /* |
|
| 89 | + /** |
|
| 90 | + * Generate the link of the css file. |
|
| 91 | + * |
|
| 92 | + * Generates the absolute link of a file containing the CSS style. |
|
| 93 | + * For example : |
|
| 94 | + * echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css |
|
| 95 | + * Note: |
|
| 96 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 97 | + * |
|
| 98 | + * @param string $path the name of the css file without the extension. |
|
| 99 | + * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
|
| 100 | + */ |
|
| 101 | + public static function css($path){ |
|
| 102 | + $logger = self::getLogger(); |
|
| 103 | + /* |
|
| 104 | 104 | * if the file name contains the ".css" extension, replace it with |
| 105 | 105 | * an empty string for better processing. |
| 106 | 106 | */ |
| 107 | - $path = str_ireplace('.css', '', $path); |
|
| 108 | - $path = ASSETS_PATH . 'css/' . $path . '.css'; |
|
| 107 | + $path = str_ireplace('.css', '', $path); |
|
| 108 | + $path = ASSETS_PATH . 'css/' . $path . '.css'; |
|
| 109 | 109 | |
| 110 | - $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
|
| 111 | - //Check if the file exists |
|
| 112 | - if(file_exists($path)){ |
|
| 113 | - $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
|
| 114 | - return Url::base_url($path); |
|
| 115 | - } |
|
| 116 | - $logger->warning('Assets file [' . $path . '] for CSS does not exist'); |
|
| 117 | - return null; |
|
| 118 | - } |
|
| 110 | + $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
|
| 111 | + //Check if the file exists |
|
| 112 | + if(file_exists($path)){ |
|
| 113 | + $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
|
| 114 | + return Url::base_url($path); |
|
| 115 | + } |
|
| 116 | + $logger->warning('Assets file [' . $path . '] for CSS does not exist'); |
|
| 117 | + return null; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Generate the link of the javascript file. |
|
| 122 | - * |
|
| 123 | - * Generates the absolute link of a file containing the javascript. |
|
| 124 | - * For example : |
|
| 125 | - * echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js |
|
| 126 | - * Note: |
|
| 127 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 128 | - * |
|
| 129 | - * @param string $path the name of the javascript file without the extension. |
|
| 130 | - * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
|
| 131 | - */ |
|
| 132 | - public static function js($path){ |
|
| 133 | - $logger = self::getLogger(); |
|
| 134 | - $path = str_ireplace('.js', '', $path); |
|
| 135 | - $path = ASSETS_PATH . 'js/' . $path . '.js'; |
|
| 136 | - $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
|
| 137 | - if(file_exists($path)){ |
|
| 138 | - $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
|
| 139 | - return Url::base_url($path); |
|
| 140 | - } |
|
| 141 | - $logger->warning('Assets file [' . $path . '] for Javascript does not exist'); |
|
| 142 | - return null; |
|
| 143 | - } |
|
| 120 | + /** |
|
| 121 | + * Generate the link of the javascript file. |
|
| 122 | + * |
|
| 123 | + * Generates the absolute link of a file containing the javascript. |
|
| 124 | + * For example : |
|
| 125 | + * echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js |
|
| 126 | + * Note: |
|
| 127 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 128 | + * |
|
| 129 | + * @param string $path the name of the javascript file without the extension. |
|
| 130 | + * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
|
| 131 | + */ |
|
| 132 | + public static function js($path){ |
|
| 133 | + $logger = self::getLogger(); |
|
| 134 | + $path = str_ireplace('.js', '', $path); |
|
| 135 | + $path = ASSETS_PATH . 'js/' . $path . '.js'; |
|
| 136 | + $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
|
| 137 | + if(file_exists($path)){ |
|
| 138 | + $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
|
| 139 | + return Url::base_url($path); |
|
| 140 | + } |
|
| 141 | + $logger->warning('Assets file [' . $path . '] for Javascript does not exist'); |
|
| 142 | + return null; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Generate the link of the image file. |
|
| 147 | - * |
|
| 148 | - * Generates the absolute link of a file containing the image. |
|
| 149 | - * For example : |
|
| 150 | - * echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png |
|
| 151 | - * Note: |
|
| 152 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 153 | - * |
|
| 154 | - * @param string $path the name of the image file with the extension. |
|
| 155 | - * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
|
| 156 | - */ |
|
| 157 | - public static function img($path){ |
|
| 158 | - $logger = self::getLogger(); |
|
| 159 | - $path = ASSETS_PATH . 'images/' . $path; |
|
| 160 | - $logger->debug('Including the Assets file [' . $path . '] for image'); |
|
| 161 | - if(file_exists($path)){ |
|
| 162 | - $logger->info('Assets file [' . $path . '] for image included successfully'); |
|
| 163 | - return Url::base_url($path); |
|
| 164 | - } |
|
| 165 | - $logger->warning('Assets file [' . $path . '] for image does not exist'); |
|
| 166 | - return null; |
|
| 167 | - } |
|
| 168 | - } |
|
| 145 | + /** |
|
| 146 | + * Generate the link of the image file. |
|
| 147 | + * |
|
| 148 | + * Generates the absolute link of a file containing the image. |
|
| 149 | + * For example : |
|
| 150 | + * echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png |
|
| 151 | + * Note: |
|
| 152 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 153 | + * |
|
| 154 | + * @param string $path the name of the image file with the extension. |
|
| 155 | + * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
|
| 156 | + */ |
|
| 157 | + public static function img($path){ |
|
| 158 | + $logger = self::getLogger(); |
|
| 159 | + $path = ASSETS_PATH . 'images/' . $path; |
|
| 160 | + $logger->debug('Including the Assets file [' . $path . '] for image'); |
|
| 161 | + if(file_exists($path)){ |
|
| 162 | + $logger->info('Assets file [' . $path . '] for image included successfully'); |
|
| 163 | + return Url::base_url($path); |
|
| 164 | + } |
|
| 165 | + $logger->warning('Assets file [' . $path . '] for image does not exist'); |
|
| 166 | + return null; |
|
| 167 | + } |
|
| 168 | + } |
|
@@ -1,195 +1,195 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @file bootstrap.php |
|
| 29 | - * |
|
| 30 | - * Contains the loading process: loading of constants, common functions, libraries |
|
| 31 | - * configurations, etc |
|
| 32 | - * verification of the environment and the routing of the request. |
|
| 33 | - * |
|
| 34 | - * @package core |
|
| 35 | - * @author Tony NGUEREZA |
|
| 36 | - * @copyright Copyright (c) 2017 |
|
| 37 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 38 | - * @link http://www.iacademy.cf |
|
| 39 | - * @version 1.0.0 |
|
| 40 | - * @filesource |
|
| 41 | - */ |
|
| 27 | + /** |
|
| 28 | + * @file bootstrap.php |
|
| 29 | + * |
|
| 30 | + * Contains the loading process: loading of constants, common functions, libraries |
|
| 31 | + * configurations, etc |
|
| 32 | + * verification of the environment and the routing of the request. |
|
| 33 | + * |
|
| 34 | + * @package core |
|
| 35 | + * @author Tony NGUEREZA |
|
| 36 | + * @copyright Copyright (c) 2017 |
|
| 37 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 38 | + * @link http://www.iacademy.cf |
|
| 39 | + * @version 1.0.0 |
|
| 40 | + * @filesource |
|
| 41 | + */ |
|
| 42 | 42 | |
| 43 | - //if the application is running in CLI mode $_SESSION global variable is not available |
|
| 44 | - if(IS_CLI){ |
|
| 45 | - $_SESSION = array(); |
|
| 46 | - } |
|
| 43 | + //if the application is running in CLI mode $_SESSION global variable is not available |
|
| 44 | + if(IS_CLI){ |
|
| 45 | + $_SESSION = array(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * inclusion of global constants of the environment that contain : name of the framework, |
|
| 50 | - * version, release date, version of PHP required, etc. |
|
| 51 | - */ |
|
| 52 | - require_once CORE_PATH . 'constants.php'; |
|
| 48 | + /** |
|
| 49 | + * inclusion of global constants of the environment that contain : name of the framework, |
|
| 50 | + * version, release date, version of PHP required, etc. |
|
| 51 | + */ |
|
| 52 | + require_once CORE_PATH . 'constants.php'; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * include file containing commons functions used in the framework such: show_error, |
|
| 56 | - * php_exception_handler, php_error_handler, get_instance, etc. |
|
| 57 | - */ |
|
| 58 | - require_once CORE_PATH . 'common.php'; |
|
| 54 | + /** |
|
| 55 | + * include file containing commons functions used in the framework such: show_error, |
|
| 56 | + * php_exception_handler, php_error_handler, get_instance, etc. |
|
| 57 | + */ |
|
| 58 | + require_once CORE_PATH . 'common.php'; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * The Benchmark class |
|
| 62 | - */ |
|
| 63 | - $BENCHMARK =& class_loader('Benchmark'); |
|
| 60 | + /** |
|
| 61 | + * The Benchmark class |
|
| 62 | + */ |
|
| 63 | + $BENCHMARK =& class_loader('Benchmark'); |
|
| 64 | 64 | |
| 65 | - $BENCHMARK->mark('APP_EXECUTION_START'); |
|
| 65 | + $BENCHMARK->mark('APP_EXECUTION_START'); |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * instance of the Log class |
|
| 69 | - */ |
|
| 67 | + /** |
|
| 68 | + * instance of the Log class |
|
| 69 | + */ |
|
| 70 | 70 | $LOGGER =& class_loader('Log', 'classes'); |
| 71 | 71 | |
| 72 | 72 | $LOGGER->setLogger('ApplicationBootstrap'); |
| 73 | 73 | |
| 74 | 74 | $LOGGER->debug('Checking PHP version ...'); |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Verification of the PHP environment: minimum and maximum version |
|
| 78 | - */ |
|
| 79 | - if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
| 80 | - show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
|
| 81 | - } |
|
| 82 | - else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
| 83 | - show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
|
| 84 | - } |
|
| 85 | - $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
|
| 76 | + /** |
|
| 77 | + * Verification of the PHP environment: minimum and maximum version |
|
| 78 | + */ |
|
| 79 | + if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
| 80 | + show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
|
| 81 | + } |
|
| 82 | + else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
| 83 | + show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
|
| 84 | + } |
|
| 85 | + $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Setting of the PHP error message handling function |
|
| 89 | - */ |
|
| 90 | - set_error_handler('php_error_handler'); |
|
| 87 | + /** |
|
| 88 | + * Setting of the PHP error message handling function |
|
| 89 | + */ |
|
| 90 | + set_error_handler('php_error_handler'); |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Setting of the PHP error exception handling function |
|
| 94 | - */ |
|
| 95 | - set_exception_handler('php_exception_handler'); |
|
| 92 | + /** |
|
| 93 | + * Setting of the PHP error exception handling function |
|
| 94 | + */ |
|
| 95 | + set_exception_handler('php_exception_handler'); |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Setting of the PHP shutdown handling function |
|
| 99 | - */ |
|
| 100 | - register_shutdown_function('php_shudown_handler'); |
|
| 97 | + /** |
|
| 98 | + * Setting of the PHP shutdown handling function |
|
| 99 | + */ |
|
| 100 | + register_shutdown_function('php_shudown_handler'); |
|
| 101 | 101 | |
| 102 | - //if user have some composer packages |
|
| 103 | - $LOGGER->debug('Check for composer autoload'); |
|
| 104 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 105 | - $LOGGER->info('The composer autoload file exists include it'); |
|
| 106 | - require_once VENDOR_PATH . 'autoload.php'; |
|
| 107 | - } |
|
| 108 | - else{ |
|
| 109 | - $LOGGER->info('The composer autoload file does not exist skipping'); |
|
| 110 | - } |
|
| 102 | + //if user have some composer packages |
|
| 103 | + $LOGGER->debug('Check for composer autoload'); |
|
| 104 | + if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 105 | + $LOGGER->info('The composer autoload file exists include it'); |
|
| 106 | + require_once VENDOR_PATH . 'autoload.php'; |
|
| 107 | + } |
|
| 108 | + else{ |
|
| 109 | + $LOGGER->info('The composer autoload file does not exist skipping'); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - $LOGGER->debug('Begin to load the required resources'); |
|
| 112 | + $LOGGER->debug('Begin to load the required resources'); |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Load the EventInfo class file |
|
| 116 | - */ |
|
| 117 | - require_once CORE_CLASSES_PATH . 'EventInfo.php'; |
|
| 114 | + /** |
|
| 115 | + * Load the EventInfo class file |
|
| 116 | + */ |
|
| 117 | + require_once CORE_CLASSES_PATH . 'EventInfo.php'; |
|
| 118 | 118 | |
| 119 | 119 | |
| 120 | - $BENCHMARK->mark('CONFIG_INIT_START'); |
|
| 121 | - /** |
|
| 122 | - * Load configurations and using the |
|
| 123 | - * static method "init()" to initialize the Config class . |
|
| 124 | - */ |
|
| 125 | - $CONFIG =& class_loader('Config', 'classes'); |
|
| 126 | - $CONFIG->init(); |
|
| 127 | - $BENCHMARK->mark('CONFIG_INIT_END'); |
|
| 120 | + $BENCHMARK->mark('CONFIG_INIT_START'); |
|
| 121 | + /** |
|
| 122 | + * Load configurations and using the |
|
| 123 | + * static method "init()" to initialize the Config class . |
|
| 124 | + */ |
|
| 125 | + $CONFIG =& class_loader('Config', 'classes'); |
|
| 126 | + $CONFIG->init(); |
|
| 127 | + $BENCHMARK->mark('CONFIG_INIT_END'); |
|
| 128 | 128 | |
| 129 | - $BENCHMARK->mark('MODULE_INIT_START'); |
|
| 130 | - /** |
|
| 131 | - * Load modules and using the |
|
| 132 | - * static method "init()" to initialize the Module class. |
|
| 133 | - */ |
|
| 134 | - $MODULE =& class_loader('Module', 'classes'); |
|
| 135 | - $MODULE->init(); |
|
| 136 | - $BENCHMARK->mark('MODULE_INIT_END'); |
|
| 129 | + $BENCHMARK->mark('MODULE_INIT_START'); |
|
| 130 | + /** |
|
| 131 | + * Load modules and using the |
|
| 132 | + * static method "init()" to initialize the Module class. |
|
| 133 | + */ |
|
| 134 | + $MODULE =& class_loader('Module', 'classes'); |
|
| 135 | + $MODULE->init(); |
|
| 136 | + $BENCHMARK->mark('MODULE_INIT_END'); |
|
| 137 | 137 | |
| 138 | - $LOGGER->debug('Loading Base Controller ...'); |
|
| 139 | - /** |
|
| 140 | - * Include of the file containing the Base Controller class |
|
| 141 | - */ |
|
| 142 | - require_once CORE_CLASSES_PATH . 'Controller.php'; |
|
| 143 | - $LOGGER->info('Base Controller loaded successfully'); |
|
| 138 | + $LOGGER->debug('Loading Base Controller ...'); |
|
| 139 | + /** |
|
| 140 | + * Include of the file containing the Base Controller class |
|
| 141 | + */ |
|
| 142 | + require_once CORE_CLASSES_PATH . 'Controller.php'; |
|
| 143 | + $LOGGER->info('Base Controller loaded successfully'); |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Register controllers autoload function |
|
| 147 | - */ |
|
| 148 | - spl_autoload_register('autoload_controller'); |
|
| 145 | + /** |
|
| 146 | + * Register controllers autoload function |
|
| 147 | + */ |
|
| 148 | + spl_autoload_register('autoload_controller'); |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Loading Security class |
|
| 152 | - */ |
|
| 153 | - $SECURITY =& class_loader('Security', 'classes'); |
|
| 154 | - $SECURITY->checkWhiteListIpAccess(); |
|
| 150 | + /** |
|
| 151 | + * Loading Security class |
|
| 152 | + */ |
|
| 153 | + $SECURITY =& class_loader('Security', 'classes'); |
|
| 154 | + $SECURITY->checkWhiteListIpAccess(); |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Loading Url class |
|
| 158 | - */ |
|
| 159 | - $URL =& class_loader('Url', 'classes'); |
|
| 156 | + /** |
|
| 157 | + * Loading Url class |
|
| 158 | + */ |
|
| 159 | + $URL =& class_loader('Url', 'classes'); |
|
| 160 | 160 | |
| 161 | - if(get_config('cache_enable', false)){ |
|
| 162 | - /** |
|
| 163 | - * Load Cache interface file |
|
| 164 | - */ |
|
| 165 | - require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
|
| 166 | - $cacheHandler = get_config('cache_handler'); |
|
| 167 | - if(! $cacheHandler){ |
|
| 168 | - show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
|
| 169 | - } |
|
| 170 | - $CACHE = null; |
|
| 171 | - //first check if the cache handler is the system driver |
|
| 172 | - if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
| 173 | - $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
| 174 | - } |
|
| 175 | - else{ |
|
| 176 | - //it's not a system driver use user library |
|
| 177 | - $CACHE =& class_loader($cacheHandler); |
|
| 178 | - } |
|
| 179 | - //check if the page already cached |
|
| 180 | - if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
| 181 | - $RESPONSE = & class_loader('Response', 'classes'); |
|
| 182 | - $RESPONSE->renderFinalPageFromCache($CACHE); |
|
| 183 | - } |
|
| 184 | - } |
|
| 161 | + if(get_config('cache_enable', false)){ |
|
| 162 | + /** |
|
| 163 | + * Load Cache interface file |
|
| 164 | + */ |
|
| 165 | + require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
|
| 166 | + $cacheHandler = get_config('cache_handler'); |
|
| 167 | + if(! $cacheHandler){ |
|
| 168 | + show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
|
| 169 | + } |
|
| 170 | + $CACHE = null; |
|
| 171 | + //first check if the cache handler is the system driver |
|
| 172 | + if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
| 173 | + $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
| 174 | + } |
|
| 175 | + else{ |
|
| 176 | + //it's not a system driver use user library |
|
| 177 | + $CACHE =& class_loader($cacheHandler); |
|
| 178 | + } |
|
| 179 | + //check if the page already cached |
|
| 180 | + if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
| 181 | + $RESPONSE = & class_loader('Response', 'classes'); |
|
| 182 | + $RESPONSE->renderFinalPageFromCache($CACHE); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - //load model class |
|
| 187 | - require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
| 186 | + //load model class |
|
| 187 | + require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
| 188 | 188 | |
| 189 | - $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
| 190 | - /** |
|
| 191 | - * Routing |
|
| 192 | - * instantiation of the "Router" class and request processing. |
|
| 193 | - */ |
|
| 194 | - $ROUTER = & class_loader('Router', 'classes'); |
|
| 195 | - $ROUTER->processRequest(); |
|
| 189 | + $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
| 190 | + /** |
|
| 191 | + * Routing |
|
| 192 | + * instantiation of the "Router" class and request processing. |
|
| 193 | + */ |
|
| 194 | + $ROUTER = & class_loader('Router', 'classes'); |
|
| 195 | + $ROUTER->processRequest(); |
|
@@ -1,149 +1,149 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') or exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') or exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class Url{ |
|
| 28 | + class Url{ |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Return the link using base_url config without front controller "index.php" |
|
| 32 | - * @param string $path the link path or full URL |
|
| 33 | - * @return string the full link URL |
|
| 34 | - */ |
|
| 35 | - public static function base_url($path = ''){ |
|
| 36 | - if(is_url($path)){ |
|
| 37 | - return $path; |
|
| 38 | - } |
|
| 39 | - return get_config('base_url') . $path; |
|
| 40 | - } |
|
| 30 | + /** |
|
| 31 | + * Return the link using base_url config without front controller "index.php" |
|
| 32 | + * @param string $path the link path or full URL |
|
| 33 | + * @return string the full link URL |
|
| 34 | + */ |
|
| 35 | + public static function base_url($path = ''){ |
|
| 36 | + if(is_url($path)){ |
|
| 37 | + return $path; |
|
| 38 | + } |
|
| 39 | + return get_config('base_url') . $path; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Return the link using base_url config with front controller "index.php" |
|
| 44 | - * @param string $path the link path or full URL |
|
| 45 | - * @return string the full link URL |
|
| 46 | - */ |
|
| 47 | - public static function site_url($path = ''){ |
|
| 48 | - if(is_url($path)){ |
|
| 49 | - return $path; |
|
| 50 | - } |
|
| 51 | - $path = rtrim($path, '/'); |
|
| 52 | - $baseUrl = get_config('base_url'); |
|
| 53 | - $frontController = get_config('front_controller'); |
|
| 54 | - $url = $baseUrl; |
|
| 55 | - if($frontController){ |
|
| 56 | - $url .= $frontController . '/'; |
|
| 57 | - } |
|
| 58 | - if(($suffix = get_config('url_suffix')) && $path){ |
|
| 59 | - if(strpos($path, '?') !== false){ |
|
| 60 | - $query = explode('?', $path); |
|
| 61 | - $query[0] = str_ireplace($suffix, '', $query[0]); |
|
| 62 | - $query[0] = rtrim($query[0], '/'); |
|
| 63 | - $query[0] .= $suffix; |
|
| 64 | - $path = implode('?', $query); |
|
| 65 | - } |
|
| 66 | - else{ |
|
| 67 | - $path .= $suffix; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - return $url . $path; |
|
| 71 | - } |
|
| 42 | + /** |
|
| 43 | + * Return the link using base_url config with front controller "index.php" |
|
| 44 | + * @param string $path the link path or full URL |
|
| 45 | + * @return string the full link URL |
|
| 46 | + */ |
|
| 47 | + public static function site_url($path = ''){ |
|
| 48 | + if(is_url($path)){ |
|
| 49 | + return $path; |
|
| 50 | + } |
|
| 51 | + $path = rtrim($path, '/'); |
|
| 52 | + $baseUrl = get_config('base_url'); |
|
| 53 | + $frontController = get_config('front_controller'); |
|
| 54 | + $url = $baseUrl; |
|
| 55 | + if($frontController){ |
|
| 56 | + $url .= $frontController . '/'; |
|
| 57 | + } |
|
| 58 | + if(($suffix = get_config('url_suffix')) && $path){ |
|
| 59 | + if(strpos($path, '?') !== false){ |
|
| 60 | + $query = explode('?', $path); |
|
| 61 | + $query[0] = str_ireplace($suffix, '', $query[0]); |
|
| 62 | + $query[0] = rtrim($query[0], '/'); |
|
| 63 | + $query[0] .= $suffix; |
|
| 64 | + $path = implode('?', $query); |
|
| 65 | + } |
|
| 66 | + else{ |
|
| 67 | + $path .= $suffix; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + return $url . $path; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Return the current site URL |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public static function current(){ |
|
| 78 | - $current = '/'; |
|
| 79 | - $requestUri = get_instance()->request->requestUri(); |
|
| 80 | - if($requestUri){ |
|
| 81 | - $current = $requestUri; |
|
| 82 | - } |
|
| 83 | - return static::domain() . $current; |
|
| 84 | - } |
|
| 73 | + /** |
|
| 74 | + * Return the current site URL |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public static function current(){ |
|
| 78 | + $current = '/'; |
|
| 79 | + $requestUri = get_instance()->request->requestUri(); |
|
| 80 | + if($requestUri){ |
|
| 81 | + $current = $requestUri; |
|
| 82 | + } |
|
| 83 | + return static::domain() . $current; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Generate a friendly text to use in link (slugs) |
|
| 88 | - * @param string $str the title or text to use to get the friendly text |
|
| 89 | - * @param string $separator the caracters separator |
|
| 90 | - * @param boolean $lowercase whether to set the final text to lowe case or not |
|
| 91 | - * @return string the friendly generated text |
|
| 92 | - */ |
|
| 93 | - public static function title($str = null, $separator = '-', $lowercase = true){ |
|
| 94 | - $str = trim($str); |
|
| 95 | - $from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ'); |
|
| 96 | - $to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n'); |
|
| 97 | - $str = str_replace($from, $to, $str); |
|
| 98 | - $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str); |
|
| 99 | - $str = str_replace('--', $separator, $str); |
|
| 100 | - //if after process we get something like one-two-three-, need truncate the last separator "-" |
|
| 101 | - if(substr($str, -1) == $separator){ |
|
| 102 | - $str = substr($str, 0, -1); |
|
| 103 | - } |
|
| 104 | - if($lowercase){ |
|
| 105 | - $str = strtolower($str); |
|
| 106 | - } |
|
| 107 | - return $str; |
|
| 108 | - } |
|
| 86 | + /** |
|
| 87 | + * Generate a friendly text to use in link (slugs) |
|
| 88 | + * @param string $str the title or text to use to get the friendly text |
|
| 89 | + * @param string $separator the caracters separator |
|
| 90 | + * @param boolean $lowercase whether to set the final text to lowe case or not |
|
| 91 | + * @return string the friendly generated text |
|
| 92 | + */ |
|
| 93 | + public static function title($str = null, $separator = '-', $lowercase = true){ |
|
| 94 | + $str = trim($str); |
|
| 95 | + $from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ'); |
|
| 96 | + $to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n'); |
|
| 97 | + $str = str_replace($from, $to, $str); |
|
| 98 | + $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str); |
|
| 99 | + $str = str_replace('--', $separator, $str); |
|
| 100 | + //if after process we get something like one-two-three-, need truncate the last separator "-" |
|
| 101 | + if(substr($str, -1) == $separator){ |
|
| 102 | + $str = substr($str, 0, -1); |
|
| 103 | + } |
|
| 104 | + if($lowercase){ |
|
| 105 | + $str = strtolower($str); |
|
| 106 | + } |
|
| 107 | + return $str; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Get the current application domain with protocol |
|
| 112 | - * @return string the domain name |
|
| 113 | - */ |
|
| 114 | - public static function domain(){ |
|
| 115 | - $domain = 'localhost'; |
|
| 116 | - $port = get_instance()->request->server('SERVER_PORT'); |
|
| 117 | - $protocol = 'http'; |
|
| 118 | - if(is_https()){ |
|
| 119 | - $protocol = 'https'; |
|
| 120 | - } |
|
| 110 | + /** |
|
| 111 | + * Get the current application domain with protocol |
|
| 112 | + * @return string the domain name |
|
| 113 | + */ |
|
| 114 | + public static function domain(){ |
|
| 115 | + $domain = 'localhost'; |
|
| 116 | + $port = get_instance()->request->server('SERVER_PORT'); |
|
| 117 | + $protocol = 'http'; |
|
| 118 | + if(is_https()){ |
|
| 119 | + $protocol = 'https'; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - $domainserverVars = array( |
|
| 123 | - 'HTTP_HOST', |
|
| 124 | - 'SERVER_NAME', |
|
| 125 | - 'SERVER_ADDR' |
|
| 126 | - ); |
|
| 122 | + $domainserverVars = array( |
|
| 123 | + 'HTTP_HOST', |
|
| 124 | + 'SERVER_NAME', |
|
| 125 | + 'SERVER_ADDR' |
|
| 126 | + ); |
|
| 127 | 127 | |
| 128 | - foreach ($domainserverVars as $var) { |
|
| 129 | - $value = get_instance()->request->server($var); |
|
| 130 | - if($value){ |
|
| 131 | - $domain = $value; |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - } |
|
| 128 | + foreach ($domainserverVars as $var) { |
|
| 129 | + $value = get_instance()->request->server($var); |
|
| 130 | + if($value){ |
|
| 131 | + $domain = $value; |
|
| 132 | + break; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){ |
|
| 137 | - $domain .= ':'.$port; |
|
| 138 | - } |
|
| 139 | - return $protocol.'://'.$domain; |
|
| 140 | - } |
|
| 136 | + if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){ |
|
| 137 | + $domain .= ':'.$port; |
|
| 138 | + } |
|
| 139 | + return $protocol.'://'.$domain; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Get the current request query string |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - public static function queryString(){ |
|
| 147 | - return get_instance()->request->server('QUERY_STRING'); |
|
| 148 | - } |
|
| 149 | - } |
|
| 142 | + /** |
|
| 143 | + * Get the current request query string |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + public static function queryString(){ |
|
| 147 | + return get_instance()->request->server('QUERY_STRING'); |
|
| 148 | + } |
|
| 149 | + } |
|
@@ -1,320 +1,320 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class Form{ |
|
| 28 | + class Form{ |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Generate the form opened tag |
|
| 32 | - * @param string $path the form action path |
|
| 33 | - * @param array $attributes the additional form attributes |
|
| 34 | - * @param string $method the form method like 'GET', 'POST' |
|
| 35 | - * @param string $enctype the form enctype like "multipart/form-data" |
|
| 36 | - * @return string the generated form html |
|
| 37 | - */ |
|
| 38 | - public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){ |
|
| 39 | - if($path){ |
|
| 40 | - $path = Url::site_url($path); |
|
| 41 | - } |
|
| 42 | - $method = strtoupper($method); |
|
| 43 | - $str = null; |
|
| 44 | - $str .= '<form action = "'.$path.'" method = "'.$method.'"'; |
|
| 45 | - if(! empty($enctype)){ |
|
| 46 | - $str .= ' enctype = "'.$enctype.'" '; |
|
| 47 | - } |
|
| 48 | - if(! isset($attributes['accept-charset'])){ |
|
| 49 | - $attributes['accept-charset'] = get_config('charset', 'utf-8'); |
|
| 50 | - } |
|
| 51 | - $str .= attributes_to_string($attributes); |
|
| 52 | - $str .= '>'; |
|
| 53 | - //if CSRF is enabled in the configuration |
|
| 54 | - if(get_config('csrf_enable', false) && $method == 'POST'){ |
|
| 55 | - $csrfValue = Security::generateCSRF(); |
|
| 56 | - $csrfName = get_config('csrf_key', 'csrf_key'); |
|
| 57 | - $str .= static::hidden($csrfName, $csrfValue); |
|
| 58 | - } |
|
| 59 | - return $str; |
|
| 60 | - } |
|
| 30 | + /** |
|
| 31 | + * Generate the form opened tag |
|
| 32 | + * @param string $path the form action path |
|
| 33 | + * @param array $attributes the additional form attributes |
|
| 34 | + * @param string $method the form method like 'GET', 'POST' |
|
| 35 | + * @param string $enctype the form enctype like "multipart/form-data" |
|
| 36 | + * @return string the generated form html |
|
| 37 | + */ |
|
| 38 | + public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){ |
|
| 39 | + if($path){ |
|
| 40 | + $path = Url::site_url($path); |
|
| 41 | + } |
|
| 42 | + $method = strtoupper($method); |
|
| 43 | + $str = null; |
|
| 44 | + $str .= '<form action = "'.$path.'" method = "'.$method.'"'; |
|
| 45 | + if(! empty($enctype)){ |
|
| 46 | + $str .= ' enctype = "'.$enctype.'" '; |
|
| 47 | + } |
|
| 48 | + if(! isset($attributes['accept-charset'])){ |
|
| 49 | + $attributes['accept-charset'] = get_config('charset', 'utf-8'); |
|
| 50 | + } |
|
| 51 | + $str .= attributes_to_string($attributes); |
|
| 52 | + $str .= '>'; |
|
| 53 | + //if CSRF is enabled in the configuration |
|
| 54 | + if(get_config('csrf_enable', false) && $method == 'POST'){ |
|
| 55 | + $csrfValue = Security::generateCSRF(); |
|
| 56 | + $csrfName = get_config('csrf_key', 'csrf_key'); |
|
| 57 | + $str .= static::hidden($csrfName, $csrfValue); |
|
| 58 | + } |
|
| 59 | + return $str; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Generate the form opened tag for multipart like to send a file |
|
| 64 | - * @see Form::open() for more details |
|
| 65 | - * @return string the generated multipart form html |
|
| 66 | - */ |
|
| 67 | - public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){ |
|
| 68 | - return self::open($path, $attributes, $method, 'multipart/form-data'); |
|
| 69 | - } |
|
| 62 | + /** |
|
| 63 | + * Generate the form opened tag for multipart like to send a file |
|
| 64 | + * @see Form::open() for more details |
|
| 65 | + * @return string the generated multipart form html |
|
| 66 | + */ |
|
| 67 | + public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){ |
|
| 68 | + return self::open($path, $attributes, $method, 'multipart/form-data'); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Generate the form close |
|
| 73 | - * @return string the form close html |
|
| 74 | - */ |
|
| 75 | - public static function close(){ |
|
| 76 | - return '</form>'; |
|
| 77 | - } |
|
| 71 | + /** |
|
| 72 | + * Generate the form close |
|
| 73 | + * @return string the form close html |
|
| 74 | + */ |
|
| 75 | + public static function close(){ |
|
| 76 | + return '</form>'; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Generate the form fieldset & legend |
|
| 81 | - * @param string $legend the legend tag value |
|
| 82 | - * @param array $fieldsetAttributes the fieldset additional HTML attributes |
|
| 83 | - * @param array $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty |
|
| 84 | - * @return string the generated fieldset value |
|
| 85 | - */ |
|
| 86 | - public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){ |
|
| 87 | - $str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>'; |
|
| 88 | - if($legend){ |
|
| 89 | - $str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>'; |
|
| 90 | - } |
|
| 91 | - return $str; |
|
| 92 | - } |
|
| 79 | + /** |
|
| 80 | + * Generate the form fieldset & legend |
|
| 81 | + * @param string $legend the legend tag value |
|
| 82 | + * @param array $fieldsetAttributes the fieldset additional HTML attributes |
|
| 83 | + * @param array $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty |
|
| 84 | + * @return string the generated fieldset value |
|
| 85 | + */ |
|
| 86 | + public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){ |
|
| 87 | + $str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>'; |
|
| 88 | + if($legend){ |
|
| 89 | + $str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>'; |
|
| 90 | + } |
|
| 91 | + return $str; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Generate the fieldset close tag |
|
| 96 | - * @return string the generated html for fieldset close |
|
| 97 | - */ |
|
| 98 | - public static function fieldsetClose(){ |
|
| 99 | - return '</fieldset>'; |
|
| 100 | - } |
|
| 94 | + /** |
|
| 95 | + * Generate the fieldset close tag |
|
| 96 | + * @return string the generated html for fieldset close |
|
| 97 | + */ |
|
| 98 | + public static function fieldsetClose(){ |
|
| 99 | + return '</fieldset>'; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Get the error message for the given form field name. |
|
| 104 | - * This use the form validation information to get the error information. |
|
| 105 | - * @param string $name the form field name |
|
| 106 | - * @return string the error message if exists and null if not |
|
| 107 | - */ |
|
| 108 | - public static function error($name){ |
|
| 109 | - $return = null; |
|
| 110 | - $obj = & get_instance(); |
|
| 111 | - if(isset($obj->formvalidation)){ |
|
| 112 | - $errors = $obj->formvalidation->returnErrors(); |
|
| 113 | - $error = isset($errors[$name]) ? $errors[$name] : null; |
|
| 114 | - if($error){ |
|
| 115 | - list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter(); |
|
| 116 | - $return = $errorStart . $error . $errorEnd; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - return $return; |
|
| 120 | - } |
|
| 102 | + /** |
|
| 103 | + * Get the error message for the given form field name. |
|
| 104 | + * This use the form validation information to get the error information. |
|
| 105 | + * @param string $name the form field name |
|
| 106 | + * @return string the error message if exists and null if not |
|
| 107 | + */ |
|
| 108 | + public static function error($name){ |
|
| 109 | + $return = null; |
|
| 110 | + $obj = & get_instance(); |
|
| 111 | + if(isset($obj->formvalidation)){ |
|
| 112 | + $errors = $obj->formvalidation->returnErrors(); |
|
| 113 | + $error = isset($errors[$name]) ? $errors[$name] : null; |
|
| 114 | + if($error){ |
|
| 115 | + list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter(); |
|
| 116 | + $return = $errorStart . $error . $errorEnd; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + return $return; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Get the form field value |
|
| 124 | - * @param string $name the form field name |
|
| 125 | - * @param mixed $default the default value if can not found the given form field name |
|
| 126 | - * @return mixed the form field value if is set, otherwise return the default value. |
|
| 127 | - */ |
|
| 128 | - public static function value($name, $default = null){ |
|
| 129 | - $value = get_instance()->request->query($name); |
|
| 130 | - return $value ? $value : $default; |
|
| 131 | - } |
|
| 122 | + /** |
|
| 123 | + * Get the form field value |
|
| 124 | + * @param string $name the form field name |
|
| 125 | + * @param mixed $default the default value if can not found the given form field name |
|
| 126 | + * @return mixed the form field value if is set, otherwise return the default value. |
|
| 127 | + */ |
|
| 128 | + public static function value($name, $default = null){ |
|
| 129 | + $value = get_instance()->request->query($name); |
|
| 130 | + return $value ? $value : $default; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Generate the form label html content |
|
| 135 | - * @param string $label the title of the label |
|
| 136 | - * @param string $for the value of the label "for" attribute |
|
| 137 | - * @param array $attributes the additional attributes to be added |
|
| 138 | - * @return string the generated label html content |
|
| 139 | - */ |
|
| 140 | - public static function label($label, $for = '', array $attributes = array()){ |
|
| 141 | - $str = '<label'; |
|
| 142 | - if($for){ |
|
| 143 | - $str .= ' for = "'.$for.'"'; |
|
| 144 | - } |
|
| 145 | - $str .= attributes_to_string($attributes); |
|
| 146 | - $str .= '>'; |
|
| 147 | - $str .= $label.'</label>'; |
|
| 148 | - return $str; |
|
| 149 | - } |
|
| 133 | + /** |
|
| 134 | + * Generate the form label html content |
|
| 135 | + * @param string $label the title of the label |
|
| 136 | + * @param string $for the value of the label "for" attribute |
|
| 137 | + * @param array $attributes the additional attributes to be added |
|
| 138 | + * @return string the generated label html content |
|
| 139 | + */ |
|
| 140 | + public static function label($label, $for = '', array $attributes = array()){ |
|
| 141 | + $str = '<label'; |
|
| 142 | + if($for){ |
|
| 143 | + $str .= ' for = "'.$for.'"'; |
|
| 144 | + } |
|
| 145 | + $str .= attributes_to_string($attributes); |
|
| 146 | + $str .= '>'; |
|
| 147 | + $str .= $label.'</label>'; |
|
| 148 | + return $str; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Generate the form field for input like "text", "email", "password", etc. |
|
| 153 | - * @param string $name the form field name |
|
| 154 | - * @param mixed $value the form field value to be set |
|
| 155 | - * @param array $attributes the additional attributes to be added in the form input |
|
| 156 | - * @param string $type the type of the form field (password, text, submit, button, etc.) |
|
| 157 | - * @return string the generated form field html content for the input |
|
| 158 | - */ |
|
| 159 | - public static function input($name, $value = null, array $attributes = array(), $type = 'text'){ |
|
| 160 | - $str = null; |
|
| 161 | - $str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"'; |
|
| 162 | - $str .= attributes_to_string($attributes); |
|
| 163 | - $str .= '/>'; |
|
| 164 | - return $str; |
|
| 165 | - } |
|
| 151 | + /** |
|
| 152 | + * Generate the form field for input like "text", "email", "password", etc. |
|
| 153 | + * @param string $name the form field name |
|
| 154 | + * @param mixed $value the form field value to be set |
|
| 155 | + * @param array $attributes the additional attributes to be added in the form input |
|
| 156 | + * @param string $type the type of the form field (password, text, submit, button, etc.) |
|
| 157 | + * @return string the generated form field html content for the input |
|
| 158 | + */ |
|
| 159 | + public static function input($name, $value = null, array $attributes = array(), $type = 'text'){ |
|
| 160 | + $str = null; |
|
| 161 | + $str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"'; |
|
| 162 | + $str .= attributes_to_string($attributes); |
|
| 163 | + $str .= '/>'; |
|
| 164 | + return $str; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Generate the form field for "text" |
|
| 169 | - * @see Form::input() for more details |
|
| 170 | - */ |
|
| 171 | - public static function text($name, $value = null, array $attributes = array()){ |
|
| 172 | - return self::input($name, $value, $attributes, 'text'); |
|
| 173 | - } |
|
| 167 | + /** |
|
| 168 | + * Generate the form field for "text" |
|
| 169 | + * @see Form::input() for more details |
|
| 170 | + */ |
|
| 171 | + public static function text($name, $value = null, array $attributes = array()){ |
|
| 172 | + return self::input($name, $value, $attributes, 'text'); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * Generate the form field for "password" |
|
| 177 | - * @see Form::input() for more details |
|
| 178 | - */ |
|
| 179 | - public static function password($name, $value = null, array $attributes = array()){ |
|
| 180 | - return self::input($name, $value, $attributes, 'password'); |
|
| 181 | - } |
|
| 175 | + /** |
|
| 176 | + * Generate the form field for "password" |
|
| 177 | + * @see Form::input() for more details |
|
| 178 | + */ |
|
| 179 | + public static function password($name, $value = null, array $attributes = array()){ |
|
| 180 | + return self::input($name, $value, $attributes, 'password'); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Generate the form field for "radio" |
|
| 185 | - * @see Form::input() for more details |
|
| 186 | - */ |
|
| 187 | - public static function radio($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 188 | - if($checked){ |
|
| 189 | - $attributes['checked'] = true; |
|
| 190 | - } |
|
| 191 | - return self::input($name, $value, $attributes, 'radio'); |
|
| 192 | - } |
|
| 183 | + /** |
|
| 184 | + * Generate the form field for "radio" |
|
| 185 | + * @see Form::input() for more details |
|
| 186 | + */ |
|
| 187 | + public static function radio($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 188 | + if($checked){ |
|
| 189 | + $attributes['checked'] = true; |
|
| 190 | + } |
|
| 191 | + return self::input($name, $value, $attributes, 'radio'); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * Generate the form field for "checkbox" |
|
| 196 | - * @see Form::input() for more details |
|
| 197 | - */ |
|
| 198 | - public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 199 | - if($checked){ |
|
| 200 | - $attributes['checked'] = true; |
|
| 201 | - } |
|
| 202 | - return self::input($name, $value, $attributes, 'checkbox'); |
|
| 203 | - } |
|
| 194 | + /** |
|
| 195 | + * Generate the form field for "checkbox" |
|
| 196 | + * @see Form::input() for more details |
|
| 197 | + */ |
|
| 198 | + public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 199 | + if($checked){ |
|
| 200 | + $attributes['checked'] = true; |
|
| 201 | + } |
|
| 202 | + return self::input($name, $value, $attributes, 'checkbox'); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - /** |
|
| 206 | - * Generate the form field for "number" |
|
| 207 | - * @see Form::input() for more details |
|
| 208 | - */ |
|
| 209 | - public static function number($name, $value = null, array $attributes = array()){ |
|
| 210 | - return self::input($name, $value, $attributes, 'number'); |
|
| 211 | - } |
|
| 205 | + /** |
|
| 206 | + * Generate the form field for "number" |
|
| 207 | + * @see Form::input() for more details |
|
| 208 | + */ |
|
| 209 | + public static function number($name, $value = null, array $attributes = array()){ |
|
| 210 | + return self::input($name, $value, $attributes, 'number'); |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * Generate the form field for "phone" |
|
| 215 | - * @see Form::input() for more details |
|
| 216 | - */ |
|
| 217 | - public static function phone($name, $value = null, array $attributes = array()){ |
|
| 218 | - return self::input($name, $value, $attributes, 'phone'); |
|
| 219 | - } |
|
| 213 | + /** |
|
| 214 | + * Generate the form field for "phone" |
|
| 215 | + * @see Form::input() for more details |
|
| 216 | + */ |
|
| 217 | + public static function phone($name, $value = null, array $attributes = array()){ |
|
| 218 | + return self::input($name, $value, $attributes, 'phone'); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Generate the form field for "email" |
|
| 223 | - * @see Form::input() for more details |
|
| 224 | - */ |
|
| 225 | - public static function email($name, $value = null, array $attributes = array()){ |
|
| 226 | - return self::input($name, $value, $attributes, 'email'); |
|
| 227 | - } |
|
| 221 | + /** |
|
| 222 | + * Generate the form field for "email" |
|
| 223 | + * @see Form::input() for more details |
|
| 224 | + */ |
|
| 225 | + public static function email($name, $value = null, array $attributes = array()){ |
|
| 226 | + return self::input($name, $value, $attributes, 'email'); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * Generate the form field for "search" |
|
| 231 | - * @see Form::input() for more details |
|
| 232 | - */ |
|
| 233 | - public static function search($name, $value = null, array $attributes = array()){ |
|
| 234 | - return self::input($name, $value, $attributes, 'search'); |
|
| 235 | - } |
|
| 229 | + /** |
|
| 230 | + * Generate the form field for "search" |
|
| 231 | + * @see Form::input() for more details |
|
| 232 | + */ |
|
| 233 | + public static function search($name, $value = null, array $attributes = array()){ |
|
| 234 | + return self::input($name, $value, $attributes, 'search'); |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * Generate the form field for "hidden" |
|
| 239 | - * @see Form::input() for more details |
|
| 240 | - */ |
|
| 241 | - public static function hidden($name, $value = null, array $attributes = array()){ |
|
| 242 | - return self::input($name, $value, $attributes, 'hidden'); |
|
| 243 | - } |
|
| 237 | + /** |
|
| 238 | + * Generate the form field for "hidden" |
|
| 239 | + * @see Form::input() for more details |
|
| 240 | + */ |
|
| 241 | + public static function hidden($name, $value = null, array $attributes = array()){ |
|
| 242 | + return self::input($name, $value, $attributes, 'hidden'); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Generate the form field for "file" |
|
| 247 | - * @see Form::input() for more details |
|
| 248 | - */ |
|
| 249 | - public static function file($name, array $attributes = array()){ |
|
| 250 | - return self::input($name, null, $attributes, 'file'); |
|
| 251 | - } |
|
| 245 | + /** |
|
| 246 | + * Generate the form field for "file" |
|
| 247 | + * @see Form::input() for more details |
|
| 248 | + */ |
|
| 249 | + public static function file($name, array $attributes = array()){ |
|
| 250 | + return self::input($name, null, $attributes, 'file'); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Generate the form field for "button" |
|
| 255 | - * @see Form::input() for more details |
|
| 256 | - */ |
|
| 257 | - public static function button($name, $value = null, array $attributes = array()){ |
|
| 258 | - return self::input($name, $value, $attributes, 'button'); |
|
| 259 | - } |
|
| 253 | + /** |
|
| 254 | + * Generate the form field for "button" |
|
| 255 | + * @see Form::input() for more details |
|
| 256 | + */ |
|
| 257 | + public static function button($name, $value = null, array $attributes = array()){ |
|
| 258 | + return self::input($name, $value, $attributes, 'button'); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * Generate the form field for "reset" |
|
| 263 | - * @see Form::input() for more details |
|
| 264 | - */ |
|
| 265 | - public static function reset($name, $value = null, array $attributes = array()){ |
|
| 266 | - return self::input($name, $value, $attributes, 'reset'); |
|
| 267 | - } |
|
| 261 | + /** |
|
| 262 | + * Generate the form field for "reset" |
|
| 263 | + * @see Form::input() for more details |
|
| 264 | + */ |
|
| 265 | + public static function reset($name, $value = null, array $attributes = array()){ |
|
| 266 | + return self::input($name, $value, $attributes, 'reset'); |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * Generate the form field for "submit" |
|
| 271 | - * @see Form::input() for more details |
|
| 272 | - */ |
|
| 273 | - public static function submit($name, $value = null, array $attributes = array()){ |
|
| 274 | - return self::input($name, $value, $attributes, 'submit'); |
|
| 275 | - } |
|
| 269 | + /** |
|
| 270 | + * Generate the form field for "submit" |
|
| 271 | + * @see Form::input() for more details |
|
| 272 | + */ |
|
| 273 | + public static function submit($name, $value = null, array $attributes = array()){ |
|
| 274 | + return self::input($name, $value, $attributes, 'submit'); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * Generate the form field for textarea |
|
| 279 | - * @param string $name the name of the textarea field |
|
| 280 | - * @param string $value the textarea field value |
|
| 281 | - * @param array $attributes the additional attributes to be added |
|
| 282 | - * @return string the generated textarea form html content |
|
| 283 | - */ |
|
| 284 | - public static function textarea($name, $value = '', array $attributes = array()){ |
|
| 285 | - $str = null; |
|
| 286 | - $str .= '<textarea name = "'.$name.'"'; |
|
| 287 | - $str .= attributes_to_string($attributes); |
|
| 288 | - $str .= '>'; |
|
| 289 | - $str .= $value.'</textarea>'; |
|
| 290 | - return $str; |
|
| 291 | - } |
|
| 277 | + /** |
|
| 278 | + * Generate the form field for textarea |
|
| 279 | + * @param string $name the name of the textarea field |
|
| 280 | + * @param string $value the textarea field value |
|
| 281 | + * @param array $attributes the additional attributes to be added |
|
| 282 | + * @return string the generated textarea form html content |
|
| 283 | + */ |
|
| 284 | + public static function textarea($name, $value = '', array $attributes = array()){ |
|
| 285 | + $str = null; |
|
| 286 | + $str .= '<textarea name = "'.$name.'"'; |
|
| 287 | + $str .= attributes_to_string($attributes); |
|
| 288 | + $str .= '>'; |
|
| 289 | + $str .= $value.'</textarea>'; |
|
| 290 | + return $str; |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * Generate the form field for select |
|
| 295 | - * @param string $name the name of the form field |
|
| 296 | - * @param mixed|array $values the values used to populate the "option" tags |
|
| 297 | - * @param mixed $selected the selected value in the option list |
|
| 298 | - * @param array $attributes the additional attribute to be added |
|
| 299 | - * @return string the generated form field html content for select |
|
| 300 | - */ |
|
| 301 | - public static function select($name, $values = null, $selected = null, array $attributes = array()){ |
|
| 302 | - if(! is_array($values)){ |
|
| 303 | - $values = array('' => $values); |
|
| 304 | - } |
|
| 305 | - $str = null; |
|
| 306 | - $str .= '<select name = "'.$name.'"'; |
|
| 307 | - $str .= attributes_to_string($attributes); |
|
| 308 | - $str .= '>'; |
|
| 309 | - foreach($values as $key => $val){ |
|
| 310 | - $select = ''; |
|
| 311 | - if($key == $selected){ |
|
| 312 | - $select = 'selected'; |
|
| 313 | - } |
|
| 314 | - $str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>'; |
|
| 315 | - } |
|
| 316 | - $str .= '</select>'; |
|
| 317 | - return $str; |
|
| 318 | - } |
|
| 293 | + /** |
|
| 294 | + * Generate the form field for select |
|
| 295 | + * @param string $name the name of the form field |
|
| 296 | + * @param mixed|array $values the values used to populate the "option" tags |
|
| 297 | + * @param mixed $selected the selected value in the option list |
|
| 298 | + * @param array $attributes the additional attribute to be added |
|
| 299 | + * @return string the generated form field html content for select |
|
| 300 | + */ |
|
| 301 | + public static function select($name, $values = null, $selected = null, array $attributes = array()){ |
|
| 302 | + if(! is_array($values)){ |
|
| 303 | + $values = array('' => $values); |
|
| 304 | + } |
|
| 305 | + $str = null; |
|
| 306 | + $str .= '<select name = "'.$name.'"'; |
|
| 307 | + $str .= attributes_to_string($attributes); |
|
| 308 | + $str .= '>'; |
|
| 309 | + foreach($values as $key => $val){ |
|
| 310 | + $select = ''; |
|
| 311 | + if($key == $selected){ |
|
| 312 | + $select = 'selected'; |
|
| 313 | + } |
|
| 314 | + $str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>'; |
|
| 315 | + } |
|
| 316 | + $str .= '</select>'; |
|
| 317 | + return $str; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - } |
|
| 320 | + } |
|
@@ -1,151 +1,151 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class RouterTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class RouterTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testAutoUri() |
|
| 27 | - { |
|
| 26 | + public function testAutoUri() |
|
| 27 | + { |
|
| 28 | 28 | //when application run in CLI the first argument will be used as route URI |
| 29 | 29 | $_SERVER['argv'][1] = ''; |
| 30 | 30 | |
| 31 | 31 | $r = new Router(); |
| 32 | 32 | //remove all all config |
| 33 | 33 | $r->setRouteConfiguration(array(), false) |
| 34 | - ->setRouteUri() |
|
| 35 | - ->setRouteSegments() |
|
| 36 | - ->determineRouteParamsInformation(); |
|
| 34 | + ->setRouteUri() |
|
| 35 | + ->setRouteSegments() |
|
| 36 | + ->determineRouteParamsInformation(); |
|
| 37 | 37 | |
| 38 | 38 | $this->assertNull($r->getController()); |
| 39 | - $this->assertSame('index', $r->getMethod()); |
|
| 40 | - $this->assertSame(0, count($r->getArgs())); |
|
| 41 | - } |
|
| 39 | + $this->assertSame('index', $r->getMethod()); |
|
| 40 | + $this->assertSame(0, count($r->getArgs())); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | public function testCustomUri() |
| 44 | - { |
|
| 44 | + { |
|
| 45 | 45 | $r = new Router(); |
| 46 | 46 | $r->setRouteUri('users/profile/34/54') |
| 47 | - ->setRouteSegments() |
|
| 48 | - ->determineRouteParamsInformation(); |
|
| 47 | + ->setRouteSegments() |
|
| 48 | + ->determineRouteParamsInformation(); |
|
| 49 | 49 | $this->assertSame('users', $r->getController()); |
| 50 | - $this->assertSame('profile', $r->getMethod()); |
|
| 51 | - $this->assertSame(2, count($r->getArgs())); |
|
| 52 | - } |
|
| 50 | + $this->assertSame('profile', $r->getMethod()); |
|
| 51 | + $this->assertSame(2, count($r->getArgs())); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | public function testWithCustomConfigControllerMethod() |
| 55 | - { |
|
| 55 | + { |
|
| 56 | 56 | $r = new Router(); |
| 57 | 57 | $r->add('/foo/bar', 'fooController@fooMethod') |
| 58 | - ->setRouteUri('/foo/bar') |
|
| 59 | - ->setRouteSegments() |
|
| 60 | - ->determineRouteParamsInformation(); |
|
| 58 | + ->setRouteUri('/foo/bar') |
|
| 59 | + ->setRouteSegments() |
|
| 60 | + ->determineRouteParamsInformation(); |
|
| 61 | 61 | $this->assertSame('fooController', $r->getController()); |
| 62 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 63 | - $this->assertSame(0, count($r->getArgs())); |
|
| 64 | - $this->assertNull($r->getModule()); |
|
| 65 | - } |
|
| 62 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 63 | + $this->assertSame(0, count($r->getArgs())); |
|
| 64 | + $this->assertNull($r->getModule()); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | public function testWithCustomConfigModuleControllerMethod() |
| 68 | - { |
|
| 68 | + { |
|
| 69 | 69 | $r = new Router(); |
| 70 | 70 | $r->add('/foo/bar', 'fooModule#fooController@fooMethod') |
| 71 | - ->setRouteUri('/foo/bar') |
|
| 72 | - ->setRouteSegments() |
|
| 73 | - ->determineRouteParamsInformation(); |
|
| 71 | + ->setRouteUri('/foo/bar') |
|
| 72 | + ->setRouteSegments() |
|
| 73 | + ->determineRouteParamsInformation(); |
|
| 74 | 74 | $this->assertSame('fooController', $r->getController()); |
| 75 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 76 | - $this->assertSame('fooModule', $r->getModule()); |
|
| 77 | - $this->assertSame(0, count($r->getArgs())); |
|
| 78 | - } |
|
| 75 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 76 | + $this->assertSame('fooModule', $r->getModule()); |
|
| 77 | + $this->assertSame(0, count($r->getArgs())); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | public function testWithCustomConfigUsingAnyPattern() |
| 81 | - { |
|
| 81 | + { |
|
| 82 | 82 | $r = new Router(); |
| 83 | 83 | $r->add('/foo/(:any)', 'fooController@fooMethod') |
| 84 | - ->setRouteUri('/foo/bar123-baz') |
|
| 85 | - ->setRouteSegments() |
|
| 86 | - ->determineRouteParamsInformation(); |
|
| 84 | + ->setRouteUri('/foo/bar123-baz') |
|
| 85 | + ->setRouteSegments() |
|
| 86 | + ->determineRouteParamsInformation(); |
|
| 87 | 87 | $this->assertSame('fooController', $r->getController()); |
| 88 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 89 | - $this->assertSame(1, count($r->getArgs())); |
|
| 88 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 89 | + $this->assertSame(1, count($r->getArgs())); |
|
| 90 | 90 | $args = $r->getArgs(); |
| 91 | 91 | $this->assertSame('bar123-baz', $args[0]); |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - public function testWithCustomConfigUsingNumericPattern() |
|
| 95 | - { |
|
| 94 | + public function testWithCustomConfigUsingNumericPattern() |
|
| 95 | + { |
|
| 96 | 96 | $r = new Router(); |
| 97 | 97 | $r->add('/foo/(:num)', 'fooController@fooMethod') |
| 98 | - ->setRouteUri('/foo/34') |
|
| 99 | - ->setRouteSegments() |
|
| 100 | - ->determineRouteParamsInformation(); |
|
| 98 | + ->setRouteUri('/foo/34') |
|
| 99 | + ->setRouteSegments() |
|
| 100 | + ->determineRouteParamsInformation(); |
|
| 101 | 101 | $this->assertSame('fooController', $r->getController()); |
| 102 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 103 | - $this->assertSame(1, count($r->getArgs())); |
|
| 102 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 103 | + $this->assertSame(1, count($r->getArgs())); |
|
| 104 | 104 | $args = $r->getArgs(); |
| 105 | 105 | $this->assertSame('34', $args[0]); |
| 106 | - } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | public function testWithCustomConfigUsingAlphaPattern() |
| 109 | - { |
|
| 109 | + { |
|
| 110 | 110 | $r = new Router(); |
| 111 | 111 | $r->add('/foo/(:alpha)', 'fooController@fooMethod') |
| 112 | - ->setRouteUri('/foo/baz') |
|
| 113 | - ->setRouteSegments() |
|
| 114 | - ->determineRouteParamsInformation(); |
|
| 112 | + ->setRouteUri('/foo/baz') |
|
| 113 | + ->setRouteSegments() |
|
| 114 | + ->determineRouteParamsInformation(); |
|
| 115 | 115 | $this->assertSame('fooController', $r->getController()); |
| 116 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 117 | - $this->assertSame(1, count($r->getArgs())); |
|
| 116 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 117 | + $this->assertSame(1, count($r->getArgs())); |
|
| 118 | 118 | $args = $r->getArgs(); |
| 119 | 119 | $this->assertSame('baz', $args[0]); |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | public function testWithCustomConfigUsingAlphaNumericPattern() |
| 123 | - { |
|
| 123 | + { |
|
| 124 | 124 | $r = new Router(); |
| 125 | 125 | $r->add('/foo/(:alnum)', 'fooController@fooMethod') |
| 126 | - ->setRouteUri('/foo/baz123') |
|
| 127 | - ->setRouteSegments() |
|
| 128 | - ->determineRouteParamsInformation(); |
|
| 126 | + ->setRouteUri('/foo/baz123') |
|
| 127 | + ->setRouteSegments() |
|
| 128 | + ->determineRouteParamsInformation(); |
|
| 129 | 129 | $this->assertSame('fooController', $r->getController()); |
| 130 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 131 | - $this->assertSame(1, count($r->getArgs())); |
|
| 130 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 131 | + $this->assertSame(1, count($r->getArgs())); |
|
| 132 | 132 | $args = $r->getArgs(); |
| 133 | 133 | $this->assertSame('baz123', $args[0]); |
| 134 | - } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | public function testWithCustomConfigUsingMultiplePattern() |
| 137 | - { |
|
| 137 | + { |
|
| 138 | 138 | $r = new Router(); |
| 139 | 139 | $r->add('/foo/(:alpha)/(:num)', 'fooController@fooMethod') |
| 140 | - ->setRouteUri('/foo/baz/123') |
|
| 141 | - ->setRouteSegments() |
|
| 142 | - ->determineRouteParamsInformation(); |
|
| 140 | + ->setRouteUri('/foo/baz/123') |
|
| 141 | + ->setRouteSegments() |
|
| 142 | + ->determineRouteParamsInformation(); |
|
| 143 | 143 | $this->assertSame('fooController', $r->getController()); |
| 144 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 145 | - $this->assertSame(2, count($r->getArgs())); |
|
| 144 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 145 | + $this->assertSame(2, count($r->getArgs())); |
|
| 146 | 146 | $args = $r->getArgs(); |
| 147 | 147 | $this->assertSame('baz', $args[0]); |
| 148 | 148 | $this->assertSame('123', $args[1]); |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - } |
|
| 152 | 151 | \ No newline at end of file |
| 152 | + } |
|
| 153 | 153 | \ No newline at end of file |
@@ -1,31 +1,31 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class DatabaseQueryBuilderTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class DatabaseQueryBuilderTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testNotYet() |
|
| 27 | - { |
|
| 28 | - $this->markTestSkipped(); |
|
| 29 | - } |
|
| 26 | + public function testNotYet() |
|
| 27 | + { |
|
| 28 | + $this->markTestSkipped(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - } |
|
| 32 | 31 | \ No newline at end of file |
| 32 | + } |
|
| 33 | 33 | \ No newline at end of file |
@@ -1,31 +1,31 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class DatabaseQueryResultTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class DatabaseQueryResultTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testNotYet() |
|
| 27 | - { |
|
| 28 | - $this->markTestSkipped(); |
|
| 29 | - } |
|
| 26 | + public function testNotYet() |
|
| 27 | + { |
|
| 28 | + $this->markTestSkipped(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - } |
|
| 32 | 31 | \ No newline at end of file |
| 32 | + } |
|
| 33 | 33 | \ No newline at end of file |