Add new types Array, Boolean, Record, Math

Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
davidarendsen 2022-08-16 14:46:06 +00:00
commit 057a2d625e
10 changed files with 137 additions and 29 deletions

27
src/Type/ArrayType.php Normal file
View file

@ -0,0 +1,27 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
use Arendsen\FluxQueryBuilder\Formatters;
use Arendsen\FluxQueryBuilder\Type;
class ArrayType implements TypeInterface
{
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 . ': ' . Formatters::valueToString($value);
} else {
$value = Formatters::valueToString($value);
}
});
return implode(', ', $this->value);
}
}

16
src/Type/BooleanType.php Normal file
View file

@ -0,0 +1,16 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
class BooleanType implements TypeInterface
{
public function __construct($value)
{
$this->value = $value;
}
public function __toString(): string
{
return $this->value ? 'true' : 'false';
}
}

19
src/Type/Math.php Normal file
View file

@ -0,0 +1,19 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
use Arendsen\FluxQueryBuilder\Formatters;
use Arendsen\FluxQueryBuilder\Type;
class Math implements TypeInterface
{
public function __construct(string $value)
{
$this->value = $value;
}
public function __toString(): string
{
return $this->value;
}
}

26
src/Type/Record.php Normal file
View file

@ -0,0 +1,26 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
use Arendsen\FluxQueryBuilder\Type;
class Record implements TypeInterface
{
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 . ': ' . new Type($value);
} else {
$value = new Type($value);
}
});
return '{' . implode(', ', $this->value) . '}';
}
}