Skip to content

Instantly share code, notes, and snippets.

@oojacoboo
Last active December 19, 2015 22:09
Show Gist options
  • Select an option

  • Save oojacoboo/6025798 to your computer and use it in GitHub Desktop.

Select an option

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
<?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