讨论数量:
public function process($type)
{
$typeMap = [
1 => 'processOne',
2 => 'processTwo',
];
if (! array_key_exists($type, $typeMap)) {
throw new \LogicException("unknown type $type");
}
$method = $typeMap[$type];
if (! method_exists($this, $method)) {
throw new \LogicException(sprintf("unknown implement method $method in class %s", get_class($this)));
}
return $this->{$method}();
}
推荐文章: