Add Flux from() and filter() methods

Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
davidarendsen 2022-08-05 15:41:38 +00:00
commit e0e69b4beb
17 changed files with 2095 additions and 0 deletions

15
src/Function/Base.php Normal file
View file

@ -0,0 +1,15 @@
<?php
namespace Arendsen\FluxQueryBuilder\Function;
abstract class Base {
/**
* @throws FunctionNotImplementedException
*/
public function __toString()
{
throw new FunctionNotImplementedException('__toString', get_class($this));
}
}

22
src/Function/Filter.php Normal file
View file

@ -0,0 +1,22 @@
<?php
namespace Arendsen\FluxQueryBuilder\Function;
class Filter extends Base {
/**
* @var array $settings
*/
private $settings;
public function __construct(array $settings)
{
$this->settings = $settings;
}
public function __toString()
{
return '|> filter(fn: (r) => ' . implode(' ', $this->settings) . ') ';
}
}

31
src/Function/From.php Normal file
View file

@ -0,0 +1,31 @@
<?php
namespace Arendsen\FluxQueryBuilder\Function;
class From extends Base {
/**
* @var array $settings
*/
private $settings;
public function __construct(array $settings)
{
$this->settings = $settings;
}
public function __toString()
{
return 'from(' . implode(', ', $this->format($this->settings)) . ') ';
}
protected function format(array $settings)
{
array_walk($settings, function(&$value, $key) {
$value = $key . ': ' . (is_string($value) ? '"' . $value . '"' : $value);
});
return $settings;
}
}

View file

@ -0,0 +1,7 @@
<?php
namespace Arendsen\FluxQueryBuilder\Function;
use Exception;
class FunctionNotImplementedException extends Exception {}