| 1 | <?php |
||
| 13 | class Options { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | private $options = array(); |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @since 1.0 |
||
| 22 | * |
||
| 23 | * @param array $options |
||
| 24 | */ |
||
| 25 | 9 | public function __construct( array $options = array() ) { |
|
| 28 | |||
| 29 | /** |
||
| 30 | * @since 1.0 |
||
| 31 | * |
||
| 32 | * @return self |
||
| 33 | */ |
||
| 34 | 6 | public static function newFromGlobals() { |
|
| 48 | |||
| 49 | /** |
||
| 50 | * @since 1.0 |
||
| 51 | * |
||
| 52 | * @param string $key |
||
| 53 | * @param mixed $value |
||
| 54 | */ |
||
| 55 | 1 | public function set( $key, $value ) { |
|
| 58 | |||
| 59 | /** |
||
| 60 | * @since 1.0 |
||
| 61 | * |
||
| 62 | * @param string $key |
||
| 63 | * |
||
| 64 | * @return boolean |
||
| 65 | */ |
||
| 66 | 8 | public function has( $key ) { |
|
| 69 | |||
| 70 | /** |
||
| 71 | * @since 1.0 |
||
| 72 | * |
||
| 73 | * @param string $key |
||
| 74 | * |
||
| 75 | * @return string |
||
| 76 | * @throws InvalidArgumentException |
||
| 77 | */ |
||
| 78 | 2 | public function get( $key ) { |
|
| 86 | |||
| 87 | } |
||
| 88 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: