Last active
December 19, 2015 22:09
-
-
Save oojacoboo/6025798 to your computer and use it in GitHub Desktop.
example of custom named methods to prevent passing strings as params to shared methods
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 | |
| namespace WidgetFactory\Modules; | |
| class MyModule extends MyORM | |
| { | |
| /** | |
| * Shared method to get the option value from the db | |
| * @param string $option | |
| * @return mixed | |
| */ | |
| private function getOption($option) { | |
| return $this->query("SELECT `value` FROM `module_option` WHERE `name` = ?", array($option)); | |
| } | |
| /** | |
| * Update the option value | |
| * @param string $option | |
| * @param mixed $value | |
| * @return mixed | |
| */ | |
| private function setOption($option, $value) { | |
| return $this->query("UPDATE `module_option` SET `value` = ? WHERE `name` = ?", array($value, $option)); | |
| } | |
| /** | |
| * Should we send emails with this module? | |
| * @return mixed | |
| */ | |
| public function getOptionSendEmails() { | |
| return $this->getOption("sendEmails"); | |
| } | |
| /** | |
| * Update the sendEmails option | |
| * @param mixed $value | |
| * @return mixed | |
| */ | |
| public function setOptionSendEmails($value) { | |
| return $this->setOption("sendEmails"); | |
| } | |
| /** | |
| * Is sharing to social networks enabled by default? | |
| * @return mixed | |
| */ | |
| public function getOptionShareByDefault() { | |
| return $this->getOption("shareByDefault"); | |
| } | |
| /** | |
| * Update the shareByDefault option | |
| * @param mixed $value | |
| * @return mixed | |
| */ | |
| public function setOptionShareByDefault($value) { | |
| return $this->setOption("shareByDefault"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment