diff --git a/composer.json b/composer.json index 671c07b..3170feb 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { - "name": "danielmewes/php-rql", + "name": "geekimo/php-rql", "type": "library", "description": "A PHP client driver for the RethinkDB query language (ReQL)", "keywords": ["rethinkdb","driver","database","reql"], - "homepage": "http://danielmewes.github.io/php-rql/", + "homepage": "https://github.com/Geekimo/php-rql/", "license": "Apache-2.0", "authors": [ { @@ -11,6 +11,11 @@ "email": "danielmewes@onlinehome.de", "homepage": "http://dmewes.com", "role": "Developer" + }, + { + "name": "Morgan Abraham", + "email": "morgan@tramicms.net", + "role": "Developer" } ], "require": { diff --git a/rdb/Connection.php b/rdb/Connection.php index dcfdf63..5d7519c 100644 --- a/rdb/Connection.php +++ b/rdb/Connection.php @@ -271,7 +271,6 @@ public function run(Query $query, $options = array(), &$profile = '') } else { return $this->createCursorFromResponse($response, $token, $response['n'], $toNativeOptions); } - } public function continueQuery($token) diff --git a/rdb/DatumConverter.php b/rdb/DatumConverter.php index 055e3a9..eb67ada 100644 --- a/rdb/DatumConverter.php +++ b/rdb/DatumConverter.php @@ -158,7 +158,6 @@ public function canEncodeAsJson($v) } return false; - } public function wrapImplicitVar(Query $q) diff --git a/rdb/Queries/Aggregations/Contains.php b/rdb/Queries/Aggregations/Contains.php index 673d399..e3353e4 100644 --- a/rdb/Queries/Aggregations/Contains.php +++ b/rdb/Queries/Aggregations/Contains.php @@ -7,12 +7,13 @@ class Contains extends ValuedQuery { - public function __construct(ValuedQuery $sequence, $value) + public function __construct(ValuedQuery $sequence, array $values) { - $value = $this->nativeToDatumOrFunction($value); - $this->setPositionalArg(0, $sequence); - $this->setPositionalArg(1, $value); + + foreach ($values as $k => $value) { + $this->setPositionalArg($k+1, $this->nativeToDatumOrFunction($value)); + } } protected function getTermType() diff --git a/rdb/Queries/Control/Branch.php b/rdb/Queries/Control/Branch.php index 8772bd3..d9df5d0 100644 --- a/rdb/Queries/Control/Branch.php +++ b/rdb/Queries/Control/Branch.php @@ -2,20 +2,34 @@ namespace r\Queries\Control; +use r\Exceptions\RqlException; use r\Query; use r\ValuedQuery\ValuedQuery; use r\ProtocolBuffer\TermTermType; class Branch extends ValuedQuery { - public function __construct(Query $test, $trueBranch, $falseBranch) + public function __construct(array $branches) { - $trueBranch = $this->nativeToDatumOrFunction($trueBranch, false); - $falseBranch = $this->nativeToDatumOrFunction($falseBranch, false); + if (count($branches) % 2 == 1) { + // poping 'false' branch from other branches + $falseBranch = $this->nativeToDatumOrFunction(array_pop($branches), false); - $this->setPositionalArg(0, $test); - $this->setPositionalArg(1, $trueBranch); - $this->setPositionalArg(2, $falseBranch); + // for each remaning branch, if the index is odd, this is a branch, so we convert, otherwise, we directly position the argument + foreach ($branches as $i => $branch) { + if($i % 2 == 1) { + // branch, so we convert + $branch = $this->nativeToDatumOrFunction($branch, false); + } + + $this->setPositionalArg($i, $branch); + } + + // pushing the 'false' branch at the end of positional args + $this->setPositionalArg(count($branches), $falseBranch); + } else { + throw new RqlException(__METHOD__ . ' must have at least 3 parameters, or an odd parameter count.'); + } } protected function getTermType() diff --git a/rdb/Queries/Math/Add.php b/rdb/Queries/Math/Add.php index 3c8a3e0..5eddf6c 100644 --- a/rdb/Queries/Math/Add.php +++ b/rdb/Queries/Math/Add.php @@ -9,6 +9,6 @@ class Add extends BinaryOp { public function __construct($value, $other) { - parent::__construct(TermTermType::PB_ADD, $value, $other); + parent::__construct(TermTermType::PB_ADD, array($value, $other)); } } diff --git a/rdb/Queries/Math/BinaryOp.php b/rdb/Queries/Math/BinaryOp.php index d91786d..ee1373f 100644 --- a/rdb/Queries/Math/BinaryOp.php +++ b/rdb/Queries/Math/BinaryOp.php @@ -6,12 +6,13 @@ class BinaryOp extends ValuedQuery { - public function __construct($termType, $value, $other) + public function __construct($termType, array $exprs) { $this->termType = $termType; - $this->setPositionalArg(0, $this->nativeToDatum($value)); - $this->setPositionalArg(1, $this->nativeToDatum($other)); + foreach ($exprs as $k => $expr) { + $this->setPositionalArg($k, $this->nativeToDatum($expr)); + } } protected function getTermType() diff --git a/rdb/Queries/Math/Div.php b/rdb/Queries/Math/Div.php index 3174b22..d63da90 100644 --- a/rdb/Queries/Math/Div.php +++ b/rdb/Queries/Math/Div.php @@ -9,6 +9,6 @@ class Div extends BinaryOp { public function __construct($value, $other) { - parent::__construct(TermTermType::PB_DIV, $value, $other); + parent::__construct(TermTermType::PB_DIV, array($value, $other)); } } diff --git a/rdb/Queries/Math/Eq.php b/rdb/Queries/Math/Eq.php index 47e084b..00ed410 100644 --- a/rdb/Queries/Math/Eq.php +++ b/rdb/Queries/Math/Eq.php @@ -9,6 +9,6 @@ class Eq extends BinaryOp { public function __construct($value, $other) { - parent::__construct(TermTermType::PB_EQ, $value, $other); + parent::__construct(TermTermType::PB_EQ, array($value, $other)); } } diff --git a/rdb/Queries/Math/Ge.php b/rdb/Queries/Math/Ge.php index a6f2ded..cd9f00a 100644 --- a/rdb/Queries/Math/Ge.php +++ b/rdb/Queries/Math/Ge.php @@ -8,6 +8,6 @@ class Ge extends BinaryOp { public function __construct($value, $other) { - parent::__construct(TermTermType::PB_GE, $value, $other); + parent::__construct(TermTermType::PB_GE, array($value, $other)); } } diff --git a/rdb/Queries/Math/Gt.php b/rdb/Queries/Math/Gt.php index 1f78875..d10c853 100644 --- a/rdb/Queries/Math/Gt.php +++ b/rdb/Queries/Math/Gt.php @@ -9,6 +9,6 @@ class Gt extends BinaryOp { public function __construct($value, $other) { - parent::__construct(TermTermType::PB_GT, $value, $other); + parent::__construct(TermTermType::PB_GT, array($value, $other)); } } diff --git a/rdb/Queries/Math/Le.php b/rdb/Queries/Math/Le.php index d296528..a436026 100644 --- a/rdb/Queries/Math/Le.php +++ b/rdb/Queries/Math/Le.php @@ -8,6 +8,6 @@ class Le extends BinaryOp { public function __construct($value, $other) { - parent::__construct(TermTermType::PB_LE, $value, $other); + parent::__construct(TermTermType::PB_LE, array($value, $other)); } } diff --git a/rdb/Queries/Math/Lt.php b/rdb/Queries/Math/Lt.php index fed06b9..7aaa7b0 100644 --- a/rdb/Queries/Math/Lt.php +++ b/rdb/Queries/Math/Lt.php @@ -8,6 +8,6 @@ class Lt extends BinaryOp { public function __construct($value, $other) { - parent::__construct(TermTermType::PB_LT, $value, $other); + parent::__construct(TermTermType::PB_LT, array($value, $other)); } } diff --git a/rdb/Queries/Math/Mod.php b/rdb/Queries/Math/Mod.php index eda29bf..f7270fa 100644 --- a/rdb/Queries/Math/Mod.php +++ b/rdb/Queries/Math/Mod.php @@ -8,6 +8,6 @@ class Mod extends BinaryOp { public function __construct($value, $other) { - parent::__construct(TermTermType::PB_MOD, $value, $other); + parent::__construct(TermTermType::PB_MOD, array($value, $other)); } } diff --git a/rdb/Queries/Math/Mul.php b/rdb/Queries/Math/Mul.php index 615c5a6..3292960 100644 --- a/rdb/Queries/Math/Mul.php +++ b/rdb/Queries/Math/Mul.php @@ -8,6 +8,6 @@ class Mul extends BinaryOp { public function __construct($value, $other) { - parent::__construct(TermTermType::PB_MUL, $value, $other); + parent::__construct(TermTermType::PB_MUL, array($value, $other)); } } diff --git a/rdb/Queries/Math/Ne.php b/rdb/Queries/Math/Ne.php index 3d95e9c..8202da1 100644 --- a/rdb/Queries/Math/Ne.php +++ b/rdb/Queries/Math/Ne.php @@ -9,6 +9,6 @@ class Ne extends BinaryOp { public function __construct($value, $other) { - parent::__construct(TermTermType::PB_NE, $value, $other); + parent::__construct(TermTermType::PB_NE, array($value, $other)); } } diff --git a/rdb/Queries/Math/RAnd.php b/rdb/Queries/Math/RAnd.php index 3186fed..5abec05 100644 --- a/rdb/Queries/Math/RAnd.php +++ b/rdb/Queries/Math/RAnd.php @@ -6,8 +6,8 @@ class RAnd extends BinaryOp { - public function __construct($value, $other) + public function __construct(array $exprs) { - parent::__construct(TermTermType::PB_AND, $value, $other); + parent::__construct(TermTermType::PB_AND, $exprs); } } diff --git a/rdb/Queries/Math/ROr.php b/rdb/Queries/Math/ROr.php index 449604e..cd6b2bc 100644 --- a/rdb/Queries/Math/ROr.php +++ b/rdb/Queries/Math/ROr.php @@ -6,8 +6,8 @@ class ROr extends BinaryOp { - public function __construct($value, $other) + public function __construct(array $exprs) { - parent::__construct(TermTermType::PB_OR, $value, $other); + parent::__construct(TermTermType::PB_OR, $exprs); } } diff --git a/rdb/Queries/Math/Sub.php b/rdb/Queries/Math/Sub.php index a82174e..3f5a34e 100644 --- a/rdb/Queries/Math/Sub.php +++ b/rdb/Queries/Math/Sub.php @@ -8,6 +8,6 @@ class Sub extends BinaryOp { public function __construct($value, $other) { - parent::__construct(TermTermType::PB_SUB, $value, $other); + parent::__construct(TermTermType::PB_SUB, array($value, $other)); } } diff --git a/rdb/ValuedQuery/ValuedQuery.php b/rdb/ValuedQuery/ValuedQuery.php index fd983a6..94e70de 100644 --- a/rdb/ValuedQuery/ValuedQuery.php +++ b/rdb/ValuedQuery/ValuedQuery.php @@ -240,9 +240,9 @@ public function max($attributeOrOpts = null) } // Note: The API docs suggest that as of 1.6, contains can accept multiple values. // We do not support that for the time being. - public function contains($value) + public function contains() { - return new Contains($this, $value); + return new Contains($this, func_get_args()); } public function pluck($attributes) { @@ -337,13 +337,21 @@ public function mod($other) { return new Mod($this, $other); } - public function rAnd($other) + public function rAnd() { - return new RAnd($this, $other); + $exprs = func_get_args(); + + array_unshift($exprs, $this); + + return new RAnd($exprs); } - public function rOr($other) + public function rOr() { - return new ROr($this, $other); + $exprs = func_get_args(); + + array_unshift($exprs, $this); + + return new ROr($exprs); } public function eq($other) { diff --git a/rdb/global.php b/rdb/global.php index 6a81fe2..fdb056f 100644 --- a/rdb/global.php +++ b/rdb/global.php @@ -135,9 +135,9 @@ function args($args) return new Args($args); } -function branch(Query $test, $trueBranch, $falseBranch) +function branch() { - return new Branch($test, $trueBranch, $falseBranch); + return new Branch(func_get_args()); } function row($attribute = null) @@ -238,13 +238,13 @@ function mod($expr1, $expr2) return new Mod($expr1, $expr2); } -function rAnd($expr1, $expr2) +function rAnd() { - return new RAnd($expr1, $expr2); + return new RAnd(func_get_args()); } -function rOr($expr1, $expr2) +function rOr() { - return new ROr($expr1, $expr2); + return new ROr(func_get_args()); } function eq($expr1, $expr2)