Rename namespace Function keyword to Functions to prevent errors
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
4c1a1a0af8
commit
79edee7400
19 changed files with 31 additions and 31 deletions
17
src/Functions/Base.php
Normal file
17
src/Functions/Base.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Formatters;
|
||||
|
||||
abstract class Base {
|
||||
|
||||
/**
|
||||
* @throws FunctionNotImplementedException
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
throw new FunctionNotImplementedException('__toString', get_class($this));
|
||||
}
|
||||
|
||||
}
|
||||
24
src/Functions/Filter.php
Normal file
24
src/Functions/Filter.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
||||
|
||||
class Filter extends Base {
|
||||
|
||||
/**
|
||||
* @var KeyValue $keyValue
|
||||
*/
|
||||
private $keyValue;
|
||||
|
||||
public function __construct(KeyValue $keyValue)
|
||||
{
|
||||
$this->keyValue = $keyValue;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> filter(fn: (r) => ' . $this->keyValue . ') ';
|
||||
}
|
||||
|
||||
}
|
||||
24
src/Functions/From.php
Normal file
24
src/Functions/From.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Formatters;
|
||||
|
||||
class From extends Base {
|
||||
|
||||
/**
|
||||
* @var array $settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
public function __construct(array $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return 'from(' . Formatters::toFluxArrayString($this->settings) . ') ';
|
||||
}
|
||||
|
||||
}
|
||||
7
src/Functions/FunctionNotImplementedException.php
Normal file
7
src/Functions/FunctionNotImplementedException.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FunctionNotImplementedException extends Exception {}
|
||||
35
src/Functions/Group.php
Normal file
35
src/Functions/Group.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Formatters;
|
||||
|
||||
class Group extends Base {
|
||||
|
||||
/**
|
||||
* @var array $columns
|
||||
*/
|
||||
private $columns;
|
||||
|
||||
/**
|
||||
* @var string $mode
|
||||
*/
|
||||
private $mode;
|
||||
|
||||
public function __construct(array $columns, string $mode = 'by')
|
||||
{
|
||||
$this->columns = $columns;
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$array = Formatters::toFluxArrayString([
|
||||
'columns' => $this->columns,
|
||||
'mode' => $this->mode,
|
||||
]);
|
||||
|
||||
return '|> group(' . $array . ') ';
|
||||
}
|
||||
|
||||
}
|
||||
22
src/Functions/Limit.php
Normal file
22
src/Functions/Limit.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
class Limit extends Base {
|
||||
|
||||
/**
|
||||
* @var int $limit
|
||||
*/
|
||||
private $limit;
|
||||
|
||||
public function __construct(int $limit)
|
||||
{
|
||||
$this->limit = $limit;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> limit(n:' . (string)$this->limit . ') ';
|
||||
}
|
||||
|
||||
}
|
||||
22
src/Functions/Map.php
Normal file
22
src/Functions/Map.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
class Map extends Base {
|
||||
|
||||
/**
|
||||
* @var array $query
|
||||
*/
|
||||
private $query;
|
||||
|
||||
public function __construct(string $query)
|
||||
{
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> map(fn: (r) => ({ ' . $this->query . ' })) ';
|
||||
}
|
||||
|
||||
}
|
||||
24
src/Functions/Range.php
Normal file
24
src/Functions/Range.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Formatters;
|
||||
|
||||
class Range extends Base {
|
||||
|
||||
/**
|
||||
* @var array $settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
public function __construct(array $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> range(' . Formatters::toFluxArrayString($this->settings) . ') ';
|
||||
}
|
||||
|
||||
}
|
||||
40
src/Functions/Reduce.php
Normal file
40
src/Functions/Reduce.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Formatters;
|
||||
|
||||
class Reduce extends Base {
|
||||
|
||||
/**
|
||||
* @var array $settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* @var array $identity
|
||||
*/
|
||||
private $identity;
|
||||
|
||||
public function __construct(array $settings, array $identity)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
$this->identity = $identity;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> reduce(fn: (r, accumulator) => ({' . implode(', ', $this->formatSettings($this->settings)) . '}), ' .
|
||||
'identity: {' . Formatters::toFluxArrayString($this->identity) . '}) ';
|
||||
}
|
||||
|
||||
protected function formatSettings(array $settings)
|
||||
{
|
||||
array_walk($settings, function(&$value, $key) {
|
||||
$value = $key . ': ' . $value;
|
||||
});
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
}
|
||||
31
src/Functions/Sort.php
Normal file
31
src/Functions/Sort.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Formatters;
|
||||
|
||||
class Sort extends Base {
|
||||
|
||||
/**
|
||||
* @var array $columns
|
||||
*/
|
||||
private $columns;
|
||||
|
||||
/**
|
||||
* @var bool $desc
|
||||
*/
|
||||
private $desc;
|
||||
|
||||
public function __construct(array $columns, bool $desc = false)
|
||||
{
|
||||
$this->columns = $columns;
|
||||
$this->desc = $desc;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> sort(columns: [' . Formatters::toFluxArrayString($this->columns) .
|
||||
'], desc: ' . Formatters::valueToString($this->desc) . ') ';
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue