Add Map expression
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
c66b71ee57
commit
d52f3e9d74
10 changed files with 140 additions and 12 deletions
|
|
@ -204,4 +204,4 @@ class KeyFilter extends Base
|
|||
throw new Exception('Operator "' . $operator . '" is not supported!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -207,4 +207,4 @@ class KeyValue extends Base
|
|||
throw new Exception('Operator "' . $operator . '" is not supported!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
27
src/Expression/Map.php
Normal file
27
src/Expression/Map.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type\FieldRecordType;
|
||||
|
||||
class Map extends Base
|
||||
{
|
||||
private static $string;
|
||||
|
||||
public static function with(string $name, string $content): Map
|
||||
{
|
||||
self::$string = 'r with ' . $name . ': ' . $content;
|
||||
return new self();
|
||||
}
|
||||
|
||||
public static function columns(array $columns)
|
||||
{
|
||||
self::$string = new FieldRecordType($columns);
|
||||
return new self();
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return self::$string;
|
||||
}
|
||||
}
|
||||
37
src/Expression/Selection.php
Normal file
37
src/Expression/Selection.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
|
||||
class Selection extends Base
|
||||
{
|
||||
private $string;
|
||||
|
||||
private function __construct(string $string)
|
||||
{
|
||||
$this->string = $string;
|
||||
}
|
||||
|
||||
public static function if(string $value): Selection
|
||||
{
|
||||
return new self('if ' . $value);
|
||||
}
|
||||
|
||||
public function then($then): Selection
|
||||
{
|
||||
$this->string .= ' then ' . new Type($then);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function else($else): Selection
|
||||
{
|
||||
$this->string .= ' else ' . new Type($else);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->string;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,14 +2,16 @@
|
|||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Expression\Map as MapExpression;
|
||||
|
||||
class Map extends Base
|
||||
{
|
||||
/**
|
||||
* @var array $query
|
||||
* @var mixed $query
|
||||
*/
|
||||
private $query;
|
||||
|
||||
public function __construct(string $query)
|
||||
public function __construct($query)
|
||||
{
|
||||
$this->query = $query;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ class QueryBuilder
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function addMap(string $query): QueryBuilder
|
||||
public function addMap($query): QueryBuilder
|
||||
{
|
||||
$this->addToQuery(
|
||||
self::FLUX_PART_MAP,
|
||||
|
|
|
|||
27
src/Type/FieldRecordType.php
Normal file
27
src/Type/FieldRecordType.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Type;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Settings;
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
|
||||
class FieldRecordType implements TypeInterface
|
||||
{
|
||||
public const SETTING_IS_RECORD = 'isRecord';
|
||||
|
||||
public function __construct(array $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
array_walk($this->value, function (&$value, $key) {
|
||||
if (is_string($key)) {
|
||||
$value = $key . ': ' . $value;
|
||||
}
|
||||
});
|
||||
|
||||
return '{' . implode(', ', $this->value) . '}';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue