Created
January 8, 2013 04:22
-
-
Save jehoshua02/4481121 to your computer and use it in GitHub Desktop.
Cuz we love seeing "Notice: Undefined index: ..." SOOOOO much!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require 'ValueHelper.php'; | |
| $get = new ValueHelper($_GET); | |
| $page = $get->options->page->value(1); | |
| $pageSize = $get->options->pageSize->value(10); | |
| $searchTerm = $get->options->searchTerm->value(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class ValueHelper | |
| { | |
| /** | |
| * Construct method | |
| * | |
| * @param mixed $value | |
| */ | |
| public function __construct($value) | |
| { | |
| $this->value = $value; | |
| } | |
| /** | |
| * Returns array item or null wrapped in another ValueHelper | |
| * | |
| * @param string $name | |
| * | |
| * @return ValueHelper | |
| */ | |
| public function __get($name) | |
| { | |
| if (is_array($this->value) && array_key_exists($name, $this->value)) { | |
| $value = $this->value[$name]; | |
| } else { | |
| $value = null; | |
| } | |
| return new ValueHelper($value); | |
| } | |
| /** | |
| * Returns value, or default if value is null | |
| * | |
| * @param mixed $default | |
| * | |
| * @return mixed | |
| */ | |
| public function value($default = null) | |
| { | |
| return ($this->value === null) ? $default : $this->value; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment