Skip to content

Instantly share code, notes, and snippets.

@renan
Last active August 27, 2015 08:54
Show Gist options
  • Save renan/7a7ce1623506b78bc4b3 to your computer and use it in GitHub Desktop.
Save renan/7a7ce1623506b78bc4b3 to your computer and use it in GitHub Desktop.
<?php
public function __call($name, $arguments)
{
$callTypeIndex = 3;
if (substr($name, 0, 2) == "is") {
$callTypeIndex = 2;
}
$callType = substr($name, 0, $callTypeIndex);
$propertyName = substr($name, $callTypeIndex);
switch (true) {
case ($callType === 'get' && count($arguments) === 0):
return $this->get($propertyName);
case ($callType === 'add' && count($arguments) === 1):
return $this->add($propertyName);
case ($callType === 'set' && count($arguments) === 1):
return $this->set($propertyName);
case ($callType === 'is' && count($arguments) === 0):
return $this->is($propertyName);
default:
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment