blob: b0f6da820bc3173ff28ced86e363cea2a4814a4c (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<?php
namespace Elastica\QueryBuilder;
use Elastica\Exception\QueryBuilderException;
/**
* Facade for a specific DSL object.
*
* @author Manuel Andreo Garcia <andreo.garcia@googlemail.com>
**/
class Facade
{
/**
* @var DSL
*/
private $_dsl;
/**
* @var Version
*/
private $_version;
/**
* Constructor.
*
* @param DSL $dsl
* @param Version $version
*/
public function __construct(DSL $dsl, Version $version)
{
$this->_dsl = $dsl;
$this->_version = $version;
}
/**
* Executes DSL methods.
*
* @param string $name
* @param array $arguments
*
* @throws QueryBuilderException
*
* @return mixed
*/
public function __call($name, array $arguments)
{
// defined check
if (false === method_exists($this->_dsl, $name)) {
throw new QueryBuilderException(
'undefined '.$this->_dsl->getType().' "'.$name.'"'
);
}
// version support check
if (false === $this->_version->supports($name, $this->_dsl->getType())) {
$reflection = new \ReflectionClass($this->_version);
throw new QueryBuilderException(
$this->_dsl->getType().' "'.$name.'" in '.$reflection->getShortName().' not supported'
);
}
return call_user_func_array(array($this->_dsl, $name), $arguments);
}
}
|