@@ -1,39 +1,39 @@ discard block |
||
| 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 | - * DB session handler class |
|
| 29 | - */ |
|
| 30 | - abstract class DBSessionHandlerModel extends Model { |
|
| 27 | + /** |
|
| 28 | + * DB session handler class |
|
| 29 | + */ |
|
| 30 | + abstract class DBSessionHandlerModel extends Model { |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The session table columns to use |
|
| 34 | - * @var array |
|
| 35 | - * @example |
|
| 36 | - * array( |
|
| 32 | + /** |
|
| 33 | + * The session table columns to use |
|
| 34 | + * @var array |
|
| 35 | + * @example |
|
| 36 | + * array( |
|
| 37 | 37 | 'sid' => '', //VARCHAR(255) Note: this a primary key |
| 38 | 38 | 'sdata' => '', //TEXT |
| 39 | 39 | 'stime' => '', //unix timestamp (INT|BIGINT) |
@@ -42,41 +42,41 @@ discard block |
||
| 42 | 42 | 'sbrowser' => '', //VARCHAR(255) |
| 43 | 43 | 'skey' => '' //VARCHAR(255) |
| 44 | 44 | ); |
| 45 | - */ |
|
| 46 | - protected $sessionTableColumns = array(); |
|
| 45 | + */ |
|
| 46 | + protected $sessionTableColumns = array(); |
|
| 47 | 47 | |
| 48 | - public function __construct(Database $db = null){ |
|
| 49 | - parent::__construct($db); |
|
| 50 | - } |
|
| 48 | + public function __construct(Database $db = null){ |
|
| 49 | + parent::__construct($db); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Return the session database table columns |
|
| 54 | - * @return array |
|
| 55 | - */ |
|
| 56 | - public function getSessionTableColumns(){ |
|
| 57 | - return $this->sessionTableColumns; |
|
| 58 | - } |
|
| 52 | + /** |
|
| 53 | + * Return the session database table columns |
|
| 54 | + * @return array |
|
| 55 | + */ |
|
| 56 | + public function getSessionTableColumns(){ |
|
| 57 | + return $this->sessionTableColumns; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Set the session database table columns |
|
| 62 | - * @param array $columns the columns definition |
|
| 63 | - */ |
|
| 64 | - public function setSessionTableColumns(array $columns){ |
|
| 65 | - $this->sessionTableColumns = $columns; |
|
| 66 | - return $this; |
|
| 67 | - } |
|
| 60 | + /** |
|
| 61 | + * Set the session database table columns |
|
| 62 | + * @param array $columns the columns definition |
|
| 63 | + */ |
|
| 64 | + public function setSessionTableColumns(array $columns){ |
|
| 65 | + $this->sessionTableColumns = $columns; |
|
| 66 | + return $this; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Delete the expire session |
|
| 71 | - * @param int $time the unix timestamp |
|
| 72 | - * @return int affected rows |
|
| 73 | - */ |
|
| 74 | - abstract public function deleteByTime($time); |
|
| 69 | + /** |
|
| 70 | + * Delete the expire session |
|
| 71 | + * @param int $time the unix timestamp |
|
| 72 | + * @return int affected rows |
|
| 73 | + */ |
|
| 74 | + abstract public function deleteByTime($time); |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * How to get the value of the table column key. Generally is the session key |
|
| 79 | - * @return mixed the key value like used to identify the data |
|
| 80 | - */ |
|
| 81 | - abstract public function getKeyValue(); |
|
| 82 | - } |
|
| 77 | + /** |
|
| 78 | + * How to get the value of the table column key. Generally is the session key |
|
| 79 | + * @return mixed the key value like used to identify the data |
|
| 80 | + */ |
|
| 81 | + abstract public function getKeyValue(); |
|
| 82 | + } |
|
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * You should have received a copy of the GNU General Public License |
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | - */ |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | protected $_temporary_return_type = NULL; |
| 121 | 121 | |
| 122 | 122 | |
| 123 | - /** |
|
| 123 | + /** |
|
| 124 | 124 | The database cache time |
| 125 | - */ |
|
| 126 | - protected $dbCacheTime = 0; |
|
| 125 | + */ |
|
| 126 | + protected $dbCacheTime = 0; |
|
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | 129 | * Instance of the Loader class |
@@ -151,12 +151,12 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | else{ |
| 153 | 153 | $obj = & get_instance(); |
| 154 | - if (isset($obj->database) && is_object($obj->database)){ |
|
| 154 | + if (isset($obj->database) && is_object($obj->database)){ |
|
| 155 | 155 | /** |
| 156 | - * NOTE: Need use "clone" because some Model need have the personal instance of the database library |
|
| 157 | - * to prevent duplication |
|
| 158 | - */ |
|
| 159 | - $this->setDatabaseInstance(clone $obj->database); |
|
| 156 | + * NOTE: Need use "clone" because some Model need have the personal instance of the database library |
|
| 157 | + * to prevent duplication |
|
| 158 | + */ |
|
| 159 | + $this->setDatabaseInstance(clone $obj->database); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | public function get($primary_value) |
| 176 | 176 | { |
| 177 | - return $this->get_by($this->primary_key, $primary_value); |
|
| 177 | + return $this->get_by($this->primary_key, $primary_value); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -189,12 +189,12 @@ discard block |
||
| 189 | 189 | { |
| 190 | 190 | $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
| 191 | 191 | } |
| 192 | - $this->_set_where($where); |
|
| 192 | + $this->_set_where($where); |
|
| 193 | 193 | |
| 194 | 194 | $this->trigger('before_get'); |
| 195 | - $type = $this->_temporary_return_type == 'array' ? 'array' : false; |
|
| 195 | + $type = $this->_temporary_return_type == 'array' ? 'array' : false; |
|
| 196 | 196 | $this->getQueryBuilder()->from($this->_table); |
| 197 | - $row = $this->_database->get($type); |
|
| 197 | + $row = $this->_database->get($type); |
|
| 198 | 198 | $this->_temporary_return_type = $this->return_type; |
| 199 | 199 | $row = $this->trigger('after_get', $row); |
| 200 | 200 | $this->_with = array(); |
@@ -231,9 +231,9 @@ discard block |
||
| 231 | 231 | { |
| 232 | 232 | $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
| 233 | 233 | } |
| 234 | - $type = $this->_temporary_return_type == 'array' ? 'array':false; |
|
| 234 | + $type = $this->_temporary_return_type == 'array' ? 'array':false; |
|
| 235 | 235 | $this->getQueryBuilder()->from($this->_table); |
| 236 | - $result = $this->_database->getAll($type); |
|
| 236 | + $result = $this->_database->getAll($type); |
|
| 237 | 237 | $this->_temporary_return_type = $this->return_type; |
| 238 | 238 | |
| 239 | 239 | foreach ($result as $key => &$row) |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | /** |
| 248 | 248 | * Insert a new row into the table. $data should be an associative array |
| 249 | 249 | * of data to be inserted. Returns newly created ID. |
| 250 | - * @see Database::insert |
|
| 250 | + * @see Database::insert |
|
| 251 | 251 | */ |
| 252 | 252 | public function insert($data = array(), $skip_validation = FALSE, $escape = true) |
| 253 | 253 | { |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | { |
| 261 | 261 | $data = $this->trigger('before_create', $data); |
| 262 | 262 | $this->getQueryBuilder()->from($this->_table); |
| 263 | - $this->_database->insert($data, $escape); |
|
| 263 | + $this->_database->insert($data, $escape); |
|
| 264 | 264 | $insert_id = $this->_database->insertId(); |
| 265 | 265 | $this->trigger('after_create', $insert_id); |
| 266 | - //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
|
| 267 | - return ! $insert_id ? true : $insert_id; |
|
| 266 | + //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
|
| 267 | + return ! $insert_id ? true : $insert_id; |
|
| 268 | 268 | } |
| 269 | 269 | else |
| 270 | 270 | { |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | { |
| 325 | 325 | $this->getQueryBuilder()->in($this->primary_key, $primary_values) |
| 326 | 326 | ->from($this->_table); |
| 327 | - $result = $this->_database->update($data, $escape); |
|
| 327 | + $result = $this->_database->update($data, $escape); |
|
| 328 | 328 | $this->trigger('after_update', array($data, $result)); |
| 329 | 329 | return $result; |
| 330 | 330 | } |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | { |
| 357 | 357 | $this->_set_where($args); |
| 358 | 358 | $this->getQueryBuilder()->from($this->_table); |
| 359 | - $result = $this->_database->update($data); |
|
| 359 | + $result = $this->_database->update($data); |
|
| 360 | 360 | $this->trigger('after_update', array($data, $result)); |
| 361 | 361 | return $result; |
| 362 | 362 | } |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | { |
| 374 | 374 | $data = $this->trigger('before_update', $data); |
| 375 | 375 | $this->getQueryBuilder()->from($this->_table); |
| 376 | - $result = $this->_database->update($data, $escape); |
|
| 376 | + $result = $this->_database->update($data, $escape); |
|
| 377 | 377 | $this->trigger('after_update', array($data, $result)); |
| 378 | 378 | return $result; |
| 379 | 379 | } |
@@ -385,16 +385,16 @@ discard block |
||
| 385 | 385 | { |
| 386 | 386 | $this->trigger('before_delete', $id); |
| 387 | 387 | $this->getQueryBuilder()->where($this->primary_key, $id); |
| 388 | - $result = false; |
|
| 388 | + $result = false; |
|
| 389 | 389 | if ($this->soft_delete) |
| 390 | 390 | { |
| 391 | 391 | $this->getQueryBuilder()->from($this->_table); |
| 392 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 392 | + $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 393 | 393 | } |
| 394 | 394 | else |
| 395 | 395 | { |
| 396 | 396 | $this->getQueryBuilder()->from($this->_table); |
| 397 | - $result = $this->_database->delete(); |
|
| 397 | + $result = $this->_database->delete(); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | $this->trigger('after_delete', $result); |
@@ -407,18 +407,18 @@ discard block |
||
| 407 | 407 | public function delete_by() |
| 408 | 408 | { |
| 409 | 409 | $where = func_get_args(); |
| 410 | - $where = $this->trigger('before_delete', $where); |
|
| 410 | + $where = $this->trigger('before_delete', $where); |
|
| 411 | 411 | $this->_set_where($where); |
| 412 | - $result = false; |
|
| 412 | + $result = false; |
|
| 413 | 413 | if ($this->soft_delete) |
| 414 | 414 | { |
| 415 | 415 | $this->getQueryBuilder()->from($this->_table); |
| 416 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 416 | + $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 417 | 417 | } |
| 418 | 418 | else |
| 419 | 419 | { |
| 420 | 420 | $this->getQueryBuilder()->from($this->_table); |
| 421 | - $result = $this->_database->delete(); |
|
| 421 | + $result = $this->_database->delete(); |
|
| 422 | 422 | } |
| 423 | 423 | $this->trigger('after_delete', $result); |
| 424 | 424 | return $result; |
@@ -431,16 +431,16 @@ discard block |
||
| 431 | 431 | { |
| 432 | 432 | $primary_values = $this->trigger('before_delete', $primary_values); |
| 433 | 433 | $this->getQueryBuilder()->in($this->primary_key, $primary_values); |
| 434 | - $result = false; |
|
| 434 | + $result = false; |
|
| 435 | 435 | if ($this->soft_delete) |
| 436 | 436 | { |
| 437 | 437 | $this->getQueryBuilder()->from($this->_table); |
| 438 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 438 | + $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 439 | 439 | } |
| 440 | 440 | else |
| 441 | 441 | { |
| 442 | 442 | $this->getQueryBuilder()->from($this->_table); |
| 443 | - $result = $this->_database->delete(); |
|
| 443 | + $result = $this->_database->delete(); |
|
| 444 | 444 | } |
| 445 | 445 | $this->trigger('after_delete', $result); |
| 446 | 446 | return $result; |
@@ -452,8 +452,8 @@ discard block |
||
| 452 | 452 | */ |
| 453 | 453 | public function truncate() |
| 454 | 454 | { |
| 455 | - $this->getQueryBuilder()->from($this->_table); |
|
| 456 | - $result = $this->_database->delete(); |
|
| 455 | + $this->getQueryBuilder()->from($this->_table); |
|
| 456 | + $result = $this->_database->delete(); |
|
| 457 | 457 | return $result; |
| 458 | 458 | } |
| 459 | 459 | |
@@ -471,14 +471,14 @@ discard block |
||
| 471 | 471 | return $this; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - /** |
|
| 475 | - * Relationship |
|
| 476 | - */ |
|
| 474 | + /** |
|
| 475 | + * Relationship |
|
| 476 | + */ |
|
| 477 | 477 | public function relate($row) |
| 478 | 478 | { |
| 479 | - if (empty($row)) |
|
| 479 | + if (empty($row)) |
|
| 480 | 480 | { |
| 481 | - return $row; |
|
| 481 | + return $row; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | $row = $this->relateBelongsTo($row); |
@@ -511,9 +511,9 @@ discard block |
||
| 511 | 511 | $this->getQueryBuilder()->where($this->soft_delete_key, FALSE); |
| 512 | 512 | } |
| 513 | 513 | $this->getQueryBuilder() |
| 514 | - ->select(array($key, $value)) |
|
| 515 | - ->from($this->_table); |
|
| 516 | - $result = $this->_database->getAll(); |
|
| 514 | + ->select(array($key, $value)) |
|
| 515 | + ->from($this->_table); |
|
| 516 | + $result = $this->_database->getAll(); |
|
| 517 | 517 | $options = array(); |
| 518 | 518 | foreach ($result as $row) |
| 519 | 519 | { |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | $where = func_get_args(); |
| 536 | 536 | $this->_set_where($where); |
| 537 | 537 | $this->getQueryBuilder()->from($this->_table); |
| 538 | - $this->_database->getAll(); |
|
| 538 | + $this->_database->getAll(); |
|
| 539 | 539 | return $this->_database->numRows(); |
| 540 | 540 | } |
| 541 | 541 | |
@@ -548,20 +548,20 @@ discard block |
||
| 548 | 548 | { |
| 549 | 549 | $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
| 550 | 550 | } |
| 551 | - $this->getQueryBuilder()->from($this->_table); |
|
| 552 | - $this->_database->getAll(); |
|
| 551 | + $this->getQueryBuilder()->from($this->_table); |
|
| 552 | + $this->_database->getAll(); |
|
| 553 | 553 | return $this->_database->numRows(); |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - /** |
|
| 557 | - * Enabled cache temporary |
|
| 558 | - */ |
|
| 559 | - public function cached($ttl = 0){ |
|
| 560 | - if ($ttl > 0){ |
|
| 561 | - $this->_database = $this->_database->cached($ttl); |
|
| 562 | - } |
|
| 563 | - return $this; |
|
| 564 | - } |
|
| 556 | + /** |
|
| 557 | + * Enabled cache temporary |
|
| 558 | + */ |
|
| 559 | + public function cached($ttl = 0){ |
|
| 560 | + if ($ttl > 0){ |
|
| 561 | + $this->_database = $this->_database->cached($ttl); |
|
| 562 | + } |
|
| 563 | + return $this; |
|
| 564 | + } |
|
| 565 | 565 | |
| 566 | 566 | /** |
| 567 | 567 | * Tell the class to skip the insert validation |
@@ -585,10 +585,10 @@ discard block |
||
| 585 | 585 | */ |
| 586 | 586 | public function get_next_id() |
| 587 | 587 | { |
| 588 | - $this->getQueryBuilder()->select('AUTO_INCREMENT') |
|
| 589 | - ->from('information_schema.TABLES') |
|
| 590 | - ->where('TABLE_NAME', $this->_table) |
|
| 591 | - ->where('TABLE_SCHEMA', $this->_database->getDatabaseName()); |
|
| 588 | + $this->getQueryBuilder()->select('AUTO_INCREMENT') |
|
| 589 | + ->from('information_schema.TABLES') |
|
| 590 | + ->where('TABLE_NAME', $this->_table) |
|
| 591 | + ->where('TABLE_SCHEMA', $this->_database->getDatabaseName()); |
|
| 592 | 592 | return (int) $this->_database->get()->AUTO_INCREMENT; |
| 593 | 593 | } |
| 594 | 594 | |
@@ -711,24 +711,24 @@ discard block |
||
| 711 | 711 | { |
| 712 | 712 | if (is_object($row)) |
| 713 | 713 | { |
| 714 | - if (isset($row->$attr)){ |
|
| 715 | - unset($row->$attr); |
|
| 716 | - } |
|
| 714 | + if (isset($row->$attr)){ |
|
| 715 | + unset($row->$attr); |
|
| 716 | + } |
|
| 717 | 717 | } |
| 718 | 718 | else |
| 719 | 719 | { |
| 720 | - if (isset($row[$attr])){ |
|
| 721 | - unset($row[$attr]); |
|
| 722 | - } |
|
| 720 | + if (isset($row[$attr])){ |
|
| 721 | + unset($row[$attr]); |
|
| 722 | + } |
|
| 723 | 723 | } |
| 724 | 724 | } |
| 725 | 725 | return $row; |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | - /** |
|
| 729 | - * Return the database instance |
|
| 730 | - * @return Database the database instance |
|
| 731 | - */ |
|
| 728 | + /** |
|
| 729 | + * Return the database instance |
|
| 730 | + * @return Database the database instance |
|
| 731 | + */ |
|
| 732 | 732 | public function getDatabaseInstance(){ |
| 733 | 733 | return $this->_database; |
| 734 | 734 | } |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | * set the Database instance for future use |
| 738 | 738 | * @param Database $db the database object |
| 739 | 739 | */ |
| 740 | - public function setDatabaseInstance($db){ |
|
| 740 | + public function setDatabaseInstance($db){ |
|
| 741 | 741 | $this->_database = $db; |
| 742 | 742 | if ($this->dbCacheTime > 0){ |
| 743 | 743 | $this->_database->setCache($this->dbCacheTime); |
@@ -756,14 +756,14 @@ discard block |
||
| 756 | 756 | /** |
| 757 | 757 | * Set the loader instance for future use |
| 758 | 758 | * @param Loader $loader the loader object |
| 759 | - * @return object |
|
| 759 | + * @return object |
|
| 760 | 760 | */ |
| 761 | - public function setLoader($loader){ |
|
| 761 | + public function setLoader($loader){ |
|
| 762 | 762 | $this->loaderInstance = $loader; |
| 763 | 763 | return $this; |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | - /** |
|
| 766 | + /** |
|
| 767 | 767 | * Return the queryBuilder instance this is the shortcut to database queryBuilder |
| 768 | 768 | * @return object the DatabaseQueryBuilder instance |
| 769 | 769 | */ |
@@ -774,9 +774,9 @@ discard block |
||
| 774 | 774 | /** |
| 775 | 775 | * Set the DatabaseQueryBuilder instance for future use |
| 776 | 776 | * @param object $queryBuilder the DatabaseQueryBuilder object |
| 777 | - * @return object |
|
| 777 | + * @return object |
|
| 778 | 778 | */ |
| 779 | - public function setQueryBuilder($queryBuilder){ |
|
| 779 | + public function setQueryBuilder($queryBuilder){ |
|
| 780 | 780 | $this->_database->setQueryBuilder($queryBuilder); |
| 781 | 781 | return $this; |
| 782 | 782 | } |
@@ -793,9 +793,9 @@ discard block |
||
| 793 | 793 | /** |
| 794 | 794 | * Set the form validation instance for future use |
| 795 | 795 | * @param FormValidation $fv the form validation object |
| 796 | - * @return object |
|
| 796 | + * @return object |
|
| 797 | 797 | */ |
| 798 | - public function setFormValidation($fv){ |
|
| 798 | + public function setFormValidation($fv){ |
|
| 799 | 799 | $this->formValidationInstance = $fv; |
| 800 | 800 | return $this; |
| 801 | 801 | } |
@@ -836,12 +836,12 @@ discard block |
||
| 836 | 836 | * INTERNAL METHODS |
| 837 | 837 | * ------------------------------------------------------------ */ |
| 838 | 838 | |
| 839 | - /** |
|
| 840 | - * relate for the relation "belongs_to" |
|
| 841 | - * @return mixed |
|
| 842 | - */ |
|
| 843 | - protected function relateBelongsTo($row){ |
|
| 844 | - foreach ($this->belongs_to as $key => $value) |
|
| 839 | + /** |
|
| 840 | + * relate for the relation "belongs_to" |
|
| 841 | + * @return mixed |
|
| 842 | + */ |
|
| 843 | + protected function relateBelongsTo($row){ |
|
| 844 | + foreach ($this->belongs_to as $key => $value) |
|
| 845 | 845 | { |
| 846 | 846 | if (is_string($value)) |
| 847 | 847 | { |
@@ -872,15 +872,15 @@ discard block |
||
| 872 | 872 | } |
| 873 | 873 | } |
| 874 | 874 | } |
| 875 | - return $row; |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - /** |
|
| 879 | - * relate for the relation "has_many" |
|
| 880 | - * @return mixed |
|
| 881 | - */ |
|
| 882 | - protected function relateHasMany($row){ |
|
| 883 | - foreach ($this->has_many as $key => $value) |
|
| 875 | + return $row; |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + /** |
|
| 879 | + * relate for the relation "has_many" |
|
| 880 | + * @return mixed |
|
| 881 | + */ |
|
| 882 | + protected function relateHasMany($row){ |
|
| 883 | + foreach ($this->has_many as $key => $value) |
|
| 884 | 884 | { |
| 885 | 885 | if (is_string($value)) |
| 886 | 886 | { |
@@ -911,8 +911,8 @@ discard block |
||
| 911 | 911 | } |
| 912 | 912 | } |
| 913 | 913 | } |
| 914 | - return $row; |
|
| 915 | - } |
|
| 914 | + return $row; |
|
| 915 | + } |
|
| 916 | 916 | |
| 917 | 917 | /** |
| 918 | 918 | * Trigger an event and call its observers. Pass through the event name |
@@ -977,30 +977,30 @@ discard block |
||
| 977 | 977 | } |
| 978 | 978 | |
| 979 | 979 | |
| 980 | - /** |
|
| 981 | - * Set WHERE parameters, when is array |
|
| 982 | - * @param array $params |
|
| 983 | - */ |
|
| 984 | - protected function _set_where_array(array $params){ |
|
| 985 | - foreach ($params as $field => $filter) |
|
| 986 | - { |
|
| 987 | - if (is_array($filter)) |
|
| 988 | - { |
|
| 989 | - $this->getQueryBuilder()->in($field, $filter); |
|
| 990 | - } |
|
| 991 | - else |
|
| 992 | - { |
|
| 993 | - if (is_int($field)) |
|
| 994 | - { |
|
| 995 | - $this->getQueryBuilder()->where($filter); |
|
| 996 | - } |
|
| 997 | - else |
|
| 998 | - { |
|
| 999 | - $this->getQueryBuilder()->where($field, $filter); |
|
| 1000 | - } |
|
| 1001 | - } |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 980 | + /** |
|
| 981 | + * Set WHERE parameters, when is array |
|
| 982 | + * @param array $params |
|
| 983 | + */ |
|
| 984 | + protected function _set_where_array(array $params){ |
|
| 985 | + foreach ($params as $field => $filter) |
|
| 986 | + { |
|
| 987 | + if (is_array($filter)) |
|
| 988 | + { |
|
| 989 | + $this->getQueryBuilder()->in($field, $filter); |
|
| 990 | + } |
|
| 991 | + else |
|
| 992 | + { |
|
| 993 | + if (is_int($field)) |
|
| 994 | + { |
|
| 995 | + $this->getQueryBuilder()->where($filter); |
|
| 996 | + } |
|
| 997 | + else |
|
| 998 | + { |
|
| 999 | + $this->getQueryBuilder()->where($field, $filter); |
|
| 1000 | + } |
|
| 1001 | + } |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | 1004 | |
| 1005 | 1005 | |
| 1006 | 1006 | /** |
@@ -1016,8 +1016,8 @@ discard block |
||
| 1016 | 1016 | { |
| 1017 | 1017 | $this->getQueryBuilder()->where($params[0]); |
| 1018 | 1018 | } |
| 1019 | - else if (count($params) == 2) |
|
| 1020 | - { |
|
| 1019 | + else if (count($params) == 2) |
|
| 1020 | + { |
|
| 1021 | 1021 | if (is_array($params[1])) |
| 1022 | 1022 | { |
| 1023 | 1023 | $this->getQueryBuilder()->in($params[0], $params[1]); |
@@ -1026,11 +1026,11 @@ discard block |
||
| 1026 | 1026 | { |
| 1027 | 1027 | $this->getQueryBuilder()->where($params[0], $params[1]); |
| 1028 | 1028 | } |
| 1029 | - } |
|
| 1030 | - else if (count($params) == 3) |
|
| 1031 | - { |
|
| 1032 | - $this->getQueryBuilder()->where($params[0], $params[1], $params[2]); |
|
| 1033 | - } |
|
| 1029 | + } |
|
| 1030 | + else if (count($params) == 3) |
|
| 1031 | + { |
|
| 1032 | + $this->getQueryBuilder()->where($params[0], $params[1], $params[2]); |
|
| 1033 | + } |
|
| 1034 | 1034 | else |
| 1035 | 1035 | { |
| 1036 | 1036 | if (is_array($params[1])) |
@@ -1046,7 +1046,7 @@ discard block |
||
| 1046 | 1046 | |
| 1047 | 1047 | /** |
| 1048 | 1048 | Shortcut to controller |
| 1049 | - */ |
|
| 1049 | + */ |
|
| 1050 | 1050 | public function __get($key){ |
| 1051 | 1051 | return get_instance()->{$key}; |
| 1052 | 1052 | } |
@@ -1,208 +1,208 @@ |
||
| 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 | - */ |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * For application languages management |
|
| 29 | - */ |
|
| 30 | - class Lang{ |
|
| 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 | + |
|
| 27 | + /** |
|
| 28 | + * For application languages management |
|
| 29 | + */ |
|
| 30 | + class Lang{ |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The supported available language for this application. |
|
| 34 | - * @example "en" => "english" |
|
| 35 | - * @see Lang::addLang() |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $availables = array(); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * The all messages language |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - protected $languages = array(); |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * The default language to use if can not |
|
| 48 | - * determine the client language |
|
| 49 | - * |
|
| 50 | - * @example $default = 'en' |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - protected $default = null; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * The current client language |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - protected $current = null; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * The logger instance |
|
| 63 | - * @var Log |
|
| 64 | - */ |
|
| 65 | - private $logger; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Construct new Lang instance |
|
| 69 | - */ |
|
| 70 | - public function __construct(){ |
|
| 71 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 72 | - $this->logger->setLogger('Library::Lang'); |
|
| 73 | - |
|
| 74 | - $this->default = get_config('default_language', 'en'); |
|
| 75 | - $this->logger->debug('Setting the supported languages'); |
|
| 32 | + /** |
|
| 33 | + * The supported available language for this application. |
|
| 34 | + * @example "en" => "english" |
|
| 35 | + * @see Lang::addLang() |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $availables = array(); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * The all messages language |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + protected $languages = array(); |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * The default language to use if can not |
|
| 48 | + * determine the client language |
|
| 49 | + * |
|
| 50 | + * @example $default = 'en' |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + protected $default = null; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * The current client language |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + protected $current = null; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * The logger instance |
|
| 63 | + * @var Log |
|
| 64 | + */ |
|
| 65 | + private $logger; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Construct new Lang instance |
|
| 69 | + */ |
|
| 70 | + public function __construct(){ |
|
| 71 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 72 | + $this->logger->setLogger('Library::Lang'); |
|
| 73 | + |
|
| 74 | + $this->default = get_config('default_language', 'en'); |
|
| 75 | + $this->logger->debug('Setting the supported languages'); |
|
| 76 | 76 | |
| 77 | - //add the supported languages ('key', 'display name') |
|
| 78 | - $languages = get_config('languages', null); |
|
| 79 | - if(! empty($languages)){ |
|
| 80 | - foreach($languages as $key => $displayName){ |
|
| 81 | - $this->addLang($key, $displayName); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - unset($languages); |
|
| 85 | - |
|
| 86 | - //if the language exists in cookie use it |
|
| 87 | - $cfgKey = get_config('language_cookie_name'); |
|
| 88 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
| 89 | - $objCookie = & class_loader('Cookie'); |
|
| 90 | - $cookieLang = $objCookie->get($cfgKey); |
|
| 91 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
| 92 | - $this->current = $cookieLang; |
|
| 93 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
| 94 | - } |
|
| 95 | - else{ |
|
| 96 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
| 97 | - $this->current = $this->getDefault(); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Get the all languages messages |
|
| 103 | - * |
|
| 104 | - * @return array the language message list |
|
| 105 | - */ |
|
| 106 | - public function getAll(){ |
|
| 107 | - return $this->languages; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Set the language message |
|
| 112 | - * |
|
| 113 | - * @param string $key the language key to identify |
|
| 114 | - * @param string $value the language message value |
|
| 115 | - */ |
|
| 116 | - public function set($key, $value){ |
|
| 117 | - $this->languages[$key] = $value; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Get the language message for the given key. If can't find return the default value |
|
| 122 | - * |
|
| 123 | - * @param string $key the message language key |
|
| 124 | - * @param string $default the default value to return if can not found the language message key |
|
| 125 | - * |
|
| 126 | - * @return string the language message value |
|
| 127 | - */ |
|
| 128 | - public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
| 129 | - if(isset($this->languages[$key])){ |
|
| 130 | - return $this->languages[$key]; |
|
| 131 | - } |
|
| 132 | - $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
| 133 | - return $default; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Check whether the language file for given name exists |
|
| 138 | - * |
|
| 139 | - * @param string $language the language name like "fr", "en", etc. |
|
| 140 | - * |
|
| 141 | - * @return boolean true if the language directory exists, false or not |
|
| 142 | - */ |
|
| 143 | - public function isValid($language){ |
|
| 144 | - $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
|
| 145 | - foreach($searchDir as $dir){ |
|
| 146 | - if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
| 147 | - return true; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - return false; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Get the default language value like "en" , "fr", etc. |
|
| 155 | - * |
|
| 156 | - * @return string the default language |
|
| 157 | - */ |
|
| 158 | - public function getDefault(){ |
|
| 159 | - return $this->default; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Get the current language defined by cookie or the default value |
|
| 164 | - * |
|
| 165 | - * @return string the current language |
|
| 166 | - */ |
|
| 167 | - public function getCurrent(){ |
|
| 168 | - return $this->current; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Add new supported or available language |
|
| 173 | - * |
|
| 174 | - * @param string $name the short language name like "en", "fr". |
|
| 175 | - * @param string $description the human readable description of this language |
|
| 176 | - */ |
|
| 177 | - public function addLang($name, $description){ |
|
| 178 | - if(isset($this->availables[$name])){ |
|
| 179 | - return; //already added cost in performance |
|
| 180 | - } |
|
| 181 | - if($this->isValid($name)){ |
|
| 182 | - $this->availables[$name] = $description; |
|
| 183 | - } |
|
| 184 | - else{ |
|
| 185 | - show_error('The language [' . $name . '] is not valid or does not exists.'); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Get the list of the application supported language |
|
| 191 | - * |
|
| 192 | - * @return array the list of the application language |
|
| 193 | - */ |
|
| 194 | - public function getSupported(){ |
|
| 195 | - return $this->availables; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Add new language messages |
|
| 200 | - * |
|
| 201 | - * @param array $langs the languages array of the messages to be added |
|
| 202 | - */ |
|
| 203 | - public function addLangMessages(array $langs){ |
|
| 204 | - foreach ($langs as $key => $value) { |
|
| 205 | - $this->set($key, $value); |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - } |
|
| 77 | + //add the supported languages ('key', 'display name') |
|
| 78 | + $languages = get_config('languages', null); |
|
| 79 | + if(! empty($languages)){ |
|
| 80 | + foreach($languages as $key => $displayName){ |
|
| 81 | + $this->addLang($key, $displayName); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + unset($languages); |
|
| 85 | + |
|
| 86 | + //if the language exists in cookie use it |
|
| 87 | + $cfgKey = get_config('language_cookie_name'); |
|
| 88 | + $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
| 89 | + $objCookie = & class_loader('Cookie'); |
|
| 90 | + $cookieLang = $objCookie->get($cfgKey); |
|
| 91 | + if($cookieLang && $this->isValid($cookieLang)){ |
|
| 92 | + $this->current = $cookieLang; |
|
| 93 | + $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
| 94 | + } |
|
| 95 | + else{ |
|
| 96 | + $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
| 97 | + $this->current = $this->getDefault(); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Get the all languages messages |
|
| 103 | + * |
|
| 104 | + * @return array the language message list |
|
| 105 | + */ |
|
| 106 | + public function getAll(){ |
|
| 107 | + return $this->languages; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Set the language message |
|
| 112 | + * |
|
| 113 | + * @param string $key the language key to identify |
|
| 114 | + * @param string $value the language message value |
|
| 115 | + */ |
|
| 116 | + public function set($key, $value){ |
|
| 117 | + $this->languages[$key] = $value; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Get the language message for the given key. If can't find return the default value |
|
| 122 | + * |
|
| 123 | + * @param string $key the message language key |
|
| 124 | + * @param string $default the default value to return if can not found the language message key |
|
| 125 | + * |
|
| 126 | + * @return string the language message value |
|
| 127 | + */ |
|
| 128 | + public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
| 129 | + if(isset($this->languages[$key])){ |
|
| 130 | + return $this->languages[$key]; |
|
| 131 | + } |
|
| 132 | + $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
| 133 | + return $default; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Check whether the language file for given name exists |
|
| 138 | + * |
|
| 139 | + * @param string $language the language name like "fr", "en", etc. |
|
| 140 | + * |
|
| 141 | + * @return boolean true if the language directory exists, false or not |
|
| 142 | + */ |
|
| 143 | + public function isValid($language){ |
|
| 144 | + $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
|
| 145 | + foreach($searchDir as $dir){ |
|
| 146 | + if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
| 147 | + return true; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + return false; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Get the default language value like "en" , "fr", etc. |
|
| 155 | + * |
|
| 156 | + * @return string the default language |
|
| 157 | + */ |
|
| 158 | + public function getDefault(){ |
|
| 159 | + return $this->default; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Get the current language defined by cookie or the default value |
|
| 164 | + * |
|
| 165 | + * @return string the current language |
|
| 166 | + */ |
|
| 167 | + public function getCurrent(){ |
|
| 168 | + return $this->current; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Add new supported or available language |
|
| 173 | + * |
|
| 174 | + * @param string $name the short language name like "en", "fr". |
|
| 175 | + * @param string $description the human readable description of this language |
|
| 176 | + */ |
|
| 177 | + public function addLang($name, $description){ |
|
| 178 | + if(isset($this->availables[$name])){ |
|
| 179 | + return; //already added cost in performance |
|
| 180 | + } |
|
| 181 | + if($this->isValid($name)){ |
|
| 182 | + $this->availables[$name] = $description; |
|
| 183 | + } |
|
| 184 | + else{ |
|
| 185 | + show_error('The language [' . $name . '] is not valid or does not exists.'); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Get the list of the application supported language |
|
| 191 | + * |
|
| 192 | + * @return array the list of the application language |
|
| 193 | + */ |
|
| 194 | + public function getSupported(){ |
|
| 195 | + return $this->availables; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Add new language messages |
|
| 200 | + * |
|
| 201 | + * @param array $langs the languages array of the messages to be added |
|
| 202 | + */ |
|
| 203 | + public function addLangMessages(array $langs){ |
|
| 204 | + foreach ($langs as $key => $value) { |
|
| 205 | + $this->set($key, $value); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + } |
|
@@ -1,52 +1,52 @@ |
||
| 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 | - if(! function_exists('__')){ |
|
| 28 | - /** |
|
| 29 | - * function for the shortcut to Lang::get() |
|
| 30 | - * @param string $key the language key to retrieve |
|
| 31 | - * @param mixed $default the default value to return if can not find the value |
|
| 32 | - * for the given key |
|
| 33 | - * @return string the language value |
|
| 34 | - */ |
|
| 35 | - function __($key, $default = 'LANGUAGE_ERROR'){ |
|
| 36 | - return get_instance()->lang->get($key, $default); |
|
| 37 | - } |
|
| 27 | + if(! function_exists('__')){ |
|
| 28 | + /** |
|
| 29 | + * function for the shortcut to Lang::get() |
|
| 30 | + * @param string $key the language key to retrieve |
|
| 31 | + * @param mixed $default the default value to return if can not find the value |
|
| 32 | + * for the given key |
|
| 33 | + * @return string the language value |
|
| 34 | + */ |
|
| 35 | + function __($key, $default = 'LANGUAGE_ERROR'){ |
|
| 36 | + return get_instance()->lang->get($key, $default); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - if(! function_exists('get_languages')){ |
|
| 43 | - /** |
|
| 44 | - * function for the shortcut to Lang::getSupported() |
|
| 45 | - * |
|
| 46 | - * @return array all the supported languages |
|
| 47 | - */ |
|
| 48 | - function get_languages(){ |
|
| 49 | - return get_instance()->lang->getSupported(); |
|
| 50 | - } |
|
| 42 | + if(! function_exists('get_languages')){ |
|
| 43 | + /** |
|
| 44 | + * function for the shortcut to Lang::getSupported() |
|
| 45 | + * |
|
| 46 | + * @return array all the supported languages |
|
| 47 | + */ |
|
| 48 | + function get_languages(){ |
|
| 49 | + return get_instance()->lang->getSupported(); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - } |
|
| 53 | 52 | \ No newline at end of file |
| 53 | + } |
|
| 54 | 54 | \ No newline at end of file |
@@ -1,74 +1,74 @@ |
||
| 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 function_string.php |
|
| 29 | - * |
|
| 30 | - * This file contains the definition of the functions relating to the processing of strings characters. |
|
| 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 | - */ |
|
| 27 | + /** |
|
| 28 | + * @file function_string.php |
|
| 29 | + * |
|
| 30 | + * This file contains the definition of the functions relating to the processing of strings characters. |
|
| 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 | 41 | |
| 42 | - if(! function_exists('get_random_string')){ |
|
| 43 | - /** |
|
| 44 | - * Generate a random string |
|
| 45 | - * @param string $type the type of generation. It can take the values: "alpha" for alphabetic characters, |
|
| 46 | - * "alnum" for alpha-numeric characters and "num" for numbers. |
|
| 47 | - * By default it is "alnum". |
|
| 48 | - * @param integer $length the length of the string to generate. By default it is 10. |
|
| 49 | - * @param boolean $lower if we return the generated string in lowercase (true). By default it's false. |
|
| 50 | - * @return string the generated string. |
|
| 51 | - */ |
|
| 52 | - function get_random_string($type = 'alnum', $length = 10, $lower = false){ |
|
| 53 | - $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; |
|
| 54 | - switch($type){ |
|
| 55 | - case 'alpha': |
|
| 56 | - $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
| 57 | - break; |
|
| 58 | - case 'alnum': |
|
| 59 | - $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; |
|
| 60 | - break; |
|
| 61 | - case 'num': |
|
| 62 | - $str = '1234567890'; |
|
| 63 | - break; |
|
| 64 | - } |
|
| 65 | - $random = null; |
|
| 66 | - for($i = 0; $i < $length; $i++){ |
|
| 67 | - $random .= $str[mt_rand() % strlen($str)]; |
|
| 68 | - } |
|
| 69 | - if($lower){ |
|
| 70 | - $random = strtolower($random); |
|
| 71 | - } |
|
| 72 | - return $random; |
|
| 73 | - } |
|
| 74 | - } |
|
| 42 | + if(! function_exists('get_random_string')){ |
|
| 43 | + /** |
|
| 44 | + * Generate a random string |
|
| 45 | + * @param string $type the type of generation. It can take the values: "alpha" for alphabetic characters, |
|
| 46 | + * "alnum" for alpha-numeric characters and "num" for numbers. |
|
| 47 | + * By default it is "alnum". |
|
| 48 | + * @param integer $length the length of the string to generate. By default it is 10. |
|
| 49 | + * @param boolean $lower if we return the generated string in lowercase (true). By default it's false. |
|
| 50 | + * @return string the generated string. |
|
| 51 | + */ |
|
| 52 | + function get_random_string($type = 'alnum', $length = 10, $lower = false){ |
|
| 53 | + $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; |
|
| 54 | + switch($type){ |
|
| 55 | + case 'alpha': |
|
| 56 | + $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
| 57 | + break; |
|
| 58 | + case 'alnum': |
|
| 59 | + $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; |
|
| 60 | + break; |
|
| 61 | + case 'num': |
|
| 62 | + $str = '1234567890'; |
|
| 63 | + break; |
|
| 64 | + } |
|
| 65 | + $random = null; |
|
| 66 | + for($i = 0; $i < $length; $i++){ |
|
| 67 | + $random .= $str[mt_rand() % strlen($str)]; |
|
| 68 | + } |
|
| 69 | + if($lower){ |
|
| 70 | + $random = strtolower($random); |
|
| 71 | + } |
|
| 72 | + return $random; |
|
| 73 | + } |
|
| 74 | + } |
|
@@ -1,739 +1,739 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * Simple Mail |
|
| 5 | - * |
|
| 6 | - * A simple PHP wrapper class for sending email using the mail() method. |
|
| 7 | - * |
|
| 8 | - * PHP version > 5.2 |
|
| 9 | - * |
|
| 10 | - * LICENSE: This source file is subject to the MIT license, which is |
|
| 11 | - * available through the world-wide-web at the following URI: |
|
| 12 | - * http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt |
|
| 13 | - * |
|
| 14 | - * @category SimpleMail |
|
| 15 | - * @package SimpleMail |
|
| 16 | - * @author Eoghan O'Brien <[email protected]> |
|
| 17 | - * @copyright 2009 - 2017 Eoghan O'Brien |
|
| 18 | - * @license http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT |
|
| 19 | - * @version 1.7.1 |
|
| 20 | - * @link http://github.com/eoghanobrien/php-simple-mail |
|
| 21 | - */ |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Simple Mail class. |
|
| 25 | - * |
|
| 26 | - * @category SimpleMail |
|
| 27 | - * @package SimpleMail |
|
| 28 | - * @author Eoghan O'Brien <[email protected]> |
|
| 29 | - * @copyright 2009 - 2017 Eoghan O'Brien |
|
| 30 | - * @license http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT |
|
| 31 | - * @version 1.7.1 |
|
| 32 | - * @link http://github.com/eoghanobrien/php-simple-mail |
|
| 33 | - */ |
|
| 34 | - class Email |
|
| 35 | - { |
|
| 36 | - /** |
|
| 37 | - * @var int $_wrap |
|
| 38 | - */ |
|
| 39 | - protected $_wrap = 78; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var array $_to |
|
| 43 | - */ |
|
| 44 | - protected $_to = array(); |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string $_subject |
|
| 48 | - */ |
|
| 49 | - protected $_subject; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var string $_message |
|
| 53 | - */ |
|
| 54 | - protected $_message; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var array $_headers |
|
| 58 | - */ |
|
| 59 | - protected $_headers = array(); |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var string $_parameters |
|
| 63 | - */ |
|
| 64 | - protected $_params; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var array $_attachments |
|
| 68 | - */ |
|
| 69 | - protected $_attachments = array(); |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var string $_uid |
|
| 73 | - */ |
|
| 74 | - protected $_uid; |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * Simple Mail |
|
| 5 | + * |
|
| 6 | + * A simple PHP wrapper class for sending email using the mail() method. |
|
| 7 | + * |
|
| 8 | + * PHP version > 5.2 |
|
| 9 | + * |
|
| 10 | + * LICENSE: This source file is subject to the MIT license, which is |
|
| 11 | + * available through the world-wide-web at the following URI: |
|
| 12 | + * http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt |
|
| 13 | + * |
|
| 14 | + * @category SimpleMail |
|
| 15 | + * @package SimpleMail |
|
| 16 | + * @author Eoghan O'Brien <[email protected]> |
|
| 17 | + * @copyright 2009 - 2017 Eoghan O'Brien |
|
| 18 | + * @license http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT |
|
| 19 | + * @version 1.7.1 |
|
| 20 | + * @link http://github.com/eoghanobrien/php-simple-mail |
|
| 21 | + */ |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Simple Mail class. |
|
| 25 | + * |
|
| 26 | + * @category SimpleMail |
|
| 27 | + * @package SimpleMail |
|
| 28 | + * @author Eoghan O'Brien <[email protected]> |
|
| 29 | + * @copyright 2009 - 2017 Eoghan O'Brien |
|
| 30 | + * @license http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT |
|
| 31 | + * @version 1.7.1 |
|
| 32 | + * @link http://github.com/eoghanobrien/php-simple-mail |
|
| 33 | + */ |
|
| 34 | + class Email |
|
| 35 | + { |
|
| 36 | + /** |
|
| 37 | + * @var int $_wrap |
|
| 38 | + */ |
|
| 39 | + protected $_wrap = 78; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var array $_to |
|
| 43 | + */ |
|
| 44 | + protected $_to = array(); |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string $_subject |
|
| 48 | + */ |
|
| 49 | + protected $_subject; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var string $_message |
|
| 53 | + */ |
|
| 54 | + protected $_message; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var array $_headers |
|
| 58 | + */ |
|
| 59 | + protected $_headers = array(); |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var string $_parameters |
|
| 63 | + */ |
|
| 64 | + protected $_params; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var array $_attachments |
|
| 68 | + */ |
|
| 69 | + protected $_attachments = array(); |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var string $_uid |
|
| 73 | + */ |
|
| 74 | + protected $_uid; |
|
| 75 | 75 | |
| 76 | - /** |
|
| 76 | + /** |
|
| 77 | 77 | * The logger instance |
| 78 | 78 | * @var Log |
| 79 | 79 | */ |
| 80 | - private $logger; |
|
| 80 | + private $logger; |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * __construct |
|
| 84 | - * |
|
| 85 | - * Resets the class properties. |
|
| 86 | - */ |
|
| 87 | - public function __construct() |
|
| 88 | - { |
|
| 89 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 82 | + /** |
|
| 83 | + * __construct |
|
| 84 | + * |
|
| 85 | + * Resets the class properties. |
|
| 86 | + */ |
|
| 87 | + public function __construct() |
|
| 88 | + { |
|
| 89 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 90 | 90 | $this->logger->setLogger('Library::Email'); |
| 91 | - $this->reset(); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * reset |
|
| 96 | - * |
|
| 97 | - * Resets all properties to initial state. |
|
| 98 | - * |
|
| 99 | - * @return self |
|
| 100 | - */ |
|
| 101 | - public function reset() |
|
| 102 | - { |
|
| 103 | - $this->_to = array(); |
|
| 104 | - $this->_headers = array(); |
|
| 105 | - $this->_subject = null; |
|
| 106 | - $this->_message = null; |
|
| 107 | - $this->_wrap = 78; |
|
| 108 | - $this->_params = null; |
|
| 109 | - $this->_attachments = array(); |
|
| 110 | - $this->_uid = $this->getUniqueId(); |
|
| 111 | - return $this; |
|
| 112 | - } |
|
| 91 | + $this->reset(); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * reset |
|
| 96 | + * |
|
| 97 | + * Resets all properties to initial state. |
|
| 98 | + * |
|
| 99 | + * @return self |
|
| 100 | + */ |
|
| 101 | + public function reset() |
|
| 102 | + { |
|
| 103 | + $this->_to = array(); |
|
| 104 | + $this->_headers = array(); |
|
| 105 | + $this->_subject = null; |
|
| 106 | + $this->_message = null; |
|
| 107 | + $this->_wrap = 78; |
|
| 108 | + $this->_params = null; |
|
| 109 | + $this->_attachments = array(); |
|
| 110 | + $this->_uid = $this->getUniqueId(); |
|
| 111 | + return $this; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * setFrom |
|
| 116 | - * |
|
| 117 | - * @param string $email The email to send as from. |
|
| 118 | - * @param string $name The name to send as from. |
|
| 119 | - * |
|
| 120 | - * @return self |
|
| 121 | - */ |
|
| 122 | - public function setFrom($email, $name = null) |
|
| 123 | - { |
|
| 124 | - $this->addMailHeader('From', (string) $email, (string) $name); |
|
| 125 | - return $this; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * setTo |
|
| 130 | - * |
|
| 131 | - * @param string $email The email address to send to. |
|
| 132 | - * @param string $name The name of the person to send to. |
|
| 133 | - * |
|
| 134 | - * @return self |
|
| 135 | - */ |
|
| 136 | - public function setTo($email, $name = null) |
|
| 137 | - { |
|
| 138 | - $this->_to[] = $this->formatHeader((string) $email, (string) $name); |
|
| 139 | - return $this; |
|
| 140 | - } |
|
| 114 | + /** |
|
| 115 | + * setFrom |
|
| 116 | + * |
|
| 117 | + * @param string $email The email to send as from. |
|
| 118 | + * @param string $name The name to send as from. |
|
| 119 | + * |
|
| 120 | + * @return self |
|
| 121 | + */ |
|
| 122 | + public function setFrom($email, $name = null) |
|
| 123 | + { |
|
| 124 | + $this->addMailHeader('From', (string) $email, (string) $name); |
|
| 125 | + return $this; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * setTo |
|
| 130 | + * |
|
| 131 | + * @param string $email The email address to send to. |
|
| 132 | + * @param string $name The name of the person to send to. |
|
| 133 | + * |
|
| 134 | + * @return self |
|
| 135 | + */ |
|
| 136 | + public function setTo($email, $name = null) |
|
| 137 | + { |
|
| 138 | + $this->_to[] = $this->formatHeader((string) $email, (string) $name); |
|
| 139 | + return $this; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Set destination using array |
|
| 144 | - * @params array $emails the list of recipient. This is an associative array name => email |
|
| 145 | - * @example array('John Doe' => '[email protected]') |
|
| 146 | - * @return Object the current instance |
|
| 147 | - */ |
|
| 148 | - public function setTos(array $emails) |
|
| 149 | - { |
|
| 150 | - foreach ($emails as $name => $email) { |
|
| 151 | - if(is_numeric($name)){ |
|
| 152 | - $this->setTo($email); |
|
| 153 | - } |
|
| 154 | - else{ |
|
| 155 | - $this->setTo($email, $name); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - return $this; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * getTo |
|
| 164 | - * |
|
| 165 | - * Return an array of formatted To addresses. |
|
| 166 | - * |
|
| 167 | - * @return array |
|
| 168 | - */ |
|
| 169 | - public function getTo() |
|
| 170 | - { |
|
| 171 | - return $this->_to; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * setCc |
|
| 177 | - * |
|
| 178 | - * @param array $pairs An array of name => email pairs. |
|
| 179 | - * |
|
| 180 | - * @return self |
|
| 181 | - */ |
|
| 182 | - public function setCc(array $pairs) |
|
| 183 | - { |
|
| 184 | - return $this->addMailHeaders('Cc', $pairs); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * setBcc |
|
| 189 | - * |
|
| 190 | - * @param array $pairs An array of name => email pairs. |
|
| 191 | - * |
|
| 192 | - * @return self |
|
| 193 | - */ |
|
| 194 | - public function setBcc(array $pairs) |
|
| 195 | - { |
|
| 196 | - return $this->addMailHeaders('Bcc', $pairs); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * setReplyTo |
|
| 201 | - * |
|
| 202 | - * @param string $email |
|
| 203 | - * @param string $name |
|
| 204 | - * |
|
| 205 | - * @return self |
|
| 206 | - */ |
|
| 207 | - public function setReplyTo($email, $name = null) |
|
| 208 | - { |
|
| 209 | - return $this->addMailHeader('Reply-To', $email, $name); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * setHtml |
|
| 214 | - * |
|
| 215 | - * @return self |
|
| 216 | - */ |
|
| 217 | - public function setHtml() |
|
| 218 | - { |
|
| 219 | - $this->addGenericHeader( |
|
| 220 | - 'Content-Type', 'text/html; charset="utf-8"' |
|
| 221 | - ); |
|
| 222 | - return $this; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * setSubject |
|
| 227 | - * |
|
| 228 | - * @param string $subject The email subject |
|
| 229 | - * |
|
| 230 | - * @return self |
|
| 231 | - */ |
|
| 232 | - public function setSubject($subject) |
|
| 233 | - { |
|
| 234 | - $this->_subject = $this->encodeUtf8( |
|
| 235 | - $this->filterOther((string) $subject) |
|
| 236 | - ); |
|
| 237 | - return $this; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * getSubject function. |
|
| 242 | - * |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - public function getSubject() |
|
| 246 | - { |
|
| 247 | - return $this->_subject; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * setMessage |
|
| 252 | - * |
|
| 253 | - * @param string $message The message to send. |
|
| 254 | - * |
|
| 255 | - * @return self |
|
| 256 | - */ |
|
| 257 | - public function setMessage($message) |
|
| 258 | - { |
|
| 259 | - $this->_message = str_replace("\n.", "\n..", (string) $message); |
|
| 260 | - return $this; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * getMessage |
|
| 265 | - * |
|
| 266 | - * @return string |
|
| 267 | - */ |
|
| 268 | - public function getMessage() |
|
| 269 | - { |
|
| 270 | - return $this->_message; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * addAttachment |
|
| 275 | - * |
|
| 276 | - * @param string $path The file path to the attachment. |
|
| 277 | - * @param string $filename The filename of the attachment when emailed. |
|
| 278 | - * @param string $data |
|
| 279 | - * |
|
| 280 | - * @return self |
|
| 281 | - */ |
|
| 282 | - public function addAttachment($path, $filename = null, $data = null) |
|
| 283 | - { |
|
| 284 | - if(! file_exists($path)){ |
|
| 285 | - show_error('The file [' .$path. '] does not exists.'); |
|
| 286 | - } |
|
| 287 | - $filename = empty($filename) ? basename($path) : $filename; |
|
| 288 | - $filename = $this->encodeUtf8($this->filterOther((string) $filename)); |
|
| 289 | - $data = empty($data) ? $this->getAttachmentData($path) : $data; |
|
| 290 | - $this->_attachments[] = array( |
|
| 291 | - 'path' => $path, |
|
| 292 | - 'file' => $filename, |
|
| 293 | - 'data' => chunk_split(base64_encode($data)) |
|
| 294 | - ); |
|
| 295 | - return $this; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * getAttachmentData |
|
| 300 | - * |
|
| 301 | - * @param string $path The path to the attachment file. |
|
| 302 | - * |
|
| 303 | - * @return string |
|
| 304 | - */ |
|
| 305 | - public function getAttachmentData($path) |
|
| 306 | - { |
|
| 307 | - if(! file_exists($path)){ |
|
| 308 | - show_error('The file [' .$path. '] does not exists.'); |
|
| 309 | - } |
|
| 310 | - $filesize = filesize($path); |
|
| 311 | - $handle = fopen($path, "r"); |
|
| 312 | - $attachment = null; |
|
| 313 | - if(is_resource($handle)){ |
|
| 314 | - $attachment = fread($handle, $filesize); |
|
| 315 | - fclose($handle); |
|
| 316 | - } |
|
| 317 | - return $attachment; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * addMailHeader |
|
| 322 | - * |
|
| 323 | - * @param string $header The header to add. |
|
| 324 | - * @param string $email The email to add. |
|
| 325 | - * @param string $name The name to add. |
|
| 326 | - * |
|
| 327 | - * @return self |
|
| 328 | - */ |
|
| 329 | - public function addMailHeader($header, $email, $name = null) |
|
| 330 | - { |
|
| 331 | - $address = $this->formatHeader((string) $email, (string) $name); |
|
| 332 | - $this->_headers[] = sprintf('%s: %s', (string) $header, $address); |
|
| 333 | - return $this; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * addMailHeaders |
|
| 338 | - * |
|
| 339 | - * @param string $header The header to add. |
|
| 340 | - * @param array $pairs An array of name => email pairs. |
|
| 341 | - * |
|
| 342 | - * @return self |
|
| 343 | - */ |
|
| 344 | - public function addMailHeaders($header, array $pairs) |
|
| 345 | - { |
|
| 346 | - if (count($pairs) === 0) { |
|
| 347 | - show_error('You must pass at least one name => email pair.'); |
|
| 348 | - } |
|
| 349 | - $addresses = array(); |
|
| 350 | - foreach ($pairs as $name => $email) { |
|
| 351 | - $name = is_numeric($name) ? null : $name; |
|
| 352 | - $addresses[] = $this->formatHeader($email, $name); |
|
| 353 | - } |
|
| 354 | - $this->addGenericHeader($header, implode(',', $addresses)); |
|
| 355 | - return $this; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * addGenericHeader |
|
| 360 | - * |
|
| 361 | - * @param string $name The generic header to add. |
|
| 362 | - * @param mixed $value The value of the header. |
|
| 363 | - * |
|
| 364 | - * @return self |
|
| 365 | - */ |
|
| 366 | - public function addGenericHeader($name, $value) |
|
| 367 | - { |
|
| 368 | - $this->_headers[] = sprintf( |
|
| 369 | - '%s: %s', |
|
| 370 | - (string) $name, |
|
| 371 | - (string) $value |
|
| 372 | - ); |
|
| 373 | - return $this; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * getHeaders |
|
| 378 | - * |
|
| 379 | - * Return the headers registered so far as an array. |
|
| 380 | - * |
|
| 381 | - * @return array |
|
| 382 | - */ |
|
| 383 | - public function getHeaders() |
|
| 384 | - { |
|
| 385 | - return $this->_headers; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * setAdditionalParameters |
|
| 390 | - * |
|
| 391 | - * Such as "[email protected] |
|
| 392 | - * |
|
| 393 | - * @param string $additionalParameters The addition mail parameter. |
|
| 394 | - * |
|
| 395 | - * @return self |
|
| 396 | - */ |
|
| 397 | - public function setParameters($additionalParameters) |
|
| 398 | - { |
|
| 399 | - $this->_params = (string) $additionalParameters; |
|
| 400 | - return $this; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * getAdditionalParameters |
|
| 405 | - * |
|
| 406 | - * @return string |
|
| 407 | - */ |
|
| 408 | - public function getParameters() |
|
| 409 | - { |
|
| 410 | - return $this->_params; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * setWrap |
|
| 415 | - * |
|
| 416 | - * @param int $wrap The number of characters at which the message will wrap. |
|
| 417 | - * |
|
| 418 | - * @return self |
|
| 419 | - */ |
|
| 420 | - public function setWrap($wrap = 78) |
|
| 421 | - { |
|
| 422 | - $wrap = (int) $wrap; |
|
| 423 | - if ($wrap < 1) { |
|
| 424 | - $wrap = 78; |
|
| 425 | - } |
|
| 426 | - $this->_wrap = $wrap; |
|
| 427 | - return $this; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * getWrap |
|
| 432 | - * |
|
| 433 | - * @return int |
|
| 434 | - */ |
|
| 435 | - public function getWrap() |
|
| 436 | - { |
|
| 437 | - return $this->_wrap; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * hasAttachments |
|
| 442 | - * |
|
| 443 | - * Checks if the email has any registered attachments. |
|
| 444 | - * |
|
| 445 | - * @return bool |
|
| 446 | - */ |
|
| 447 | - public function hasAttachments() |
|
| 448 | - { |
|
| 449 | - return !empty($this->_attachments); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * assembleAttachment |
|
| 454 | - * |
|
| 455 | - * @return string |
|
| 456 | - */ |
|
| 457 | - public function assembleAttachmentHeaders() |
|
| 458 | - { |
|
| 459 | - $head = array(); |
|
| 460 | - $head[] = "MIME-Version: 1.0"; |
|
| 461 | - $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\""; |
|
| 462 | - |
|
| 463 | - return join(PHP_EOL, $head); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * assembleAttachmentBody |
|
| 468 | - * |
|
| 469 | - * @return string |
|
| 470 | - */ |
|
| 471 | - public function assembleAttachmentBody() |
|
| 472 | - { |
|
| 473 | - $body = array(); |
|
| 474 | - $body[] = "This is a multi-part message in MIME format."; |
|
| 475 | - $body[] = "--{$this->_uid}"; |
|
| 476 | - $body[] = "Content-Type: text/html; charset=\"utf-8\""; |
|
| 477 | - $body[] = "Content-Transfer-Encoding: quoted-printable"; |
|
| 478 | - $body[] = ""; |
|
| 479 | - $body[] = quoted_printable_encode($this->_message); |
|
| 480 | - $body[] = ""; |
|
| 481 | - $body[] = "--{$this->_uid}"; |
|
| 482 | - |
|
| 483 | - foreach ($this->_attachments as $attachment) { |
|
| 484 | - $body[] = $this->getAttachmentMimeTemplate($attachment); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return implode(PHP_EOL, $body) . '--'; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * getAttachmentMimeTemplate |
|
| 492 | - * |
|
| 493 | - * @param array $attachment An array containing 'file' and 'data' keys. |
|
| 494 | - * |
|
| 495 | - * @return string |
|
| 496 | - */ |
|
| 497 | - public function getAttachmentMimeTemplate($attachment) |
|
| 498 | - { |
|
| 499 | - $file = $attachment['file']; |
|
| 500 | - $data = $attachment['data']; |
|
| 501 | - |
|
| 502 | - $head = array(); |
|
| 503 | - $head[] = "Content-Type: application/octet-stream; name=\"{$file}\""; |
|
| 504 | - $head[] = "Content-Transfer-Encoding: base64"; |
|
| 505 | - $head[] = "Content-Disposition: attachment; filename=\"{$file}\""; |
|
| 506 | - $head[] = ""; |
|
| 507 | - $head[] = $data; |
|
| 508 | - $head[] = ""; |
|
| 509 | - $head[] = "--{$this->_uid}"; |
|
| 510 | - |
|
| 511 | - return implode(PHP_EOL, $head); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * send the email |
|
| 516 | - * |
|
| 517 | - * @return boolean |
|
| 518 | - */ |
|
| 519 | - public function send() |
|
| 520 | - { |
|
| 521 | - $to = $this->getToForSend(); |
|
| 522 | - $headers = $this->getHeadersForSend(); |
|
| 523 | - |
|
| 524 | - if (empty($to)) { |
|
| 525 | - show_error('Unable to send, no To address has been set.'); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - if ($this->hasAttachments()) { |
|
| 529 | - $message = $this->assembleAttachmentBody(); |
|
| 530 | - $headers .= PHP_EOL . $this->assembleAttachmentHeaders(); |
|
| 531 | - } else { |
|
| 532 | - $message = $this->getWrapMessage(); |
|
| 533 | - } |
|
| 534 | - $this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message); |
|
| 535 | - return mail($to, $this->_subject, $message, $headers, $this->_params); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * debug |
|
| 540 | - * |
|
| 541 | - * @return string |
|
| 542 | - */ |
|
| 543 | - public function debug() |
|
| 544 | - { |
|
| 545 | - return '<pre>' . print_r($this, true) . '</pre>'; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * magic __toString function |
|
| 550 | - * |
|
| 551 | - * @return string |
|
| 552 | - */ |
|
| 553 | - public function __toString() |
|
| 554 | - { |
|
| 555 | - return print_r($this, true); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * formatHeader |
|
| 560 | - * |
|
| 561 | - * Formats a display address for emails according to RFC2822 e.g. |
|
| 562 | - * Name <[email protected]> |
|
| 563 | - * |
|
| 564 | - * @param string $email The email address. |
|
| 565 | - * @param string $name The display name. |
|
| 566 | - * |
|
| 567 | - * @return string |
|
| 568 | - */ |
|
| 569 | - public function formatHeader($email, $name = null) |
|
| 570 | - { |
|
| 571 | - $email = $this->filterEmail((string) $email); |
|
| 572 | - if (empty($name)) { |
|
| 573 | - return $email; |
|
| 574 | - } |
|
| 575 | - $name = $this->encodeUtf8($this->filterName((string) $name)); |
|
| 576 | - return sprintf('"%s" <%s>', $name, $email); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * encodeUtf8 |
|
| 581 | - * |
|
| 582 | - * @param string $value The value to encode. |
|
| 583 | - * |
|
| 584 | - * @return string |
|
| 585 | - */ |
|
| 586 | - public function encodeUtf8($value) |
|
| 587 | - { |
|
| 588 | - $value = trim($value); |
|
| 589 | - if (preg_match('/(\s)/', $value)) { |
|
| 590 | - return $this->encodeUtf8Words($value); |
|
| 591 | - } |
|
| 592 | - return $this->encodeUtf8Word($value); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * encodeUtf8Word |
|
| 597 | - * |
|
| 598 | - * @param string $value The word to encode. |
|
| 599 | - * |
|
| 600 | - * @return string |
|
| 601 | - */ |
|
| 602 | - public function encodeUtf8Word($value) |
|
| 603 | - { |
|
| 604 | - return sprintf('=?UTF-8?B?%s?=', base64_encode($value)); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * encodeUtf8Words |
|
| 609 | - * |
|
| 610 | - * @param string $value The words to encode. |
|
| 611 | - * |
|
| 612 | - * @return string |
|
| 613 | - */ |
|
| 614 | - public function encodeUtf8Words($value) |
|
| 615 | - { |
|
| 616 | - $words = explode(' ', $value); |
|
| 617 | - $encoded = array(); |
|
| 618 | - foreach ($words as $word) { |
|
| 619 | - $encoded[] = $this->encodeUtf8Word($word); |
|
| 620 | - } |
|
| 621 | - return join($this->encodeUtf8Word(' '), $encoded); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * filterEmail |
|
| 626 | - * |
|
| 627 | - * Removes any carriage return, line feed, tab, double quote, comma |
|
| 628 | - * and angle bracket characters before sanitizing the email address. |
|
| 629 | - * |
|
| 630 | - * @param string $email The email to filter. |
|
| 631 | - * |
|
| 632 | - * @return string |
|
| 633 | - */ |
|
| 634 | - public function filterEmail($email) |
|
| 635 | - { |
|
| 636 | - $rule = array( |
|
| 637 | - "\r" => '', |
|
| 638 | - "\n" => '', |
|
| 639 | - "\t" => '', |
|
| 640 | - '"' => '', |
|
| 641 | - ',' => '', |
|
| 642 | - '<' => '', |
|
| 643 | - '>' => '' |
|
| 644 | - ); |
|
| 645 | - $email = strtr($email, $rule); |
|
| 646 | - $email = filter_var($email, FILTER_SANITIZE_EMAIL); |
|
| 647 | - return $email; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * filterName |
|
| 652 | - * |
|
| 653 | - * Removes any carriage return, line feed or tab characters. Replaces |
|
| 654 | - * double quotes with single quotes and angle brackets with square |
|
| 655 | - * brackets, before sanitizing the string and stripping out html tags. |
|
| 656 | - * |
|
| 657 | - * @param string $name The name to filter. |
|
| 658 | - * |
|
| 659 | - * @return string |
|
| 660 | - */ |
|
| 661 | - public function filterName($name) |
|
| 662 | - { |
|
| 663 | - $rule = array( |
|
| 664 | - "\r" => '', |
|
| 665 | - "\n" => '', |
|
| 666 | - "\t" => '', |
|
| 667 | - '"' => "'", |
|
| 668 | - '<' => '[', |
|
| 669 | - '>' => ']', |
|
| 670 | - ); |
|
| 671 | - $filtered = filter_var( |
|
| 672 | - $name, |
|
| 673 | - FILTER_SANITIZE_STRING, |
|
| 674 | - FILTER_FLAG_NO_ENCODE_QUOTES |
|
| 675 | - ); |
|
| 676 | - return trim(strtr($filtered, $rule)); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * filterOther |
|
| 681 | - * |
|
| 682 | - * Removes ASCII control characters including any carriage return, line |
|
| 683 | - * feed or tab characters. |
|
| 684 | - * |
|
| 685 | - * @param string $data The data to filter. |
|
| 686 | - * |
|
| 687 | - * @return string |
|
| 688 | - */ |
|
| 689 | - public function filterOther($data) |
|
| 690 | - { |
|
| 691 | - return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * getHeadersForSend |
|
| 696 | - * |
|
| 697 | - * @return string |
|
| 698 | - */ |
|
| 699 | - public function getHeadersForSend() |
|
| 700 | - { |
|
| 701 | - if (empty($this->_headers)) { |
|
| 702 | - return ''; |
|
| 703 | - } |
|
| 704 | - return join(PHP_EOL, $this->_headers); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * getToForSend |
|
| 709 | - * |
|
| 710 | - * @return string |
|
| 711 | - */ |
|
| 712 | - public function getToForSend() |
|
| 713 | - { |
|
| 714 | - if (empty($this->_to)) { |
|
| 715 | - return ''; |
|
| 716 | - } |
|
| 717 | - return join(', ', $this->_to); |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - /** |
|
| 721 | - * getUniqueId |
|
| 722 | - * |
|
| 723 | - * @return string |
|
| 724 | - */ |
|
| 725 | - public function getUniqueId() |
|
| 726 | - { |
|
| 727 | - return md5(uniqid(time())); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * getWrapMessage |
|
| 732 | - * |
|
| 733 | - * @return string |
|
| 734 | - */ |
|
| 735 | - public function getWrapMessage() |
|
| 736 | - { |
|
| 737 | - return wordwrap($this->_message, $this->_wrap); |
|
| 738 | - } |
|
| 739 | - } |
|
| 142 | + /** |
|
| 143 | + * Set destination using array |
|
| 144 | + * @params array $emails the list of recipient. This is an associative array name => email |
|
| 145 | + * @example array('John Doe' => '[email protected]') |
|
| 146 | + * @return Object the current instance |
|
| 147 | + */ |
|
| 148 | + public function setTos(array $emails) |
|
| 149 | + { |
|
| 150 | + foreach ($emails as $name => $email) { |
|
| 151 | + if(is_numeric($name)){ |
|
| 152 | + $this->setTo($email); |
|
| 153 | + } |
|
| 154 | + else{ |
|
| 155 | + $this->setTo($email, $name); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + return $this; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * getTo |
|
| 164 | + * |
|
| 165 | + * Return an array of formatted To addresses. |
|
| 166 | + * |
|
| 167 | + * @return array |
|
| 168 | + */ |
|
| 169 | + public function getTo() |
|
| 170 | + { |
|
| 171 | + return $this->_to; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * setCc |
|
| 177 | + * |
|
| 178 | + * @param array $pairs An array of name => email pairs. |
|
| 179 | + * |
|
| 180 | + * @return self |
|
| 181 | + */ |
|
| 182 | + public function setCc(array $pairs) |
|
| 183 | + { |
|
| 184 | + return $this->addMailHeaders('Cc', $pairs); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * setBcc |
|
| 189 | + * |
|
| 190 | + * @param array $pairs An array of name => email pairs. |
|
| 191 | + * |
|
| 192 | + * @return self |
|
| 193 | + */ |
|
| 194 | + public function setBcc(array $pairs) |
|
| 195 | + { |
|
| 196 | + return $this->addMailHeaders('Bcc', $pairs); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * setReplyTo |
|
| 201 | + * |
|
| 202 | + * @param string $email |
|
| 203 | + * @param string $name |
|
| 204 | + * |
|
| 205 | + * @return self |
|
| 206 | + */ |
|
| 207 | + public function setReplyTo($email, $name = null) |
|
| 208 | + { |
|
| 209 | + return $this->addMailHeader('Reply-To', $email, $name); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * setHtml |
|
| 214 | + * |
|
| 215 | + * @return self |
|
| 216 | + */ |
|
| 217 | + public function setHtml() |
|
| 218 | + { |
|
| 219 | + $this->addGenericHeader( |
|
| 220 | + 'Content-Type', 'text/html; charset="utf-8"' |
|
| 221 | + ); |
|
| 222 | + return $this; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * setSubject |
|
| 227 | + * |
|
| 228 | + * @param string $subject The email subject |
|
| 229 | + * |
|
| 230 | + * @return self |
|
| 231 | + */ |
|
| 232 | + public function setSubject($subject) |
|
| 233 | + { |
|
| 234 | + $this->_subject = $this->encodeUtf8( |
|
| 235 | + $this->filterOther((string) $subject) |
|
| 236 | + ); |
|
| 237 | + return $this; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * getSubject function. |
|
| 242 | + * |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + public function getSubject() |
|
| 246 | + { |
|
| 247 | + return $this->_subject; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * setMessage |
|
| 252 | + * |
|
| 253 | + * @param string $message The message to send. |
|
| 254 | + * |
|
| 255 | + * @return self |
|
| 256 | + */ |
|
| 257 | + public function setMessage($message) |
|
| 258 | + { |
|
| 259 | + $this->_message = str_replace("\n.", "\n..", (string) $message); |
|
| 260 | + return $this; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * getMessage |
|
| 265 | + * |
|
| 266 | + * @return string |
|
| 267 | + */ |
|
| 268 | + public function getMessage() |
|
| 269 | + { |
|
| 270 | + return $this->_message; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * addAttachment |
|
| 275 | + * |
|
| 276 | + * @param string $path The file path to the attachment. |
|
| 277 | + * @param string $filename The filename of the attachment when emailed. |
|
| 278 | + * @param string $data |
|
| 279 | + * |
|
| 280 | + * @return self |
|
| 281 | + */ |
|
| 282 | + public function addAttachment($path, $filename = null, $data = null) |
|
| 283 | + { |
|
| 284 | + if(! file_exists($path)){ |
|
| 285 | + show_error('The file [' .$path. '] does not exists.'); |
|
| 286 | + } |
|
| 287 | + $filename = empty($filename) ? basename($path) : $filename; |
|
| 288 | + $filename = $this->encodeUtf8($this->filterOther((string) $filename)); |
|
| 289 | + $data = empty($data) ? $this->getAttachmentData($path) : $data; |
|
| 290 | + $this->_attachments[] = array( |
|
| 291 | + 'path' => $path, |
|
| 292 | + 'file' => $filename, |
|
| 293 | + 'data' => chunk_split(base64_encode($data)) |
|
| 294 | + ); |
|
| 295 | + return $this; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * getAttachmentData |
|
| 300 | + * |
|
| 301 | + * @param string $path The path to the attachment file. |
|
| 302 | + * |
|
| 303 | + * @return string |
|
| 304 | + */ |
|
| 305 | + public function getAttachmentData($path) |
|
| 306 | + { |
|
| 307 | + if(! file_exists($path)){ |
|
| 308 | + show_error('The file [' .$path. '] does not exists.'); |
|
| 309 | + } |
|
| 310 | + $filesize = filesize($path); |
|
| 311 | + $handle = fopen($path, "r"); |
|
| 312 | + $attachment = null; |
|
| 313 | + if(is_resource($handle)){ |
|
| 314 | + $attachment = fread($handle, $filesize); |
|
| 315 | + fclose($handle); |
|
| 316 | + } |
|
| 317 | + return $attachment; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * addMailHeader |
|
| 322 | + * |
|
| 323 | + * @param string $header The header to add. |
|
| 324 | + * @param string $email The email to add. |
|
| 325 | + * @param string $name The name to add. |
|
| 326 | + * |
|
| 327 | + * @return self |
|
| 328 | + */ |
|
| 329 | + public function addMailHeader($header, $email, $name = null) |
|
| 330 | + { |
|
| 331 | + $address = $this->formatHeader((string) $email, (string) $name); |
|
| 332 | + $this->_headers[] = sprintf('%s: %s', (string) $header, $address); |
|
| 333 | + return $this; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * addMailHeaders |
|
| 338 | + * |
|
| 339 | + * @param string $header The header to add. |
|
| 340 | + * @param array $pairs An array of name => email pairs. |
|
| 341 | + * |
|
| 342 | + * @return self |
|
| 343 | + */ |
|
| 344 | + public function addMailHeaders($header, array $pairs) |
|
| 345 | + { |
|
| 346 | + if (count($pairs) === 0) { |
|
| 347 | + show_error('You must pass at least one name => email pair.'); |
|
| 348 | + } |
|
| 349 | + $addresses = array(); |
|
| 350 | + foreach ($pairs as $name => $email) { |
|
| 351 | + $name = is_numeric($name) ? null : $name; |
|
| 352 | + $addresses[] = $this->formatHeader($email, $name); |
|
| 353 | + } |
|
| 354 | + $this->addGenericHeader($header, implode(',', $addresses)); |
|
| 355 | + return $this; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * addGenericHeader |
|
| 360 | + * |
|
| 361 | + * @param string $name The generic header to add. |
|
| 362 | + * @param mixed $value The value of the header. |
|
| 363 | + * |
|
| 364 | + * @return self |
|
| 365 | + */ |
|
| 366 | + public function addGenericHeader($name, $value) |
|
| 367 | + { |
|
| 368 | + $this->_headers[] = sprintf( |
|
| 369 | + '%s: %s', |
|
| 370 | + (string) $name, |
|
| 371 | + (string) $value |
|
| 372 | + ); |
|
| 373 | + return $this; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * getHeaders |
|
| 378 | + * |
|
| 379 | + * Return the headers registered so far as an array. |
|
| 380 | + * |
|
| 381 | + * @return array |
|
| 382 | + */ |
|
| 383 | + public function getHeaders() |
|
| 384 | + { |
|
| 385 | + return $this->_headers; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * setAdditionalParameters |
|
| 390 | + * |
|
| 391 | + * Such as "[email protected] |
|
| 392 | + * |
|
| 393 | + * @param string $additionalParameters The addition mail parameter. |
|
| 394 | + * |
|
| 395 | + * @return self |
|
| 396 | + */ |
|
| 397 | + public function setParameters($additionalParameters) |
|
| 398 | + { |
|
| 399 | + $this->_params = (string) $additionalParameters; |
|
| 400 | + return $this; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * getAdditionalParameters |
|
| 405 | + * |
|
| 406 | + * @return string |
|
| 407 | + */ |
|
| 408 | + public function getParameters() |
|
| 409 | + { |
|
| 410 | + return $this->_params; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * setWrap |
|
| 415 | + * |
|
| 416 | + * @param int $wrap The number of characters at which the message will wrap. |
|
| 417 | + * |
|
| 418 | + * @return self |
|
| 419 | + */ |
|
| 420 | + public function setWrap($wrap = 78) |
|
| 421 | + { |
|
| 422 | + $wrap = (int) $wrap; |
|
| 423 | + if ($wrap < 1) { |
|
| 424 | + $wrap = 78; |
|
| 425 | + } |
|
| 426 | + $this->_wrap = $wrap; |
|
| 427 | + return $this; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * getWrap |
|
| 432 | + * |
|
| 433 | + * @return int |
|
| 434 | + */ |
|
| 435 | + public function getWrap() |
|
| 436 | + { |
|
| 437 | + return $this->_wrap; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * hasAttachments |
|
| 442 | + * |
|
| 443 | + * Checks if the email has any registered attachments. |
|
| 444 | + * |
|
| 445 | + * @return bool |
|
| 446 | + */ |
|
| 447 | + public function hasAttachments() |
|
| 448 | + { |
|
| 449 | + return !empty($this->_attachments); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * assembleAttachment |
|
| 454 | + * |
|
| 455 | + * @return string |
|
| 456 | + */ |
|
| 457 | + public function assembleAttachmentHeaders() |
|
| 458 | + { |
|
| 459 | + $head = array(); |
|
| 460 | + $head[] = "MIME-Version: 1.0"; |
|
| 461 | + $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\""; |
|
| 462 | + |
|
| 463 | + return join(PHP_EOL, $head); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * assembleAttachmentBody |
|
| 468 | + * |
|
| 469 | + * @return string |
|
| 470 | + */ |
|
| 471 | + public function assembleAttachmentBody() |
|
| 472 | + { |
|
| 473 | + $body = array(); |
|
| 474 | + $body[] = "This is a multi-part message in MIME format."; |
|
| 475 | + $body[] = "--{$this->_uid}"; |
|
| 476 | + $body[] = "Content-Type: text/html; charset=\"utf-8\""; |
|
| 477 | + $body[] = "Content-Transfer-Encoding: quoted-printable"; |
|
| 478 | + $body[] = ""; |
|
| 479 | + $body[] = quoted_printable_encode($this->_message); |
|
| 480 | + $body[] = ""; |
|
| 481 | + $body[] = "--{$this->_uid}"; |
|
| 482 | + |
|
| 483 | + foreach ($this->_attachments as $attachment) { |
|
| 484 | + $body[] = $this->getAttachmentMimeTemplate($attachment); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return implode(PHP_EOL, $body) . '--'; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * getAttachmentMimeTemplate |
|
| 492 | + * |
|
| 493 | + * @param array $attachment An array containing 'file' and 'data' keys. |
|
| 494 | + * |
|
| 495 | + * @return string |
|
| 496 | + */ |
|
| 497 | + public function getAttachmentMimeTemplate($attachment) |
|
| 498 | + { |
|
| 499 | + $file = $attachment['file']; |
|
| 500 | + $data = $attachment['data']; |
|
| 501 | + |
|
| 502 | + $head = array(); |
|
| 503 | + $head[] = "Content-Type: application/octet-stream; name=\"{$file}\""; |
|
| 504 | + $head[] = "Content-Transfer-Encoding: base64"; |
|
| 505 | + $head[] = "Content-Disposition: attachment; filename=\"{$file}\""; |
|
| 506 | + $head[] = ""; |
|
| 507 | + $head[] = $data; |
|
| 508 | + $head[] = ""; |
|
| 509 | + $head[] = "--{$this->_uid}"; |
|
| 510 | + |
|
| 511 | + return implode(PHP_EOL, $head); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * send the email |
|
| 516 | + * |
|
| 517 | + * @return boolean |
|
| 518 | + */ |
|
| 519 | + public function send() |
|
| 520 | + { |
|
| 521 | + $to = $this->getToForSend(); |
|
| 522 | + $headers = $this->getHeadersForSend(); |
|
| 523 | + |
|
| 524 | + if (empty($to)) { |
|
| 525 | + show_error('Unable to send, no To address has been set.'); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + if ($this->hasAttachments()) { |
|
| 529 | + $message = $this->assembleAttachmentBody(); |
|
| 530 | + $headers .= PHP_EOL . $this->assembleAttachmentHeaders(); |
|
| 531 | + } else { |
|
| 532 | + $message = $this->getWrapMessage(); |
|
| 533 | + } |
|
| 534 | + $this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message); |
|
| 535 | + return mail($to, $this->_subject, $message, $headers, $this->_params); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * debug |
|
| 540 | + * |
|
| 541 | + * @return string |
|
| 542 | + */ |
|
| 543 | + public function debug() |
|
| 544 | + { |
|
| 545 | + return '<pre>' . print_r($this, true) . '</pre>'; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * magic __toString function |
|
| 550 | + * |
|
| 551 | + * @return string |
|
| 552 | + */ |
|
| 553 | + public function __toString() |
|
| 554 | + { |
|
| 555 | + return print_r($this, true); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * formatHeader |
|
| 560 | + * |
|
| 561 | + * Formats a display address for emails according to RFC2822 e.g. |
|
| 562 | + * Name <[email protected]> |
|
| 563 | + * |
|
| 564 | + * @param string $email The email address. |
|
| 565 | + * @param string $name The display name. |
|
| 566 | + * |
|
| 567 | + * @return string |
|
| 568 | + */ |
|
| 569 | + public function formatHeader($email, $name = null) |
|
| 570 | + { |
|
| 571 | + $email = $this->filterEmail((string) $email); |
|
| 572 | + if (empty($name)) { |
|
| 573 | + return $email; |
|
| 574 | + } |
|
| 575 | + $name = $this->encodeUtf8($this->filterName((string) $name)); |
|
| 576 | + return sprintf('"%s" <%s>', $name, $email); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * encodeUtf8 |
|
| 581 | + * |
|
| 582 | + * @param string $value The value to encode. |
|
| 583 | + * |
|
| 584 | + * @return string |
|
| 585 | + */ |
|
| 586 | + public function encodeUtf8($value) |
|
| 587 | + { |
|
| 588 | + $value = trim($value); |
|
| 589 | + if (preg_match('/(\s)/', $value)) { |
|
| 590 | + return $this->encodeUtf8Words($value); |
|
| 591 | + } |
|
| 592 | + return $this->encodeUtf8Word($value); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * encodeUtf8Word |
|
| 597 | + * |
|
| 598 | + * @param string $value The word to encode. |
|
| 599 | + * |
|
| 600 | + * @return string |
|
| 601 | + */ |
|
| 602 | + public function encodeUtf8Word($value) |
|
| 603 | + { |
|
| 604 | + return sprintf('=?UTF-8?B?%s?=', base64_encode($value)); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * encodeUtf8Words |
|
| 609 | + * |
|
| 610 | + * @param string $value The words to encode. |
|
| 611 | + * |
|
| 612 | + * @return string |
|
| 613 | + */ |
|
| 614 | + public function encodeUtf8Words($value) |
|
| 615 | + { |
|
| 616 | + $words = explode(' ', $value); |
|
| 617 | + $encoded = array(); |
|
| 618 | + foreach ($words as $word) { |
|
| 619 | + $encoded[] = $this->encodeUtf8Word($word); |
|
| 620 | + } |
|
| 621 | + return join($this->encodeUtf8Word(' '), $encoded); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * filterEmail |
|
| 626 | + * |
|
| 627 | + * Removes any carriage return, line feed, tab, double quote, comma |
|
| 628 | + * and angle bracket characters before sanitizing the email address. |
|
| 629 | + * |
|
| 630 | + * @param string $email The email to filter. |
|
| 631 | + * |
|
| 632 | + * @return string |
|
| 633 | + */ |
|
| 634 | + public function filterEmail($email) |
|
| 635 | + { |
|
| 636 | + $rule = array( |
|
| 637 | + "\r" => '', |
|
| 638 | + "\n" => '', |
|
| 639 | + "\t" => '', |
|
| 640 | + '"' => '', |
|
| 641 | + ',' => '', |
|
| 642 | + '<' => '', |
|
| 643 | + '>' => '' |
|
| 644 | + ); |
|
| 645 | + $email = strtr($email, $rule); |
|
| 646 | + $email = filter_var($email, FILTER_SANITIZE_EMAIL); |
|
| 647 | + return $email; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * filterName |
|
| 652 | + * |
|
| 653 | + * Removes any carriage return, line feed or tab characters. Replaces |
|
| 654 | + * double quotes with single quotes and angle brackets with square |
|
| 655 | + * brackets, before sanitizing the string and stripping out html tags. |
|
| 656 | + * |
|
| 657 | + * @param string $name The name to filter. |
|
| 658 | + * |
|
| 659 | + * @return string |
|
| 660 | + */ |
|
| 661 | + public function filterName($name) |
|
| 662 | + { |
|
| 663 | + $rule = array( |
|
| 664 | + "\r" => '', |
|
| 665 | + "\n" => '', |
|
| 666 | + "\t" => '', |
|
| 667 | + '"' => "'", |
|
| 668 | + '<' => '[', |
|
| 669 | + '>' => ']', |
|
| 670 | + ); |
|
| 671 | + $filtered = filter_var( |
|
| 672 | + $name, |
|
| 673 | + FILTER_SANITIZE_STRING, |
|
| 674 | + FILTER_FLAG_NO_ENCODE_QUOTES |
|
| 675 | + ); |
|
| 676 | + return trim(strtr($filtered, $rule)); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * filterOther |
|
| 681 | + * |
|
| 682 | + * Removes ASCII control characters including any carriage return, line |
|
| 683 | + * feed or tab characters. |
|
| 684 | + * |
|
| 685 | + * @param string $data The data to filter. |
|
| 686 | + * |
|
| 687 | + * @return string |
|
| 688 | + */ |
|
| 689 | + public function filterOther($data) |
|
| 690 | + { |
|
| 691 | + return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * getHeadersForSend |
|
| 696 | + * |
|
| 697 | + * @return string |
|
| 698 | + */ |
|
| 699 | + public function getHeadersForSend() |
|
| 700 | + { |
|
| 701 | + if (empty($this->_headers)) { |
|
| 702 | + return ''; |
|
| 703 | + } |
|
| 704 | + return join(PHP_EOL, $this->_headers); |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * getToForSend |
|
| 709 | + * |
|
| 710 | + * @return string |
|
| 711 | + */ |
|
| 712 | + public function getToForSend() |
|
| 713 | + { |
|
| 714 | + if (empty($this->_to)) { |
|
| 715 | + return ''; |
|
| 716 | + } |
|
| 717 | + return join(', ', $this->_to); |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + /** |
|
| 721 | + * getUniqueId |
|
| 722 | + * |
|
| 723 | + * @return string |
|
| 724 | + */ |
|
| 725 | + public function getUniqueId() |
|
| 726 | + { |
|
| 727 | + return md5(uniqid(time())); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * getWrapMessage |
|
| 732 | + * |
|
| 733 | + * @return string |
|
| 734 | + */ |
|
| 735 | + public function getWrapMessage() |
|
| 736 | + { |
|
| 737 | + return wordwrap($this->_message, $this->_wrap); |
|
| 738 | + } |
|
| 739 | + } |
|
@@ -1,112 +1,112 @@ |
||
| 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 | - class Cookie{ |
|
| 27 | + class Cookie{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The logger instance |
|
| 31 | - * @var Log |
|
| 32 | - */ |
|
| 33 | - private static $logger; |
|
| 29 | + /** |
|
| 30 | + * The logger instance |
|
| 31 | + * @var Log |
|
| 32 | + */ |
|
| 33 | + private static $logger; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * The signleton of the logger |
|
| 37 | - * @return Object the Log instance |
|
| 38 | - */ |
|
| 39 | - private static function getLogger(){ |
|
| 40 | - if(self::$logger == null){ |
|
| 41 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 42 | - self::$logger[0]->setLogger('Library::Cookie'); |
|
| 43 | - } |
|
| 44 | - return self::$logger[0]; |
|
| 45 | - } |
|
| 35 | + /** |
|
| 36 | + * The signleton of the logger |
|
| 37 | + * @return Object the Log instance |
|
| 38 | + */ |
|
| 39 | + private static function getLogger(){ |
|
| 40 | + if(self::$logger == null){ |
|
| 41 | + self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 42 | + self::$logger[0]->setLogger('Library::Cookie'); |
|
| 43 | + } |
|
| 44 | + return self::$logger[0]; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Get the cookie item value |
|
| 49 | - * @param string $item the cookie item name to get |
|
| 50 | - * @param mixed $default the default value to use if can not find the cokkie item in the list |
|
| 51 | - * @return mixed the cookie value if exist or the default value |
|
| 52 | - */ |
|
| 53 | - public static function get($item, $default = null){ |
|
| 54 | - $logger = self::getLogger(); |
|
| 55 | - if(array_key_exists($item, $_COOKIE)){ |
|
| 56 | - return $_COOKIE[$item]; |
|
| 57 | - } |
|
| 58 | - $logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']'); |
|
| 59 | - return $default; |
|
| 60 | - } |
|
| 47 | + /** |
|
| 48 | + * Get the cookie item value |
|
| 49 | + * @param string $item the cookie item name to get |
|
| 50 | + * @param mixed $default the default value to use if can not find the cokkie item in the list |
|
| 51 | + * @return mixed the cookie value if exist or the default value |
|
| 52 | + */ |
|
| 53 | + public static function get($item, $default = null){ |
|
| 54 | + $logger = self::getLogger(); |
|
| 55 | + if(array_key_exists($item, $_COOKIE)){ |
|
| 56 | + return $_COOKIE[$item]; |
|
| 57 | + } |
|
| 58 | + $logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']'); |
|
| 59 | + return $default; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Set the cookie item value |
|
| 64 | - * @param string $name the cookie item name |
|
| 65 | - * @param string $value the cookie value to set |
|
| 66 | - * @param integer $expire the time to live for this cookie |
|
| 67 | - * @param string $path the path that the cookie will be available |
|
| 68 | - * @param string $domain the domain that the cookie will be available |
|
| 69 | - * @param boolean $secure if this cookie will be available on secure connection or not |
|
| 70 | - * @param boolean $httponly if this cookie will be available under HTTP protocol. |
|
| 71 | - */ |
|
| 72 | - public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){ |
|
| 73 | - if(headers_sent()){ |
|
| 74 | - show_error('There exists a cookie that we wanted to create that we couldn\'t |
|
| 62 | + /** |
|
| 63 | + * Set the cookie item value |
|
| 64 | + * @param string $name the cookie item name |
|
| 65 | + * @param string $value the cookie value to set |
|
| 66 | + * @param integer $expire the time to live for this cookie |
|
| 67 | + * @param string $path the path that the cookie will be available |
|
| 68 | + * @param string $domain the domain that the cookie will be available |
|
| 69 | + * @param boolean $secure if this cookie will be available on secure connection or not |
|
| 70 | + * @param boolean $httponly if this cookie will be available under HTTP protocol. |
|
| 71 | + */ |
|
| 72 | + public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){ |
|
| 73 | + if(headers_sent()){ |
|
| 74 | + show_error('There exists a cookie that we wanted to create that we couldn\'t |
|
| 75 | 75 | because headers was already sent. Make sure to do this first |
| 76 | 76 | before outputing anything.'); |
| 77 | - } |
|
| 78 | - $timestamp = $expire; |
|
| 79 | - if($expire){ |
|
| 80 | - $timestamp = time() + $expire; |
|
| 81 | - } |
|
| 82 | - setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly); |
|
| 83 | - } |
|
| 77 | + } |
|
| 78 | + $timestamp = $expire; |
|
| 79 | + if($expire){ |
|
| 80 | + $timestamp = time() + $expire; |
|
| 81 | + } |
|
| 82 | + setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Delete the cookie item in the list |
|
| 87 | - * @param string $item the cookie item name to be cleared |
|
| 88 | - * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
|
| 89 | - */ |
|
| 90 | - public static function delete($item){ |
|
| 91 | - $logger = self::getLogger(); |
|
| 92 | - if(array_key_exists($item, $_COOKIE)){ |
|
| 93 | - $logger->info('Delete cookie item ['.$item.']'); |
|
| 94 | - unset($_COOKIE[$item]); |
|
| 95 | - return true; |
|
| 96 | - } |
|
| 97 | - else{ |
|
| 98 | - $logger->warning('Cookie item ['.$item.'] to be deleted does not exists'); |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - } |
|
| 85 | + /** |
|
| 86 | + * Delete the cookie item in the list |
|
| 87 | + * @param string $item the cookie item name to be cleared |
|
| 88 | + * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
|
| 89 | + */ |
|
| 90 | + public static function delete($item){ |
|
| 91 | + $logger = self::getLogger(); |
|
| 92 | + if(array_key_exists($item, $_COOKIE)){ |
|
| 93 | + $logger->info('Delete cookie item ['.$item.']'); |
|
| 94 | + unset($_COOKIE[$item]); |
|
| 95 | + return true; |
|
| 96 | + } |
|
| 97 | + else{ |
|
| 98 | + $logger->warning('Cookie item ['.$item.'] to be deleted does not exists'); |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Check if the given cookie item exists |
|
| 105 | - * @param string $item the cookie item name |
|
| 106 | - * @return boolean true if the cookie item is set, false or not |
|
| 107 | - */ |
|
| 108 | - public static function exists($item){ |
|
| 109 | - return array_key_exists($item, $_COOKIE); |
|
| 110 | - } |
|
| 103 | + /** |
|
| 104 | + * Check if the given cookie item exists |
|
| 105 | + * @param string $item the cookie item name |
|
| 106 | + * @return boolean true if the cookie item is set, false or not |
|
| 107 | + */ |
|
| 108 | + public static function exists($item){ |
|
| 109 | + return array_key_exists($item, $_COOKIE); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - } |
|
| 112 | + } |
|
@@ -1,65 +1,65 @@ |
||
| 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 | - class StringHash{ |
|
| 27 | + class StringHash{ |
|
| 28 | 28 | |
| 29 | - //blowfish |
|
| 30 | - private static $algo = '$2a'; |
|
| 29 | + //blowfish |
|
| 30 | + private static $algo = '$2a'; |
|
| 31 | 31 | |
| 32 | - //cost parameter |
|
| 33 | - private static $cost = '$10'; |
|
| 32 | + //cost parameter |
|
| 33 | + private static $cost = '$10'; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Get the unique salt for the string hash |
|
| 37 | - * @return string the unique generated salt |
|
| 38 | - */ |
|
| 39 | - private static function uniqueSalt() { |
|
| 40 | - return substr(sha1(mt_rand()), 0, 22); |
|
| 41 | - } |
|
| 35 | + /** |
|
| 36 | + * Get the unique salt for the string hash |
|
| 37 | + * @return string the unique generated salt |
|
| 38 | + */ |
|
| 39 | + private static function uniqueSalt() { |
|
| 40 | + return substr(sha1(mt_rand()), 0, 22); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Hash the given string |
|
| 45 | - * @param string $value the plain string text to be hashed |
|
| 46 | - * @return string the hashed string |
|
| 47 | - */ |
|
| 48 | - public static function hash($value) { |
|
| 49 | - return crypt($value, self::$algo . |
|
| 50 | - self::$cost . |
|
| 51 | - '$' . self::uniqueSalt()); |
|
| 52 | - } |
|
| 43 | + /** |
|
| 44 | + * Hash the given string |
|
| 45 | + * @param string $value the plain string text to be hashed |
|
| 46 | + * @return string the hashed string |
|
| 47 | + */ |
|
| 48 | + public static function hash($value) { |
|
| 49 | + return crypt($value, self::$algo . |
|
| 50 | + self::$cost . |
|
| 51 | + '$' . self::uniqueSalt()); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Check if the hash and plain string is valid |
|
| 56 | - * @param string $hash the hashed string |
|
| 57 | - * @param string $plain the plain text |
|
| 58 | - * @return boolean true if is valid or false if not |
|
| 59 | - */ |
|
| 60 | - public static function check($hash, $plain) { |
|
| 61 | - $full_salt = substr($hash, 0, 29); |
|
| 62 | - $new_hash = crypt($plain, $full_salt); |
|
| 63 | - return ($hash === $new_hash); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | 54 | \ No newline at end of file |
| 55 | + /** |
|
| 56 | + * Check if the hash and plain string is valid |
|
| 57 | + * @param string $hash the hashed string |
|
| 58 | + * @param string $plain the plain text |
|
| 59 | + * @return boolean true if is valid or false if not |
|
| 60 | + */ |
|
| 61 | + public static function check($hash, $plain) { |
|
| 62 | + $full_salt = substr($hash, 0, 29); |
|
| 63 | + $new_hash = crypt($plain, $full_salt); |
|
| 64 | + return ($hash === $new_hash); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | \ No newline at end of file |
@@ -1,89 +1,89 @@ |
||
| 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 | - /** |
|
| 28 | - * Class for Benchmark |
|
| 29 | - */ |
|
| 30 | - class Benchmark{ |
|
| 31 | - /** |
|
| 32 | - * The markers for excution time |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 35 | - private $markersTime = array(); |
|
| 27 | + /** |
|
| 28 | + * Class for Benchmark |
|
| 29 | + */ |
|
| 30 | + class Benchmark{ |
|
| 31 | + /** |
|
| 32 | + * The markers for excution time |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | + private $markersTime = array(); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * The markers for memory usage |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - private $markersMemory = array(); |
|
| 37 | + /** |
|
| 38 | + * The markers for memory usage |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + private $markersMemory = array(); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * This method is used to mark one point for benchmark (execution time and memory usage) |
|
| 45 | - * @param string $name the marker name |
|
| 46 | - */ |
|
| 47 | - public function mark($name){ |
|
| 48 | - //Marker for execution time |
|
| 49 | - $this->markersTime[$name] = microtime(true); |
|
| 50 | - //Marker for memory usage |
|
| 51 | - $this->markersMemory[$name] = memory_get_usage(true); |
|
| 52 | - } |
|
| 43 | + /** |
|
| 44 | + * This method is used to mark one point for benchmark (execution time and memory usage) |
|
| 45 | + * @param string $name the marker name |
|
| 46 | + */ |
|
| 47 | + public function mark($name){ |
|
| 48 | + //Marker for execution time |
|
| 49 | + $this->markersTime[$name] = microtime(true); |
|
| 50 | + //Marker for memory usage |
|
| 51 | + $this->markersMemory[$name] = memory_get_usage(true); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * This method is used to get the total excution time in second between two markers |
|
| 56 | - * @param string $startMarkerName the marker for start point |
|
| 57 | - * @param string $endMarkerName the marker for end point |
|
| 58 | - * @param integer $decimalCount the number of decimal |
|
| 59 | - * @return string the total execution time |
|
| 60 | - */ |
|
| 61 | - public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 62 | - if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){ |
|
| 63 | - return 0; |
|
| 64 | - } |
|
| 54 | + /** |
|
| 55 | + * This method is used to get the total excution time in second between two markers |
|
| 56 | + * @param string $startMarkerName the marker for start point |
|
| 57 | + * @param string $endMarkerName the marker for end point |
|
| 58 | + * @param integer $decimalCount the number of decimal |
|
| 59 | + * @return string the total execution time |
|
| 60 | + */ |
|
| 61 | + public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 62 | + if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){ |
|
| 63 | + return 0; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if(! isset($this->markersTime[$endMarkerName])){ |
|
| 67 | - $this->markersTime[$endMarkerName] = microtime(true); |
|
| 68 | - } |
|
| 69 | - return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount); |
|
| 70 | - } |
|
| 66 | + if(! isset($this->markersTime[$endMarkerName])){ |
|
| 67 | + $this->markersTime[$endMarkerName] = microtime(true); |
|
| 68 | + } |
|
| 69 | + return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * This method is used to get the total memory usage in byte between two markers |
|
| 74 | - * @param string $startMarkerName the marker for start point |
|
| 75 | - * @param string $endMarkerName the marker for end point |
|
| 76 | - * @param integer $decimalCount the number of decimal |
|
| 77 | - * @return string the total memory usage |
|
| 78 | - */ |
|
| 79 | - public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 80 | - if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){ |
|
| 81 | - return 0; |
|
| 82 | - } |
|
| 72 | + /** |
|
| 73 | + * This method is used to get the total memory usage in byte between two markers |
|
| 74 | + * @param string $startMarkerName the marker for start point |
|
| 75 | + * @param string $endMarkerName the marker for end point |
|
| 76 | + * @param integer $decimalCount the number of decimal |
|
| 77 | + * @return string the total memory usage |
|
| 78 | + */ |
|
| 79 | + public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 80 | + if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){ |
|
| 81 | + return 0; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if(! isset($this->markersMemory[$endMarkerName])){ |
|
| 85 | - $this->markersMemory[$endMarkerName] = microtime(true); |
|
| 86 | - } |
|
| 87 | - return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount); |
|
| 88 | - } |
|
| 89 | - } |
|
| 84 | + if(! isset($this->markersMemory[$endMarkerName])){ |
|
| 85 | + $this->markersMemory[$endMarkerName] = microtime(true); |
|
| 86 | + } |
|
| 87 | + return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount); |
|
| 88 | + } |
|
| 89 | + } |
|