public function getClientBy($selector, $value, $callable = null)
{
$selector = strtolower($selector);
if (!in_array($selector, array('id', 'key', 'slot', 'role', 'alias', 'command'))) {
throw new \InvalidArgumentException("Invalid selector type: `{$selector}`");
}
if (!method_exists($this->connection, $method = "getConnectionBy{$selector}")) {
$class = get_class($this->connection);
throw new \InvalidArgumentException("Selecting connection by {$selector} is not supported by {$class}");
}
if (!($connection = $this->connection->{$method}($value))) {
throw new \InvalidArgumentException("Cannot find a connection by {$selector} matching `{$value}`");
}
$client = new static($connection, $this->getOptions());
if ($callable) {
return call_user_func($callable, $client);
} else {
return $client;
}
}