Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move SitesCache invocation out of Site model #299

Merged
merged 2 commits into from
Jul 29, 2015
Merged

Conversation

bensheldon
Copy link
Contributor

Make responsibilities a little clearer and the Site model a little more free-standing by removing any reliance on caching.

Question: what's the best way to shadow static methods with instance methods? Apparently PHP won't let them have the same name.

public function __construct() {
$this->cache = Terminus::get_cache();
}

// Returns the UUID of the site
public function find($name, $options = array()) {
public function _find($name, $options = array()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this function be private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... I wasn't really sure. The instance is mostly there for OOPness, but I don't really expect the instance to be really used. I'll just make it private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TeslaDethray I just made the method private. Can you please take another look at this PR? Thanks!

@TeslaDethray
Copy link
Contributor

+1
To answer your question, since PHP doesn't support overloading as other languages do, the way you would make it work as though it did would to access both functions via __call($function, $args) and __callStatic($function, $args) and have it map the call to the true names of these functions. I would use:

public function findInstance($args) {
...
}
public function __call($function, $args) {
  $function_name = $function . 'Instance';
  return $this->$function_name($args);
}
public static function __callStatic($function, $args) {
  $function_name = $function . 'Instance';
  $this_class = new ThisClass();
  return $this_class->$function_name($args);
}

That being said, it's neither elegant nor great for readability. PHP overloading is a strange game, and the only winning move is not to play.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants