summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/QueryBuilder/Facade.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/QueryBuilder/Facade.php')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/QueryBuilder/Facade.php64
1 files changed, 64 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/QueryBuilder/Facade.php b/vendor/ruflin/elastica/lib/Elastica/QueryBuilder/Facade.php
new file mode 100644
index 00000000..b0f6da82
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/QueryBuilder/Facade.php
@@ -0,0 +1,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);
+ }
+}