nash-ye /
ebloodbank
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Abstract entity class file |
||
| 4 | * |
||
| 5 | * @package EBloodBank |
||
| 6 | * @subpackage Models |
||
| 7 | * @since 1.0 |
||
| 8 | */ |
||
| 9 | namespace EBloodBank\Models; |
||
| 10 | |||
| 11 | use EBloodBank as EBB; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Abstract entity class |
||
| 15 | * |
||
| 16 | * @since 1.0 |
||
| 17 | * |
||
| 18 | * @MappedSuperclass |
||
| 19 | */ |
||
| 20 | abstract class Entity |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @return mixed |
||
| 24 | * @since 1.0 |
||
| 25 | */ |
||
| 26 | public function get($key) |
||
| 27 | { |
||
| 28 | if (property_exists($this, $key)) { |
||
| 29 | return $this->$key; |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @return bool |
||
| 35 | * @since 1.0 |
||
| 36 | */ |
||
| 37 | abstract public function isExists(); |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return void |
||
| 41 | * @since 1.0 |
||
| 42 | */ |
||
| 43 | public function display($key, $format = 'html') |
||
| 44 | { |
||
| 45 | switch ($format) { |
||
| 46 | |||
| 47 | case 'attr': |
||
| 48 | echo EBB\escAttr($this->get($key)); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 49 | break; |
||
| 50 | |||
| 51 | case 'html': |
||
| 52 | echo EBB\escHTML($this->get($key)); |
||
| 53 | break; |
||
| 54 | |||
| 55 | default: |
||
| 56 | case 'plain': |
||
| 57 | echo $this->get($key); |
||
| 58 | break; |
||
| 59 | |||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return mixed |
||
| 65 | * @since 1.0 |
||
| 66 | */ |
||
| 67 | public static function sanitize($key, $value) |
||
| 68 | { |
||
| 69 | return $value; |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @return bool |
||
| 74 | * @since 1.0 |
||
| 75 | */ |
||
| 76 | public static function validate($key, $value) |
||
| 77 | { |
||
| 78 | return true; |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return void |
||
| 83 | * @since 1.0 |
||
| 84 | */ |
||
| 85 | public function set($key, $value, $sanitize = false, $validate = true) |
||
| 86 | { |
||
| 87 | if (property_exists($this, $key)) { |
||
| 88 | if ($sanitize) { |
||
| 89 | $value = static::sanitize($key, $value); |
||
| 90 | } |
||
| 91 | if (! $validate || static::validate($key, $value)) { |
||
| 92 | $this->$key = $value; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 |