blob: ccaeb6dd4ba3f916b11d6f9403deb4d7e8589fcf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<?php
namespace Elastica\Connection\Strategy;
use Elastica\Exception\InvalidException;
/**
* Description of CallbackStrategy.
*
* @author chabior
*/
class CallbackStrategy implements StrategyInterface
{
/**
* @var callable
*/
protected $_callback;
/**
* @param callable $callback
*
* @throws \Elastica\Exception\InvalidException
*/
public function __construct($callback)
{
if (!self::isValid($callback)) {
throw new InvalidException(sprintf('Callback should be a callable, %s given!', gettype($callback)));
}
$this->_callback = $callback;
}
/**
* @param array|\Elastica\Connection[] $connections
*
* @return \Elastica\Connection
*/
public function getConnection($connections)
{
return call_user_func_array($this->_callback, array($connections));
}
/**
* @param callable $callback
*
* @return bool
*/
public static function isValid($callback)
{
return is_callable($callback);
}
}
|