| @@ 43-72 (lines=30) @@ | ||
| 40 | return sprintf('set%s', ucfirst($attr)); |
|
| 41 | } |
|
| 42 | ||
| 43 | public function get($attr) |
|
| 44 | { |
|
| 45 | $attributes = $this->getAttributes(); |
|
| 46 | ||
| 47 | $getMethod = $this->getMethod($attr); |
|
| 48 | if (method_exists($this, $getMethod)) { |
|
| 49 | return $this->$getMethod(); |
|
| 50 | } |
|
| 51 | ||
| 52 | trigger_error( |
|
| 53 | sprintf( |
|
| 54 | 'The class "%s" don\'t have a method "%s"', |
|
| 55 | get_class($this), |
|
| 56 | $getMethod |
|
| 57 | ), |
|
| 58 | E_USER_WARNING |
|
| 59 | ); |
|
| 60 | ||
| 61 | if (array_key_exists($attr, $attributes)) { |
|
| 62 | return $attributes[$attr]; |
|
| 63 | } |
|
| 64 | ||
| 65 | throw new InvalidArgumentException( |
|
| 66 | sprintf( |
|
| 67 | 'The class "%s" don\'t have an attribute "%s"', |
|
| 68 | get_class($this), |
|
| 69 | $attr |
|
| 70 | ) |
|
| 71 | ); |
|
| 72 | } |
|
| 73 | ||
| 74 | public function set($attr, $value) |
|
| 75 | { |
|
| @@ 74-104 (lines=31) @@ | ||
| 71 | ); |
|
| 72 | } |
|
| 73 | ||
| 74 | public function set($attr, $value) |
|
| 75 | { |
|
| 76 | $setMethod = $this->setMethod($attr); |
|
| 77 | ||
| 78 | if (method_exists($this, $setMethod)) { |
|
| 79 | return $this->$setMethod($value); |
|
| 80 | } |
|
| 81 | ||
| 82 | trigger_error( |
|
| 83 | sprintf( |
|
| 84 | 'The class "%s" don\'t have a method "%s"', |
|
| 85 | get_class($this), |
|
| 86 | $setMethod |
|
| 87 | ), |
|
| 88 | E_USER_WARNING |
|
| 89 | ); |
|
| 90 | ||
| 91 | $attributes = $this->getAttributes(); |
|
| 92 | ||
| 93 | if (in_array($attr, $attributes)) { |
|
| 94 | $this->$attr = $value; |
|
| 95 | } |
|
| 96 | ||
| 97 | throw new InvalidArgumentException( |
|
| 98 | sprintf( |
|
| 99 | 'The class "%s" don\'t have an attribute "%s"', |
|
| 100 | get_class($this), |
|
| 101 | $attr |
|
| 102 | ) |
|
| 103 | ); |
|
| 104 | } |
|
| 105 | ||
| 106 | public function toArray() |
|
| 107 | { |
|