Marks fork as 2.0.0.
This commit is contained in:
parent
d93a6b5c09
commit
8d8de4a2b0
81 changed files with 1921 additions and 3954 deletions
|
|
@ -1,118 +1,97 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Builder;
|
||||
namespace Hosterra\FluxBuilder\Builder;
|
||||
|
||||
use DateTime;
|
||||
use Arendsen\FluxQueryBuilder\QueryBuilder;
|
||||
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Filter;
|
||||
use Arendsen\FluxQueryBuilder\Functions\From;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Measurement;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Range;
|
||||
use Arendsen\FluxQueryBuilder\Functions\RawFunction;
|
||||
use Hosterra\FluxBuilder\QueryBuilder;
|
||||
use Hosterra\FluxBuilder\Builder\QueryBuilderInterface;
|
||||
use Hosterra\FluxBuilder\Expression\KeyFilter;
|
||||
use Hosterra\FluxBuilder\Functions\Filter;
|
||||
use Hosterra\FluxBuilder\Functions\From;
|
||||
use Hosterra\FluxBuilder\Functions\Measurement;
|
||||
use Hosterra\FluxBuilder\Functions\Range;
|
||||
use Hosterra\FluxBuilder\Functions\RawFunction;
|
||||
|
||||
trait Basics
|
||||
{
|
||||
public function from(array $from): QueryBuilderInterface
|
||||
{
|
||||
$this->setRequirements();
|
||||
trait Basics {
|
||||
public function from( array $from ): QueryBuilderInterface {
|
||||
$this->setRequirements();
|
||||
|
||||
$this->addToQuery(
|
||||
new From($from)
|
||||
);
|
||||
$this->addToQuery(
|
||||
new From( $from )
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function fromBucket(string $bucket): QueryBuilderInterface
|
||||
{
|
||||
return $this->from(['bucket' => $bucket]);
|
||||
}
|
||||
public function fromBucket( string $bucket ): QueryBuilderInterface {
|
||||
return $this->from( [ 'bucket' => $bucket ] );
|
||||
}
|
||||
|
||||
public function fromMeasurement(string $measurement): QueryBuilderInterface
|
||||
{
|
||||
$this->setRequirements();
|
||||
public function fromMeasurement( string $measurement ): QueryBuilderInterface {
|
||||
$this->setRequirements();
|
||||
|
||||
$this->addToQuery(
|
||||
new Measurement($measurement)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
$this->addToQuery(
|
||||
new Measurement( $measurement )
|
||||
);
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* @param KeyValue $keyValue
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function addFilter(KeyValue $keyValue): QueryBuilderInterface
|
||||
{
|
||||
$this->setRequirements();
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->addToQuery(
|
||||
new Filter($keyValue)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
public function addKeyFilter( KeyFilter $keyFilter ): QueryBuilderInterface {
|
||||
$this->setRequirements();
|
||||
|
||||
public function addKeyFilter(KeyFilter $keyFilter): QueryBuilderInterface
|
||||
{
|
||||
$this->setRequirements();
|
||||
$this->addToQuery(
|
||||
new Filter( $keyFilter )
|
||||
);
|
||||
|
||||
$this->addToQuery(
|
||||
new Filter($keyFilter)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addFieldFilter(array $fields): QueryBuilderInterface
|
||||
{
|
||||
$this->setRequirements();
|
||||
public function addFieldFilter( array $fields ): QueryBuilderInterface {
|
||||
$this->setRequirements();
|
||||
|
||||
$this->addToQuery(
|
||||
new Filter($fields)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
$this->addToQuery(
|
||||
new Filter( $fields )
|
||||
);
|
||||
|
||||
public function addRange(DateTime $start, ?DateTime $stop = null): QueryBuilderInterface
|
||||
{
|
||||
$this->setRequirements();
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->addToQuery(
|
||||
new Range($start, $stop)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
public function addRange( DateTime $start, ?DateTime $stop = null ): QueryBuilderInterface {
|
||||
$this->setRequirements();
|
||||
|
||||
public function addRangeStart(DateTime $start): QueryBuilderInterface
|
||||
{
|
||||
$this->addRange($start);
|
||||
return $this;
|
||||
}
|
||||
$this->addToQuery(
|
||||
new Range( $start, $stop )
|
||||
);
|
||||
|
||||
public function addRangeInBetween(DateTime $start, DateTime $stop): QueryBuilderInterface
|
||||
{
|
||||
$this->addRange($start, $stop);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addRawFunction(string $input): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new RawFunction($input)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
public function addRangeStart( DateTime $start ): QueryBuilderInterface {
|
||||
$this->addRange( $start );
|
||||
|
||||
private function setRequirements()
|
||||
{
|
||||
$this->requiredFluxQueryParts = [
|
||||
From::class,
|
||||
Range::class,
|
||||
Measurement::class,
|
||||
];
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addRangeInBetween( DateTime $start, DateTime $stop ): QueryBuilderInterface {
|
||||
$this->addRange( $start, $stop );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addRawFunction( string $input ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new RawFunction( $input )
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function setRequirements() {
|
||||
$this->requiredFluxQueryParts = [
|
||||
From::class,
|
||||
Range::class,
|
||||
Measurement::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Builder;
|
||||
namespace Hosterra\FluxBuilder\Builder;
|
||||
|
||||
interface QueryBuilderInterface
|
||||
{
|
||||
public function build(): string;
|
||||
interface QueryBuilderInterface {
|
||||
public function build(): string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,167 +1,166 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Builder;
|
||||
namespace Hosterra\FluxBuilder\Builder;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
|
||||
use Arendsen\FluxQueryBuilder\Functions\AggregateWindow;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Bottom;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Count;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Duplicate;
|
||||
use Arendsen\FluxQueryBuilder\Functions\First;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Group;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Last;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Limit;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Map;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Max;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Mean;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Min;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Reduce;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Sort;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Sum;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Unique;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Window;
|
||||
use Hosterra\FluxBuilder\Builder\QueryBuilderInterface;
|
||||
use Hosterra\FluxBuilder\Functions\AggregateWindow;
|
||||
use Hosterra\FluxBuilder\Functions\Bottom;
|
||||
use Hosterra\FluxBuilder\Functions\Count;
|
||||
use Hosterra\FluxBuilder\Functions\Duplicate;
|
||||
use Hosterra\FluxBuilder\Functions\First;
|
||||
use Hosterra\FluxBuilder\Functions\Group;
|
||||
use Hosterra\FluxBuilder\Functions\Last;
|
||||
use Hosterra\FluxBuilder\Functions\Limit;
|
||||
use Hosterra\FluxBuilder\Functions\Map;
|
||||
use Hosterra\FluxBuilder\Functions\Max;
|
||||
use Hosterra\FluxBuilder\Functions\Mean;
|
||||
use Hosterra\FluxBuilder\Functions\Min;
|
||||
use Hosterra\FluxBuilder\Functions\Reduce;
|
||||
use Hosterra\FluxBuilder\Functions\Sort;
|
||||
use Hosterra\FluxBuilder\Functions\Sum;
|
||||
use Hosterra\FluxBuilder\Functions\Unique;
|
||||
use Hosterra\FluxBuilder\Functions\Window;
|
||||
|
||||
trait Universe
|
||||
{
|
||||
public function addAggregateWindow($every, $fn, array $options = []): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new AggregateWindow($every, $fn, $options)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
trait Universe {
|
||||
public function addAggregateWindow( $every, $fn, array $options = [] ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new AggregateWindow( $every, $fn, $options )
|
||||
);
|
||||
|
||||
public function addBottom(int $n, array $columns = []): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(new Bottom($n, $columns));
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addCount(?string $column = null): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Count($column)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
public function addBottom( int $n, array $columns = [] ): QueryBuilderInterface {
|
||||
$this->addToQuery( new Bottom( $n, $columns ) );
|
||||
|
||||
public function addDuplicate(string $column, string $as): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Duplicate($column, $as)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addFirst(?string $column = null): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new First($column)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
public function addCount( ?string $column = null ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Count( $column )
|
||||
);
|
||||
|
||||
public function addGroup(array $columns, $mode = 'by'): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Group($columns, $mode)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addLast(string $column = '_value'): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Last($column)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
public function addDuplicate( string $column, string $as ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Duplicate( $column, $as )
|
||||
);
|
||||
|
||||
public function addLimit(int $limit, int $offset = 0): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Limit($limit, $offset)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addMap($query): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Map($query)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
public function addFirst( ?string $column = null ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new First( $column )
|
||||
);
|
||||
|
||||
public function addMax(?string $column = null): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Max($column)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addMean(?string $column = ''): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Mean($column)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
public function addGroup( array $columns, $mode = 'by' ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Group( $columns, $mode )
|
||||
);
|
||||
|
||||
public function addMin(?string $column = null): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Min($column)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addReduce(array $settings, array $identity): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Reduce($settings, $identity)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
public function addLast( string $column = '_value' ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Last( $column )
|
||||
);
|
||||
|
||||
public function addSort(array $columns = ['_value'], bool $desc = false): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Sort($columns, $desc)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addSum(string $column): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Sum($column)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
public function addLimit( int $limit, int $offset = 0 ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Limit( $limit, $offset )
|
||||
);
|
||||
|
||||
public function addUnique(?string $column = null): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Unique($column)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addUnWindow(): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Window('inf')
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
public function addMap( $query ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Map( $query )
|
||||
);
|
||||
|
||||
public function addWindow($every, array $options = []): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Window($every, $options)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addMax( ?string $column = null ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Max( $column )
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addMean( ?string $column = '' ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Mean( $column )
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addMin( ?string $column = null ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Min( $column )
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addReduce( array $settings, array $identity ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Reduce( $settings, $identity )
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addSort( array $columns = [ '_value' ], bool $desc = false ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Sort( $columns, $desc )
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addSum( string $column ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Sum( $column )
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addUnique( ?string $column = null ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Unique( $column )
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addUnWindow(): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Window( 'inf' )
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addWindow( $every, array $options = [] ): QueryBuilderInterface {
|
||||
$this->addToQuery(
|
||||
new Window( $every, $options )
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Exception;
|
||||
namespace Hosterra\FluxBuilder\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ExpressionNotImplementedException extends Exception
|
||||
{
|
||||
class ExpressionNotImplementedException extends Exception {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Exception;
|
||||
namespace Hosterra\FluxBuilder\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FunctionInvalidInputException extends Exception
|
||||
{
|
||||
class FunctionInvalidInputException extends Exception {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Exception;
|
||||
namespace Hosterra\FluxBuilder\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FunctionNotImplementedException extends Exception
|
||||
{
|
||||
class FunctionNotImplementedException extends Exception {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Exception;
|
||||
namespace Hosterra\FluxBuilder\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FunctionRequiredSettingMissingException extends Exception
|
||||
{
|
||||
public function __construct(string $functionName, string $message)
|
||||
{
|
||||
parent::__construct('Function ' . $functionName . ' - ' . $message);
|
||||
}
|
||||
class FunctionRequiredSettingMissingException extends Exception {
|
||||
public function __construct( string $functionName, string $message ) {
|
||||
parent::__construct( 'Function ' . $functionName . ' - ' . $message );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
||||
namespace Hosterra\FluxBuilder\Expression;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Exception\ExpressionNotImplementedException;
|
||||
use Hosterra\FluxBuilder\Exception\ExpressionNotImplementedException;
|
||||
|
||||
abstract class Base
|
||||
{
|
||||
/**
|
||||
* @throws ExpressionNotImplementedException
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
throw new ExpressionNotImplementedException('__toString', get_class($this));
|
||||
}
|
||||
abstract class Base {
|
||||
/**
|
||||
* @throws ExpressionNotImplementedException
|
||||
*/
|
||||
public function __toString() {
|
||||
throw new ExpressionNotImplementedException( '__toString', get_class( $this ) );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,207 +1,194 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
||||
namespace Hosterra\FluxBuilder\Expression;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
use Exception;
|
||||
|
||||
class KeyFilter extends Base
|
||||
{
|
||||
public const EQUAL_TO = '==';
|
||||
public const NOT_EQUAL_TO = '!=';
|
||||
public const GREATER_THAN = '>';
|
||||
public const GREATER_EQUAL_TO = '>=';
|
||||
public const LESS_THAN = '<';
|
||||
public const LESS_EQUAL_TO = '<=';
|
||||
public const EQUAL_TO_REGEX = '=~';
|
||||
public const NOT_EQUAL_TO_REGEX = '!~';
|
||||
class KeyFilter extends Base {
|
||||
public const EQUAL_TO = '==';
|
||||
public const NOT_EQUAL_TO = '!=';
|
||||
public const GREATER_THAN = '>';
|
||||
public const GREATER_EQUAL_TO = '>=';
|
||||
public const LESS_THAN = '<';
|
||||
public const LESS_EQUAL_TO = '<=';
|
||||
public const EQUAL_TO_REGEX = '=~';
|
||||
public const NOT_EQUAL_TO_REGEX = '!~';
|
||||
|
||||
public const COMPARISON_OPERATORS = [
|
||||
self::EQUAL_TO,
|
||||
self::NOT_EQUAL_TO,
|
||||
self::GREATER_THAN,
|
||||
self::GREATER_EQUAL_TO,
|
||||
self::LESS_THAN,
|
||||
self::LESS_EQUAL_TO,
|
||||
self::EQUAL_TO_REGEX,
|
||||
self::NOT_EQUAL_TO_REGEX,
|
||||
];
|
||||
public const COMPARISON_OPERATORS = [
|
||||
self::EQUAL_TO,
|
||||
self::NOT_EQUAL_TO,
|
||||
self::GREATER_THAN,
|
||||
self::GREATER_EQUAL_TO,
|
||||
self::LESS_THAN,
|
||||
self::LESS_EQUAL_TO,
|
||||
self::EQUAL_TO_REGEX,
|
||||
self::NOT_EQUAL_TO_REGEX,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array $expressions
|
||||
*/
|
||||
private $expressions;
|
||||
/**
|
||||
* @var array $expressions
|
||||
*/
|
||||
private $expressions;
|
||||
|
||||
private function __construct(string $key, string $operator, $value)
|
||||
{
|
||||
$this->checkOperator($operator);
|
||||
$this->expressions[] = 'r.' . $key . ' ' . $operator . ' ' . new Type($value);
|
||||
}
|
||||
private function __construct( string $key, string $operator, $value ) {
|
||||
$this->checkOperator( $operator );
|
||||
$this->expressions[] = 'r.' . $key . ' ' . $operator . ' ' . new Type( $value );
|
||||
}
|
||||
|
||||
public static function set(string $key, string $operator, $value): KeyFilter
|
||||
{
|
||||
return new self($key, $operator, $value);
|
||||
}
|
||||
public static function set( string $key, string $operator, $value ): KeyFilter {
|
||||
return new self( $key, $operator, $value );
|
||||
}
|
||||
|
||||
public static function setEqualTo(string $key, string $value): KeyFilter
|
||||
{
|
||||
return self::set($key, self::EQUAL_TO, $value);
|
||||
}
|
||||
public static function setEqualTo( string $key, string $value ): KeyFilter {
|
||||
return self::set( $key, self::EQUAL_TO, $value );
|
||||
}
|
||||
|
||||
public static function setNotEqualTo(string $key, string $value): KeyFilter
|
||||
{
|
||||
return self::set($key, self::NOT_EQUAL_TO, $value);
|
||||
}
|
||||
public static function setNotEqualTo( string $key, string $value ): KeyFilter {
|
||||
return self::set( $key, self::NOT_EQUAL_TO, $value );
|
||||
}
|
||||
|
||||
public static function setGreaterThan(string $key, int $value): KeyFilter
|
||||
{
|
||||
return self::set($key, self::GREATER_THAN, $value);
|
||||
}
|
||||
public static function setGreaterThan( string $key, int $value ): KeyFilter {
|
||||
return self::set( $key, self::GREATER_THAN, $value );
|
||||
}
|
||||
|
||||
public static function setGreaterOrEqualTo(string $key, int $value): KeyFilter
|
||||
{
|
||||
return self::set($key, self::GREATER_EQUAL_TO, $value);
|
||||
}
|
||||
public static function setGreaterOrEqualTo( string $key, int $value ): KeyFilter {
|
||||
return self::set( $key, self::GREATER_EQUAL_TO, $value );
|
||||
}
|
||||
|
||||
public static function setLessThan(string $key, int $value): KeyFilter
|
||||
{
|
||||
return self::set($key, self::LESS_THAN, $value);
|
||||
}
|
||||
public static function setLessThan( string $key, int $value ): KeyFilter {
|
||||
return self::set( $key, self::LESS_THAN, $value );
|
||||
}
|
||||
|
||||
public static function setLessOrEqualTo(string $key, int $value): KeyFilter
|
||||
{
|
||||
return self::set($key, self::LESS_EQUAL_TO, $value);
|
||||
}
|
||||
public static function setLessOrEqualTo( string $key, int $value ): KeyFilter {
|
||||
return self::set( $key, self::LESS_EQUAL_TO, $value );
|
||||
}
|
||||
|
||||
public static function setEqualToRegex(string $key, string $value): KeyFilter
|
||||
{
|
||||
return self::set($key, self::EQUAL_TO_REGEX, $value);
|
||||
}
|
||||
public static function setEqualToRegex( string $key, string $value ): KeyFilter {
|
||||
return self::set( $key, self::EQUAL_TO_REGEX, $value );
|
||||
}
|
||||
|
||||
public static function setNotEqualToRegex(string $key, string $value): KeyFilter
|
||||
{
|
||||
return self::set($key, self::NOT_EQUAL_TO_REGEX, $value);
|
||||
}
|
||||
public static function setNotEqualToRegex( string $key, string $value ): KeyFilter {
|
||||
return self::set( $key, self::NOT_EQUAL_TO_REGEX, $value );
|
||||
}
|
||||
|
||||
public function and(string $key, string $operator, $value): KeyFilter
|
||||
{
|
||||
$this->checkOperator($operator);
|
||||
$this->expressions[] = 'and r.' . $key . ' ' . $operator . ' ' . new Type($value);
|
||||
return $this;
|
||||
}
|
||||
public function and( string $key, string $operator, $value ): KeyFilter {
|
||||
$this->checkOperator( $operator );
|
||||
$this->expressions[] = 'and r.' . $key . ' ' . $operator . ' ' . new Type( $value );
|
||||
|
||||
public function andEqualTo(string $key, string $value): KeyFilter
|
||||
{
|
||||
$this->and($key, self::EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function andNotEqualTo(string $key, string $value): KeyFilter
|
||||
{
|
||||
$this->and($key, self::NOT_EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
public function andEqualTo( string $key, string $value ): KeyFilter {
|
||||
$this->and( $key, self::EQUAL_TO, $value );
|
||||
|
||||
public function andGreaterThan(string $key, int $value): KeyFilter
|
||||
{
|
||||
$this->and($key, self::GREATER_THAN, $value);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function andGreaterOrEqualTo(string $key, int $value): KeyFilter
|
||||
{
|
||||
$this->and($key, self::GREATER_EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
public function andNotEqualTo( string $key, string $value ): KeyFilter {
|
||||
$this->and( $key, self::NOT_EQUAL_TO, $value );
|
||||
|
||||
public function andLessThan(string $key, int $value): KeyFilter
|
||||
{
|
||||
$this->and($key, self::LESS_THAN, $value);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function andLessOrEqualTo(string $key, int $value): KeyFilter
|
||||
{
|
||||
$this->and($key, self::LESS_EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
public function andGreaterThan( string $key, int $value ): KeyFilter {
|
||||
$this->and( $key, self::GREATER_THAN, $value );
|
||||
|
||||
public function andEqualToRegex(string $key, string $value): KeyFilter
|
||||
{
|
||||
$this->and($key, self::EQUAL_TO_REGEX, $value);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function andNotEqualToRegex(string $key, string $value): KeyFilter
|
||||
{
|
||||
$this->and($key, self::NOT_EQUAL_TO_REGEX, $value);
|
||||
return $this;
|
||||
}
|
||||
public function andGreaterOrEqualTo( string $key, int $value ): KeyFilter {
|
||||
$this->and( $key, self::GREATER_EQUAL_TO, $value );
|
||||
|
||||
public function or(string $key, string $operator, $value): KeyFilter
|
||||
{
|
||||
$this->checkOperator($operator);
|
||||
$this->expressions[] = 'or r.' . $key . ' ' . $operator . ' ' . new Type($value);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orEqualTo(string $key, string $value): KeyFilter
|
||||
{
|
||||
$this->or($key, self::EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
public function andLessThan( string $key, int $value ): KeyFilter {
|
||||
$this->and( $key, self::LESS_THAN, $value );
|
||||
|
||||
public function orNotEqualTo(string $key, string $value): KeyFilter
|
||||
{
|
||||
$this->or($key, self::NOT_EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orGreaterThan(string $key, int $value): KeyFilter
|
||||
{
|
||||
$this->or($key, self::GREATER_THAN, $value);
|
||||
return $this;
|
||||
}
|
||||
public function andLessOrEqualTo( string $key, int $value ): KeyFilter {
|
||||
$this->and( $key, self::LESS_EQUAL_TO, $value );
|
||||
|
||||
public function orGreaterOrEqualTo(string $key, int $value): KeyFilter
|
||||
{
|
||||
$this->or($key, self::GREATER_EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orLessThan(string $key, int $value): KeyFilter
|
||||
{
|
||||
$this->or($key, self::LESS_THAN, $value);
|
||||
return $this;
|
||||
}
|
||||
public function andEqualToRegex( string $key, string $value ): KeyFilter {
|
||||
$this->and( $key, self::EQUAL_TO_REGEX, $value );
|
||||
|
||||
public function orLessOrEqualTo(string $key, int $value): KeyFilter
|
||||
{
|
||||
$this->or($key, self::LESS_EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orEqualToRegex(string $key, string $value): KeyFilter
|
||||
{
|
||||
$this->or($key, self::EQUAL_TO_REGEX, $value);
|
||||
return $this;
|
||||
}
|
||||
public function andNotEqualToRegex( string $key, string $value ): KeyFilter {
|
||||
$this->and( $key, self::NOT_EQUAL_TO_REGEX, $value );
|
||||
|
||||
public function orNotEqualToRegex(string $key, string $value): KeyFilter
|
||||
{
|
||||
$this->or($key, self::NOT_EQUAL_TO_REGEX, $value);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return implode(' ', $this->expressions);
|
||||
}
|
||||
public function or( string $key, string $operator, $value ): KeyFilter {
|
||||
$this->checkOperator( $operator );
|
||||
$this->expressions[] = 'or r.' . $key . ' ' . $operator . ' ' . new Type( $value );
|
||||
|
||||
protected function checkOperator(string $operator)
|
||||
{
|
||||
if (!in_array($operator, self::COMPARISON_OPERATORS)) {
|
||||
throw new Exception('Operator "' . $operator . '" is not supported!');
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orEqualTo( string $key, string $value ): KeyFilter {
|
||||
$this->or( $key, self::EQUAL_TO, $value );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orNotEqualTo( string $key, string $value ): KeyFilter {
|
||||
$this->or( $key, self::NOT_EQUAL_TO, $value );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orGreaterThan( string $key, int $value ): KeyFilter {
|
||||
$this->or( $key, self::GREATER_THAN, $value );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orGreaterOrEqualTo( string $key, int $value ): KeyFilter {
|
||||
$this->or( $key, self::GREATER_EQUAL_TO, $value );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orLessThan( string $key, int $value ): KeyFilter {
|
||||
$this->or( $key, self::LESS_THAN, $value );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orLessOrEqualTo( string $key, int $value ): KeyFilter {
|
||||
$this->or( $key, self::LESS_EQUAL_TO, $value );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orEqualToRegex( string $key, string $value ): KeyFilter {
|
||||
$this->or( $key, self::EQUAL_TO_REGEX, $value );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orNotEqualToRegex( string $key, string $value ): KeyFilter {
|
||||
$this->or( $key, self::NOT_EQUAL_TO_REGEX, $value );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return implode( ' ', $this->expressions );
|
||||
}
|
||||
|
||||
protected function checkOperator( string $operator ) {
|
||||
if ( ! in_array( $operator, self::COMPARISON_OPERATORS ) ) {
|
||||
throw new Exception( 'Operator "' . $operator . '" is not supported!' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,210 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
class KeyValue extends Base
|
||||
{
|
||||
public const EQUAL_TO = '==';
|
||||
public const NOT_EQUAL_TO = '!=';
|
||||
public const GREATER_THAN = '>';
|
||||
public const GREATER_EQUAL_TO = '>=';
|
||||
public const LESS_THAN = '<';
|
||||
public const LESS_EQUAL_TO = '<=';
|
||||
public const EQUAL_TO_REGEX = '=~';
|
||||
public const NOT_EQUAL_TO_REGEX = '!~';
|
||||
|
||||
public const COMPARISON_OPERATORS = [
|
||||
self::EQUAL_TO,
|
||||
self::NOT_EQUAL_TO,
|
||||
self::GREATER_THAN,
|
||||
self::GREATER_EQUAL_TO,
|
||||
self::LESS_THAN,
|
||||
self::LESS_EQUAL_TO,
|
||||
self::EQUAL_TO_REGEX,
|
||||
self::NOT_EQUAL_TO_REGEX,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array $expressions
|
||||
*/
|
||||
private $expressions;
|
||||
|
||||
private function __construct(string $key, string $operator, $value)
|
||||
{
|
||||
$this->checkOperator($operator);
|
||||
$this->expressions[] = 'r.' . $key . ' ' . $operator . ' ' . new Type($value);
|
||||
}
|
||||
|
||||
public static function set(string $key, string $operator, $value): KeyValue
|
||||
{
|
||||
return new self($key, $operator, $value);
|
||||
}
|
||||
|
||||
public static function setEqualTo(string $key, string $value): KeyValue
|
||||
{
|
||||
return self::set($key, self::EQUAL_TO, $value);
|
||||
}
|
||||
|
||||
public static function setNotEqualTo(string $key, string $value): KeyValue
|
||||
{
|
||||
return self::set($key, self::NOT_EQUAL_TO, $value);
|
||||
}
|
||||
|
||||
public static function setGreaterThan(string $key, int $value): KeyValue
|
||||
{
|
||||
return self::set($key, self::GREATER_THAN, $value);
|
||||
}
|
||||
|
||||
public static function setGreaterOrEqualTo(string $key, int $value): KeyValue
|
||||
{
|
||||
return self::set($key, self::GREATER_EQUAL_TO, $value);
|
||||
}
|
||||
|
||||
public static function setLessThan(string $key, int $value): KeyValue
|
||||
{
|
||||
return self::set($key, self::LESS_THAN, $value);
|
||||
}
|
||||
|
||||
public static function setLessOrEqualTo(string $key, int $value): KeyValue
|
||||
{
|
||||
return self::set($key, self::LESS_EQUAL_TO, $value);
|
||||
}
|
||||
|
||||
public static function setEqualToRegex(string $key, string $value): KeyValue
|
||||
{
|
||||
return self::set($key, self::EQUAL_TO_REGEX, $value);
|
||||
}
|
||||
|
||||
public static function setNotEqualToRegex(string $key, string $value): KeyValue
|
||||
{
|
||||
return self::set($key, self::NOT_EQUAL_TO_REGEX, $value);
|
||||
}
|
||||
|
||||
public function and(string $key, string $operator, $value): KeyValue
|
||||
{
|
||||
$this->checkOperator($operator);
|
||||
$this->expressions[] = 'and r.' . $key . ' ' . $operator . ' ' . new Type($value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function andEqualTo(string $key, string $value): KeyValue
|
||||
{
|
||||
$this->and($key, self::EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function andNotEqualTo(string $key, string $value): KeyValue
|
||||
{
|
||||
$this->and($key, self::NOT_EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function andGreaterThan(string $key, int $value): KeyValue
|
||||
{
|
||||
$this->and($key, self::GREATER_THAN, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function andGreaterOrEqualTo(string $key, int $value): KeyValue
|
||||
{
|
||||
$this->and($key, self::GREATER_EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function andLessThan(string $key, int $value): KeyValue
|
||||
{
|
||||
$this->and($key, self::LESS_THAN, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function andLessOrEqualTo(string $key, int $value): KeyValue
|
||||
{
|
||||
$this->and($key, self::LESS_EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function andEqualToRegex(string $key, string $value): KeyValue
|
||||
{
|
||||
$this->and($key, self::EQUAL_TO_REGEX, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function andNotEqualToRegex(string $key, string $value): KeyValue
|
||||
{
|
||||
$this->and($key, self::NOT_EQUAL_TO_REGEX, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function or(string $key, string $operator, $value): KeyValue
|
||||
{
|
||||
$this->checkOperator($operator);
|
||||
$this->expressions[] = 'or r.' . $key . ' ' . $operator . ' ' . new Type($value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orEqualTo(string $key, string $value): KeyValue
|
||||
{
|
||||
$this->or($key, self::EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orNotEqualTo(string $key, string $value): KeyValue
|
||||
{
|
||||
$this->or($key, self::NOT_EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orGreaterThan(string $key, int $value): KeyValue
|
||||
{
|
||||
$this->or($key, self::GREATER_THAN, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orGreaterOrEqualTo(string $key, int $value): KeyValue
|
||||
{
|
||||
$this->or($key, self::GREATER_EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orLessThan(string $key, int $value): KeyValue
|
||||
{
|
||||
$this->or($key, self::LESS_THAN, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orLessOrEqualTo(string $key, int $value): KeyValue
|
||||
{
|
||||
$this->or($key, self::LESS_EQUAL_TO, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orEqualToRegex(string $key, string $value): KeyValue
|
||||
{
|
||||
$this->or($key, self::EQUAL_TO_REGEX, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function orNotEqualToRegex(string $key, string $value): KeyValue
|
||||
{
|
||||
$this->or($key, self::NOT_EQUAL_TO_REGEX, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return implode(' ', $this->expressions);
|
||||
}
|
||||
|
||||
protected function checkOperator(string $operator)
|
||||
{
|
||||
if (!in_array($operator, self::COMPARISON_OPERATORS)) {
|
||||
throw new Exception('Operator "' . $operator . '" is not supported!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
||||
namespace Hosterra\FluxBuilder\Expression;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type\FieldRecordType;
|
||||
use Hosterra\FluxBuilder\Type\FieldRecordType;
|
||||
|
||||
class Map extends Base
|
||||
{
|
||||
private static $string;
|
||||
class Map extends Base {
|
||||
private static $string;
|
||||
|
||||
public static function with(string $name, string $content): Map
|
||||
{
|
||||
$object = new self();
|
||||
$object::$string = 'r with ' . $name . ': ' . $content;
|
||||
return $object;
|
||||
}
|
||||
public static function with( string $name, string $content ): Map {
|
||||
$object = new self();
|
||||
$object::$string = 'r with ' . $name . ': ' . $content;
|
||||
|
||||
public static function columns(array $columns)
|
||||
{
|
||||
$object = new self();
|
||||
$object::$string = new FieldRecordType($columns);
|
||||
return $object;
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return self::$string;
|
||||
}
|
||||
public static function columns( array $columns ) {
|
||||
$object = new self();
|
||||
$object::$string = new FieldRecordType( $columns );
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return self::$string;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
||||
namespace Hosterra\FluxBuilder\Expression;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class Selection extends Base
|
||||
{
|
||||
private $string;
|
||||
class Selection extends Base {
|
||||
private $string;
|
||||
|
||||
private function __construct(string $string)
|
||||
{
|
||||
$this->string = $string;
|
||||
}
|
||||
private function __construct( string $string ) {
|
||||
$this->string = $string;
|
||||
}
|
||||
|
||||
public static function if(string $value): Selection
|
||||
{
|
||||
return new self('if ' . $value);
|
||||
}
|
||||
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 then( $then ): Selection {
|
||||
$this->string .= ' then ' . new Type( $then );
|
||||
|
||||
public function else($else): Selection
|
||||
{
|
||||
$this->string .= ' else ' . new Type($else);
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->string;
|
||||
}
|
||||
public function else( $else ): Selection {
|
||||
$this->string .= ' else ' . new Type( $else );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return $this->string;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,51 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
||||
use Arendsen\FluxQueryBuilder\Type\CustomType;
|
||||
use Arendsen\FluxQueryBuilder\Type\DurationType;
|
||||
use Arendsen\FluxQueryBuilder\Type\FnType;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type\ArrayType;
|
||||
use Hosterra\FluxBuilder\Type\CustomType;
|
||||
use Hosterra\FluxBuilder\Type\DurationType;
|
||||
use Hosterra\FluxBuilder\Type\FnType;
|
||||
|
||||
class AggregateWindow extends Base
|
||||
{
|
||||
/**
|
||||
* @var string $every
|
||||
*/
|
||||
private $every;
|
||||
class AggregateWindow extends Base {
|
||||
/**
|
||||
* @var string $every
|
||||
*/
|
||||
private $every;
|
||||
|
||||
/**
|
||||
* @var string $fn
|
||||
*/
|
||||
private $fn;
|
||||
/**
|
||||
* @var string $fn
|
||||
*/
|
||||
private $fn;
|
||||
|
||||
/**
|
||||
* @var array $options
|
||||
*/
|
||||
private $options;
|
||||
/**
|
||||
* @var array $options
|
||||
*/
|
||||
private $options;
|
||||
|
||||
public function __construct($every, $fn, array $options = [])
|
||||
{
|
||||
$this->every = $every;
|
||||
$this->fn = $fn;
|
||||
$this->options = $options;
|
||||
}
|
||||
public function __construct( $every, $fn, array $options = [] ) {
|
||||
$this->every = $every;
|
||||
$this->fn = $fn;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$input = new ArrayType(array_filter([
|
||||
'every' => new DurationType($this->every),
|
||||
'period' => isset($this->options['period']) ? new DurationType($this->options['period']) : null,
|
||||
'offset' => isset($this->options['offset']) ? new DurationType($this->options['offset']) : null,
|
||||
'fn' => new CustomType($this->fn),
|
||||
'location' => isset($this->options['location']) ? new Type($this->options['location']) : null,
|
||||
'column' => isset($this->options['column']) ? new Type($this->options['column']) : null,
|
||||
'timeSrc' => isset($this->options['timeSrc']) ? new Type($this->options['timeSrc']) : null,
|
||||
'timeDst' => isset($this->options['timeDst']) ? new Type($this->options['timeDst']) : null,
|
||||
'createEmpty' => isset($this->options['createEmpty']) && !$this->options['createEmpty'] ?
|
||||
new Type($this->options['createEmpty']) : null,
|
||||
]));
|
||||
return '|> aggregateWindow(' . $input . ') ';
|
||||
}
|
||||
public function __toString() {
|
||||
$input = new ArrayType( array_filter( [
|
||||
'every' => new DurationType( $this->every ),
|
||||
'period' => isset( $this->options['period'] ) ? new DurationType( $this->options['period'] ) : null,
|
||||
'offset' => isset( $this->options['offset'] ) ? new DurationType( $this->options['offset'] ) : null,
|
||||
'fn' => new CustomType( $this->fn ),
|
||||
'location' => isset( $this->options['location'] ) ? new Type( $this->options['location'] ) : null,
|
||||
'column' => isset( $this->options['column'] ) ? new Type( $this->options['column'] ) : null,
|
||||
'timeSrc' => isset( $this->options['timeSrc'] ) ? new Type( $this->options['timeSrc'] ) : null,
|
||||
'timeDst' => isset( $this->options['timeDst'] ) ? new Type( $this->options['timeDst'] ) : null,
|
||||
'createEmpty' => isset( $this->options['createEmpty'] ) && ! $this->options['createEmpty'] ?
|
||||
new Type( $this->options['createEmpty'] ) : null,
|
||||
] ) );
|
||||
|
||||
return '|> aggregateWindow(' . $input . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Exception\FunctionNotImplementedException;
|
||||
use Hosterra\FluxBuilder\Exception\FunctionNotImplementedException;
|
||||
|
||||
abstract class Base
|
||||
{
|
||||
/**
|
||||
* @throws FunctionNotImplementedException
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
throw new FunctionNotImplementedException('__toString', get_class($this));
|
||||
}
|
||||
abstract class Base {
|
||||
/**
|
||||
* @throws FunctionNotImplementedException
|
||||
*/
|
||||
public function __toString() {
|
||||
throw new FunctionNotImplementedException( '__toString', get_class( $this ) );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
||||
use Hosterra\FluxBuilder\Type\ArrayType;
|
||||
|
||||
class Bottom extends Base
|
||||
{
|
||||
/**
|
||||
* @var int $n
|
||||
*/
|
||||
private $n;
|
||||
class Bottom extends Base {
|
||||
/**
|
||||
* @var int $n
|
||||
*/
|
||||
private $n;
|
||||
|
||||
/**
|
||||
* @var array $columns
|
||||
*/
|
||||
private $columns;
|
||||
/**
|
||||
* @var array $columns
|
||||
*/
|
||||
private $columns;
|
||||
|
||||
public function __construct($n, array $columns = [])
|
||||
{
|
||||
$this->n = $n;
|
||||
$this->columns = $columns;
|
||||
}
|
||||
public function __construct( $n, array $columns = [] ) {
|
||||
$this->n = $n;
|
||||
$this->columns = $columns;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$input = new ArrayType(array_filter([
|
||||
'n' => $this->n,
|
||||
'columns' => $this->columns ?: null,
|
||||
]));
|
||||
return '|> bottom(' . $input . ') ';
|
||||
}
|
||||
public function __toString() {
|
||||
$input = new ArrayType( array_filter( [
|
||||
'n' => $this->n,
|
||||
'columns' => $this->columns ?: null,
|
||||
] ) );
|
||||
|
||||
return '|> bottom(' . $input . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class Count extends Base
|
||||
{
|
||||
/**
|
||||
* @var string|null $column
|
||||
*/
|
||||
private $column;
|
||||
class Count extends Base {
|
||||
/**
|
||||
* @var string|null $column
|
||||
*/
|
||||
private $column;
|
||||
|
||||
public function __construct(?string $column = null)
|
||||
{
|
||||
$this->column = $column;
|
||||
}
|
||||
public function __construct( ?string $column = null ) {
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$params = new Type(array_filter([
|
||||
'column' => $this->column
|
||||
]));
|
||||
public function __toString() {
|
||||
$params = new Type( array_filter( [
|
||||
'column' => $this->column
|
||||
] ) );
|
||||
|
||||
return '|> count(' . $params . ') ';
|
||||
}
|
||||
return '|> count(' . $params . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type\ArrayType;
|
||||
|
||||
class Duplicate extends Base
|
||||
{
|
||||
/**
|
||||
* @var string $column
|
||||
*/
|
||||
private $column;
|
||||
class Duplicate extends Base {
|
||||
/**
|
||||
* @var string $column
|
||||
*/
|
||||
private $column;
|
||||
|
||||
/**
|
||||
* @var string $as
|
||||
*/
|
||||
private $as;
|
||||
/**
|
||||
* @var string $as
|
||||
*/
|
||||
private $as;
|
||||
|
||||
public function __construct(string $column, string $as)
|
||||
{
|
||||
$this->column = $column;
|
||||
$this->as = $as;
|
||||
}
|
||||
public function __construct( string $column, string $as ) {
|
||||
$this->column = $column;
|
||||
$this->as = $as;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$input = new ArrayType([
|
||||
'column' => $this->column,
|
||||
'as' => $this->as
|
||||
]);
|
||||
public function __toString() {
|
||||
$input = new ArrayType( [
|
||||
'column' => $this->column,
|
||||
'as' => $this->as
|
||||
] );
|
||||
|
||||
return '|> duplicate(' . $input . ') ';
|
||||
}
|
||||
return '|> duplicate(' . $input . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,51 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Exception\FunctionInvalidInputException;
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
|
||||
use Hosterra\FluxBuilder\Exception\FunctionInvalidInputException;
|
||||
|
||||
class Filter extends Base
|
||||
{
|
||||
/**
|
||||
* @var mixed $filter
|
||||
*/
|
||||
private $filter;
|
||||
use Hosterra\FluxBuilder\Expression\KeyFilter;
|
||||
|
||||
public function __construct($filter)
|
||||
{
|
||||
$this->filter = $filter;
|
||||
}
|
||||
class Filter extends Base {
|
||||
/**
|
||||
* @var mixed $filter
|
||||
*/
|
||||
private $filter;
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> filter(fn: (r) => ' . $this->format() . ') ';
|
||||
}
|
||||
public function __construct( $filter ) {
|
||||
$this->filter = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FunctionInvalidInputException
|
||||
*/
|
||||
protected function format(): string
|
||||
{
|
||||
if ($this->filter instanceof KeyValue || $this->filter instanceof KeyFilter) {
|
||||
return $this->filter->__toString();
|
||||
} elseif (is_array($this->filter)) {
|
||||
$filterCounter = 0;
|
||||
$filterString = '';
|
||||
foreach ($this->filter as $filter) {
|
||||
if ($filterCounter > 0) {
|
||||
$filterString .= ' or ';
|
||||
}
|
||||
public function __toString() {
|
||||
return '|> filter(fn: (r) => ' . $this->format() . ') ';
|
||||
}
|
||||
|
||||
$filterString .= 'r._field == "' . $filter . '"';
|
||||
/**
|
||||
* @throws FunctionInvalidInputException
|
||||
*/
|
||||
protected function format(): string {
|
||||
if ( $this->filter instanceof KeyValue || $this->filter instanceof KeyFilter ) {
|
||||
return $this->filter->__toString();
|
||||
} elseif ( is_array( $this->filter ) ) {
|
||||
$filterCounter = 0;
|
||||
$filterString = '';
|
||||
foreach ( $this->filter as $filter ) {
|
||||
if ( $filterCounter > 0 ) {
|
||||
$filterString .= ' or ';
|
||||
}
|
||||
|
||||
$filterCounter++;
|
||||
}
|
||||
$filterString .= 'r._field == "' . $filter . '"';
|
||||
|
||||
return $filterString;
|
||||
}
|
||||
$filterCounter ++;
|
||||
}
|
||||
|
||||
throw new FunctionInvalidInputException('Filter input is incorrect.');
|
||||
}
|
||||
return $filterString;
|
||||
}
|
||||
|
||||
throw new FunctionInvalidInputException( 'Filter input is incorrect.' );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class First extends Base
|
||||
{
|
||||
/**
|
||||
* @var string|null $column
|
||||
*/
|
||||
private $column;
|
||||
class First extends Base {
|
||||
/**
|
||||
* @var string|null $column
|
||||
*/
|
||||
private $column;
|
||||
|
||||
public function __construct(?string $column = null)
|
||||
{
|
||||
$this->column = $column;
|
||||
}
|
||||
public function __construct( ?string $column = null ) {
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$params = new Type(array_filter([
|
||||
'column' => $this->column
|
||||
]));
|
||||
public function __toString() {
|
||||
$params = new Type( array_filter( [
|
||||
'column' => $this->column
|
||||
] ) );
|
||||
|
||||
return '|> first(' . $params . ') ';
|
||||
}
|
||||
return '|> first(' . $params . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class From extends Base
|
||||
{
|
||||
/**
|
||||
* @var array $settings
|
||||
*/
|
||||
private $settings;
|
||||
class From extends Base {
|
||||
/**
|
||||
* @var array $settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
public function __construct(array $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
}
|
||||
public function __construct( array $settings ) {
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return 'from(' . new Type($this->settings) . ') ';
|
||||
}
|
||||
public function __toString() {
|
||||
return 'from(' . new Type( $this->settings ) . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class Group extends Base
|
||||
{
|
||||
/**
|
||||
* @var array $columns
|
||||
*/
|
||||
private $columns;
|
||||
class Group extends Base {
|
||||
/**
|
||||
* @var array $columns
|
||||
*/
|
||||
private $columns;
|
||||
|
||||
/**
|
||||
* @var string $mode
|
||||
*/
|
||||
private $mode;
|
||||
/**
|
||||
* @var string $mode
|
||||
*/
|
||||
private $mode;
|
||||
|
||||
public function __construct(array $columns, string $mode = 'by')
|
||||
{
|
||||
$this->columns = $columns;
|
||||
$this->mode = $mode;
|
||||
}
|
||||
public function __construct( array $columns, string $mode = 'by' ) {
|
||||
$this->columns = $columns;
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$array = new Type([
|
||||
'columns' => $this->columns,
|
||||
'mode' => $this->mode,
|
||||
]);
|
||||
public function __toString() {
|
||||
$array = new Type( [
|
||||
'columns' => $this->columns,
|
||||
'mode' => $this->mode,
|
||||
] );
|
||||
|
||||
return '|> group(' . $array . ') ';
|
||||
}
|
||||
return '|> group(' . $array . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
class Last extends Base
|
||||
{
|
||||
/**
|
||||
* @var int $column
|
||||
*/
|
||||
private $column;
|
||||
class Last extends Base {
|
||||
/**
|
||||
* @var int $column
|
||||
*/
|
||||
private $column;
|
||||
|
||||
public function __construct(string $column = '_value')
|
||||
{
|
||||
$this->column = $column;
|
||||
}
|
||||
public function __construct( string $column = '_value' ) {
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> last(column: "' . (string)$this->column . '") ';
|
||||
}
|
||||
public function __toString() {
|
||||
return '|> last(column: "' . (string) $this->column . '") ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
class Limit extends Base
|
||||
{
|
||||
/**
|
||||
* @var int $limit
|
||||
*/
|
||||
private $limit;
|
||||
class Limit extends Base {
|
||||
/**
|
||||
* @var int $limit
|
||||
*/
|
||||
private $limit;
|
||||
|
||||
/**
|
||||
* @var int $offset
|
||||
*/
|
||||
private $offset;
|
||||
/**
|
||||
* @var int $offset
|
||||
*/
|
||||
private $offset;
|
||||
|
||||
public function __construct(int $limit, int $offset = 0)
|
||||
{
|
||||
$this->limit = $limit;
|
||||
$this->offset = $offset;
|
||||
}
|
||||
public function __construct( int $limit, int $offset = 0 ) {
|
||||
$this->limit = $limit;
|
||||
$this->offset = $offset;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> limit(n: ' . (string)$this->limit . ', offset: ' . (string)$this->offset . ') ';
|
||||
}
|
||||
public function __toString() {
|
||||
return '|> limit(n: ' . (string) $this->limit . ', offset: ' . (string) $this->offset . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Expression\Map as MapExpression;
|
||||
use Hosterra\FluxBuilder\Expression\Map as MapExpression;
|
||||
|
||||
class Map extends Base
|
||||
{
|
||||
/**
|
||||
* @var mixed $query
|
||||
*/
|
||||
private $query;
|
||||
class Map extends Base {
|
||||
/**
|
||||
* @var mixed $query
|
||||
*/
|
||||
private $query;
|
||||
|
||||
public function __construct($query)
|
||||
{
|
||||
$this->query = $query;
|
||||
}
|
||||
public function __construct( $query ) {
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> map(fn: (r) => ({ ' . $this->query . ' })) ';
|
||||
}
|
||||
public function __toString() {
|
||||
return '|> map(fn: (r) => ({ ' . $this->query . ' })) ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class Max extends Base
|
||||
{
|
||||
/**
|
||||
* @var string|null $column
|
||||
*/
|
||||
private $column;
|
||||
class Max extends Base {
|
||||
/**
|
||||
* @var string|null $column
|
||||
*/
|
||||
private $column;
|
||||
|
||||
public function __construct(?string $column = null)
|
||||
{
|
||||
$this->column = $column;
|
||||
}
|
||||
public function __construct( ?string $column = null ) {
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$params = new Type(array_filter([
|
||||
'column' => $this->column
|
||||
]));
|
||||
public function __toString() {
|
||||
$params = new Type( array_filter( [
|
||||
'column' => $this->column
|
||||
] ) );
|
||||
|
||||
return '|> max(' . $params . ') ';
|
||||
}
|
||||
return '|> max(' . $params . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type\ArrayType;
|
||||
|
||||
class Mean extends Base
|
||||
{
|
||||
/**
|
||||
* @var string $column
|
||||
*/
|
||||
private $column;
|
||||
class Mean extends Base {
|
||||
/**
|
||||
* @var string $column
|
||||
*/
|
||||
private $column;
|
||||
|
||||
public function __construct(string $column = '_value')
|
||||
{
|
||||
$this->column = $column;
|
||||
}
|
||||
public function __construct( string $column = '_value' ) {
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$input = new ArrayType(array_filter([
|
||||
'column' => !empty($this->column) && $this->column !== '_value' ?
|
||||
new Type($this->column) : null
|
||||
]));
|
||||
public function __toString() {
|
||||
$input = new ArrayType( array_filter( [
|
||||
'column' => ! empty( $this->column ) && $this->column !== '_value' ?
|
||||
new Type( $this->column ) : null
|
||||
] ) );
|
||||
|
||||
return '|> mean(' . $input . ') ';
|
||||
}
|
||||
return '|> mean(' . $input . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
class Measurement extends Base
|
||||
{
|
||||
/**
|
||||
* @var string $measurement
|
||||
*/
|
||||
private $measurement;
|
||||
class Measurement extends Base {
|
||||
/**
|
||||
* @var string $measurement
|
||||
*/
|
||||
private $measurement;
|
||||
|
||||
public function __construct(string $measurement)
|
||||
{
|
||||
$this->measurement = $measurement;
|
||||
}
|
||||
public function __construct( string $measurement ) {
|
||||
$this->measurement = $measurement;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> filter(fn: (r) => r._measurement == "' . (string)$this->measurement . '") ';
|
||||
}
|
||||
public function __toString() {
|
||||
return '|> filter(fn: (r) => r._measurement == "' . (string) $this->measurement . '") ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class Min extends Base
|
||||
{
|
||||
/**
|
||||
* @var string|null $column
|
||||
*/
|
||||
private $column;
|
||||
class Min extends Base {
|
||||
/**
|
||||
* @var string|null $column
|
||||
*/
|
||||
private $column;
|
||||
|
||||
public function __construct(?string $column = null)
|
||||
{
|
||||
$this->column = $column;
|
||||
}
|
||||
public function __construct( ?string $column = null ) {
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$params = new Type(array_filter([
|
||||
'column' => $this->column
|
||||
]));
|
||||
public function __toString() {
|
||||
$params = new Type( array_filter( [
|
||||
'column' => $this->column
|
||||
] ) );
|
||||
|
||||
return '|> min(' . $params . ') ';
|
||||
}
|
||||
return '|> min(' . $params . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Exception\FunctionRequiredSettingMissingException;
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Exception\FunctionRequiredSettingMissingException;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
use DateTime;
|
||||
|
||||
class Range extends Base
|
||||
{
|
||||
/**
|
||||
* @var mixed $start
|
||||
*/
|
||||
private $start;
|
||||
class Range extends Base {
|
||||
/**
|
||||
* @var mixed $start
|
||||
*/
|
||||
private $start;
|
||||
|
||||
/**
|
||||
* @var mixed $stop
|
||||
*/
|
||||
private $stop;
|
||||
/**
|
||||
* @var mixed $stop
|
||||
*/
|
||||
private $stop;
|
||||
|
||||
public function __construct(DateTime $start, ?DateTime $stop = null)
|
||||
{
|
||||
$this->start = new Type($start);
|
||||
$this->stop = $stop ? new Type($stop) : null;
|
||||
}
|
||||
public function __construct( DateTime $start, ?DateTime $stop = null ) {
|
||||
$this->start = new Type( $start );
|
||||
$this->stop = $stop ? new Type( $stop ) : null;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if (!$this->start) {
|
||||
throw new FunctionRequiredSettingMissingException('Range', 'Start setting is required!');
|
||||
}
|
||||
public function __toString() {
|
||||
if ( ! $this->start ) {
|
||||
throw new FunctionRequiredSettingMissingException( 'Range', 'Start setting is required!' );
|
||||
}
|
||||
|
||||
$settingsString = 'start: ' . $this->start;
|
||||
if ($this->stop) {
|
||||
$settingsString .= ', stop: ' . $this->stop;
|
||||
}
|
||||
$settingsString = 'start: ' . $this->start;
|
||||
if ( $this->stop ) {
|
||||
$settingsString .= ', stop: ' . $this->stop;
|
||||
}
|
||||
|
||||
return '|> range(' . $settingsString . ') ';
|
||||
}
|
||||
return '|> range(' . $settingsString . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
class RawFunction extends Base
|
||||
{
|
||||
/**
|
||||
* @var string $input
|
||||
*/
|
||||
private $input;
|
||||
class RawFunction extends Base {
|
||||
/**
|
||||
* @var string $input
|
||||
*/
|
||||
private $input;
|
||||
|
||||
public function __construct(string $input)
|
||||
{
|
||||
$this->input = $input;
|
||||
}
|
||||
public function __construct( string $input ) {
|
||||
$this->input = $input;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->input . ' ';
|
||||
}
|
||||
public function __toString() {
|
||||
return $this->input . ' ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type\RecordType;
|
||||
use Hosterra\FluxBuilder\Type\RecordType;
|
||||
|
||||
class Reduce extends Base
|
||||
{
|
||||
/**
|
||||
* @var array $settings
|
||||
*/
|
||||
private $settings;
|
||||
class Reduce extends Base {
|
||||
/**
|
||||
* @var array $settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* @var array $identity
|
||||
*/
|
||||
private $identity;
|
||||
/**
|
||||
* @var array $identity
|
||||
*/
|
||||
private $identity;
|
||||
|
||||
public function __construct(array $settings, array $identity)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
$this->identity = $identity;
|
||||
}
|
||||
public function __construct( array $settings, array $identity ) {
|
||||
$this->settings = $settings;
|
||||
$this->identity = $identity;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> reduce(fn: (r, accumulator) => (' . new RecordType($this->settings) . '), ' .
|
||||
'identity: ' . new RecordType($this->identity) . ') ';
|
||||
}
|
||||
public function __toString() {
|
||||
return '|> reduce(fn: (r, accumulator) => (' . new RecordType( $this->settings ) . '), ' .
|
||||
'identity: ' . new RecordType( $this->identity ) . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class Sort extends Base
|
||||
{
|
||||
/**
|
||||
* @var array $columns
|
||||
*/
|
||||
private $columns;
|
||||
class Sort extends Base {
|
||||
/**
|
||||
* @var array $columns
|
||||
*/
|
||||
private $columns;
|
||||
|
||||
/**
|
||||
* @var bool $desc
|
||||
*/
|
||||
private $desc;
|
||||
/**
|
||||
* @var bool $desc
|
||||
*/
|
||||
private $desc;
|
||||
|
||||
public function __construct(array $columns = ['_value'], bool $desc = false)
|
||||
{
|
||||
$this->columns = $columns;
|
||||
$this->desc = $desc;
|
||||
}
|
||||
public function __construct( array $columns = [ '_value' ], bool $desc = false ) {
|
||||
$this->columns = $columns;
|
||||
$this->desc = $desc;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> sort(columns: [' . new Type($this->columns) .
|
||||
'], desc: ' . new Type($this->desc) . ') ';
|
||||
}
|
||||
public function __toString() {
|
||||
return '|> sort(columns: [' . new Type( $this->columns ) .
|
||||
'], desc: ' . new Type( $this->desc ) . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
class Sum extends Base
|
||||
{
|
||||
/**
|
||||
* @var string $column
|
||||
*/
|
||||
private $column;
|
||||
class Sum extends Base {
|
||||
/**
|
||||
* @var string $column
|
||||
*/
|
||||
private $column;
|
||||
|
||||
public function __construct(string $column)
|
||||
{
|
||||
$this->column = $column;
|
||||
}
|
||||
public function __construct( string $column ) {
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> sum(column: "' . (string)$this->column . '") ';
|
||||
}
|
||||
public function __toString() {
|
||||
return '|> sum(column: "' . (string) $this->column . '") ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class Unique extends Base
|
||||
{
|
||||
/**
|
||||
* @var string|null $column
|
||||
*/
|
||||
private $column;
|
||||
class Unique extends Base {
|
||||
/**
|
||||
* @var string|null $column
|
||||
*/
|
||||
private $column;
|
||||
|
||||
public function __construct(?string $column = null)
|
||||
{
|
||||
$this->column = $column;
|
||||
}
|
||||
public function __construct( ?string $column = null ) {
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$params = new Type(array_filter([
|
||||
'column' => $this->column
|
||||
]));
|
||||
public function __toString() {
|
||||
$params = new Type( array_filter( [
|
||||
'column' => $this->column
|
||||
] ) );
|
||||
|
||||
return '|> unique(' . $params . ') ';
|
||||
}
|
||||
return '|> unique(' . $params . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,42 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
namespace Hosterra\FluxBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
||||
use Arendsen\FluxQueryBuilder\Type\DurationType;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type\ArrayType;
|
||||
use Hosterra\FluxBuilder\Type\DurationType;
|
||||
|
||||
class Window extends Base
|
||||
{
|
||||
/**
|
||||
* @var string $every
|
||||
*/
|
||||
private $every;
|
||||
class Window extends Base {
|
||||
/**
|
||||
* @var string $every
|
||||
*/
|
||||
private $every;
|
||||
|
||||
/**
|
||||
* @var array $options
|
||||
*/
|
||||
private $options;
|
||||
/**
|
||||
* @var array $options
|
||||
*/
|
||||
private $options;
|
||||
|
||||
public function __construct($every, array $options = [])
|
||||
{
|
||||
$this->every = $every;
|
||||
$this->options = $options;
|
||||
}
|
||||
public function __construct( $every, array $options = [] ) {
|
||||
$this->every = $every;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$input = new ArrayType(array_filter([
|
||||
'every' => new DurationType($this->every),
|
||||
'period' => isset($this->options['period']) ? new DurationType($this->options['period']) : null,
|
||||
'offset' => isset($this->options['offset']) ? new DurationType($this->options['offset']) : null,
|
||||
'location' => isset($this->options['location']) ? new Type($this->options['location']) : null,
|
||||
'timeColumn' => isset($this->options['timeColumn']) ? new Type($this->options['timeColumn']) : null,
|
||||
'startColumn' => isset($this->options['startColumn']) ? new Type($this->options['startColumn']) : null,
|
||||
'stopColumn' => isset($this->options['stopColumn']) ? new Type($this->options['stopColumn']) : null,
|
||||
'createEmpty' => isset($this->options['createEmpty']) && $this->options['createEmpty'] ?
|
||||
new Type($this->options['createEmpty']) : null,
|
||||
]));
|
||||
return '|> window(' . $input . ') ';
|
||||
}
|
||||
public function __toString() {
|
||||
$input = new ArrayType( array_filter( [
|
||||
'every' => new DurationType( $this->every ),
|
||||
'period' => isset( $this->options['period'] ) ? new DurationType( $this->options['period'] ) : null,
|
||||
'offset' => isset( $this->options['offset'] ) ? new DurationType( $this->options['offset'] ) : null,
|
||||
'location' => isset( $this->options['location'] ) ? new Type( $this->options['location'] ) : null,
|
||||
'timeColumn' => isset( $this->options['timeColumn'] ) ? new Type( $this->options['timeColumn'] ) : null,
|
||||
'startColumn' => isset( $this->options['startColumn'] ) ? new Type( $this->options['startColumn'] ) : null,
|
||||
'stopColumn' => isset( $this->options['stopColumn'] ) ? new Type( $this->options['stopColumn'] ) : null,
|
||||
'createEmpty' => isset( $this->options['createEmpty'] ) && $this->options['createEmpty'] ?
|
||||
new Type( $this->options['createEmpty'] ) : null,
|
||||
] ) );
|
||||
|
||||
return '|> window(' . $input . ') ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,64 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder;
|
||||
namespace Hosterra\FluxBuilder;
|
||||
|
||||
use Exception;
|
||||
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
|
||||
use Arendsen\FluxQueryBuilder\Builder\Basics;
|
||||
use Arendsen\FluxQueryBuilder\Builder\Universe;
|
||||
use Hosterra\FluxBuilder\Builder\QueryBuilderInterface;
|
||||
use Hosterra\FluxBuilder\Builder\Basics;
|
||||
use Hosterra\FluxBuilder\Builder\Universe;
|
||||
|
||||
class QueryBuilder implements QueryBuilderInterface
|
||||
{
|
||||
use Basics;
|
||||
use Universe;
|
||||
class QueryBuilder implements QueryBuilderInterface {
|
||||
|
||||
/**
|
||||
* @var array $requiredFluxQueryParts
|
||||
*/
|
||||
private $requiredFluxQueryParts = [];
|
||||
const VERSION = '2.0.0';
|
||||
use Basics;
|
||||
use Universe;
|
||||
|
||||
/**
|
||||
* @var array $fluxQueryParts
|
||||
*/
|
||||
private $fluxQueryParts = [];
|
||||
/**
|
||||
* @var array $requiredFluxQueryParts
|
||||
*/
|
||||
private $requiredFluxQueryParts = [];
|
||||
|
||||
/**
|
||||
* @var array $requiredData
|
||||
*/
|
||||
private $requiredData = [];
|
||||
/**
|
||||
* @var array $fluxQueryParts
|
||||
*/
|
||||
private $fluxQueryParts = [];
|
||||
|
||||
protected function addToQuery($query)
|
||||
{
|
||||
$this->fluxQueryParts[] = $query;
|
||||
/**
|
||||
* @var array $requiredData
|
||||
*/
|
||||
private $requiredData = [];
|
||||
|
||||
foreach ($this->requiredFluxQueryParts as $input) {
|
||||
if ($query instanceof $input) {
|
||||
$this->requiredData[] = $query;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected function addToQuery( $query ) {
|
||||
$this->fluxQueryParts[] = $query;
|
||||
|
||||
public function build(): string
|
||||
{
|
||||
$this->checkRequired();
|
||||
foreach ( $this->requiredFluxQueryParts as $input ) {
|
||||
if ( $query instanceof $input ) {
|
||||
$this->requiredData[] = $query;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$query = '';
|
||||
public function build(): string {
|
||||
$this->checkRequired();
|
||||
|
||||
foreach ($this->fluxQueryParts as $part) {
|
||||
$query .= $part;
|
||||
}
|
||||
$query = '';
|
||||
|
||||
return $query;
|
||||
}
|
||||
foreach ( $this->fluxQueryParts as $part ) {
|
||||
$query .= $part;
|
||||
}
|
||||
|
||||
protected function checkRequired()
|
||||
{
|
||||
foreach ($this->requiredFluxQueryParts as $key => $input) {
|
||||
if (isset($this->requiredData[$key]) && !$this->requiredData[$key] instanceof $input) {
|
||||
throw new Exception('You need to put the "' . $input . '" part of the query in the correct order!');
|
||||
} elseif (!isset($this->requiredData[$key])) {
|
||||
throw new Exception('You need to define the "' . $input . '" part of the query!');
|
||||
}
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function checkRequired() {
|
||||
foreach ( $this->requiredFluxQueryParts as $key => $input ) {
|
||||
if ( isset( $this->requiredData[ $key ] ) && ! $this->requiredData[ $key ] instanceof $input ) {
|
||||
throw new Exception( 'You need to put the "' . $input . '" part of the query in the correct order!' );
|
||||
} elseif ( ! isset( $this->requiredData[ $key ] ) ) {
|
||||
throw new Exception( 'You need to define the "' . $input . '" part of the query!' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder;
|
||||
namespace Hosterra\FluxBuilder;
|
||||
|
||||
class Settings
|
||||
{
|
||||
/**
|
||||
* @var array $settings
|
||||
*/
|
||||
protected $settings;
|
||||
class Settings {
|
||||
/**
|
||||
* @var array $settings
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
public function __construct(array $settings = [])
|
||||
{
|
||||
$this->settings = $settings;
|
||||
}
|
||||
public function __construct( array $settings = [] ) {
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
public static function set(array $settings = [])
|
||||
{
|
||||
return new self($settings);
|
||||
}
|
||||
public static function set( array $settings = [] ) {
|
||||
return new self( $settings );
|
||||
}
|
||||
|
||||
public function get(string $key)
|
||||
{
|
||||
return isset($this->settings[$key]) ? $this->settings[$key] : null;
|
||||
}
|
||||
public function get( string $key ) {
|
||||
return isset( $this->settings[ $key ] ) ? $this->settings[ $key ] : null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
68
src/Type.php
68
src/Type.php
|
|
@ -1,43 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder;
|
||||
namespace Hosterra\FluxBuilder;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type\TypeInterface;
|
||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
||||
use Arendsen\FluxQueryBuilder\Type\BooleanType;
|
||||
use Arendsen\FluxQueryBuilder\Type\TimeType;
|
||||
use Hosterra\FluxBuilder\Type\TypeInterface;
|
||||
use Hosterra\FluxBuilder\Type\ArrayType;
|
||||
use Hosterra\FluxBuilder\Type\BooleanType;
|
||||
use Hosterra\FluxBuilder\Type\TimeType;
|
||||
use DateTime;
|
||||
|
||||
class Type
|
||||
{
|
||||
/**
|
||||
* @var mixed $value
|
||||
*/
|
||||
protected $value;
|
||||
class Type {
|
||||
/**
|
||||
* @var mixed $value
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
public function __construct( $value ) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
switch (gettype($this->value)) {
|
||||
case 'object':
|
||||
if ($this->value instanceof DateTime) {
|
||||
return new TimeType($this->value);
|
||||
}
|
||||
return $this->value->__toString();
|
||||
case 'string':
|
||||
return '"' . $this->value . '"';
|
||||
case 'boolean':
|
||||
return new BooleanType($this->value);
|
||||
case 'array':
|
||||
return new ArrayType($this->value);
|
||||
case 'NULL':
|
||||
return 'null';
|
||||
default:
|
||||
return (string)$this->value;
|
||||
}
|
||||
}
|
||||
public function __toString(): string {
|
||||
switch ( gettype( $this->value ) ) {
|
||||
case 'object':
|
||||
if ( $this->value instanceof DateTime ) {
|
||||
return new TimeType( $this->value );
|
||||
}
|
||||
|
||||
return $this->value->__toString();
|
||||
case 'string':
|
||||
return '"' . $this->value . '"';
|
||||
case 'boolean':
|
||||
return new BooleanType( $this->value );
|
||||
case 'array':
|
||||
return new ArrayType( $this->value );
|
||||
case 'NULL':
|
||||
return 'null';
|
||||
default:
|
||||
return (string) $this->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,47 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Type;
|
||||
namespace Hosterra\FluxBuilder\Type;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Settings;
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Settings;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class ArrayType implements TypeInterface
|
||||
{
|
||||
/**
|
||||
* @var array $value
|
||||
*/
|
||||
protected $value;
|
||||
class ArrayType implements TypeInterface {
|
||||
/**
|
||||
* @var array $value
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
public function __construct(array $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
public function __construct( array $value ) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
array_walk($this->value, function (&$value, $key) {
|
||||
if ($this->isAssociativeArray($key)) {
|
||||
$value = $key . ': ' . $this->getPrefix($value) . new Type($value) . $this->getSuffix($value);
|
||||
} else {
|
||||
$value = $this->getPrefix($value) . new Type($value) . $this->getSuffix($value);
|
||||
}
|
||||
});
|
||||
public function __toString(): string {
|
||||
array_walk( $this->value, function ( &$value, $key ) {
|
||||
if ( $this->isAssociativeArray( $key ) ) {
|
||||
$value = $key . ': ' . $this->getPrefix( $value ) . new Type( $value ) . $this->getSuffix( $value );
|
||||
} else {
|
||||
$value = $this->getPrefix( $value ) . new Type( $value ) . $this->getSuffix( $value );
|
||||
}
|
||||
} );
|
||||
|
||||
return implode(', ', $this->value);
|
||||
}
|
||||
return implode( ', ', $this->value );
|
||||
}
|
||||
|
||||
protected function isAssociativeArray($key): bool
|
||||
{
|
||||
return is_string($key);
|
||||
}
|
||||
protected function isAssociativeArray( $key ): bool {
|
||||
return is_string( $key );
|
||||
}
|
||||
|
||||
protected function getPrefix($value): string
|
||||
{
|
||||
return is_array($value) ? '[' : '';
|
||||
}
|
||||
protected function getPrefix( $value ): string {
|
||||
return is_array( $value ) ? '[' : '';
|
||||
}
|
||||
|
||||
protected function getSuffix($value): string
|
||||
{
|
||||
return is_array($value) ? ']' : '';
|
||||
}
|
||||
protected function getSuffix( $value ): string {
|
||||
return is_array( $value ) ? ']' : '';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Type;
|
||||
namespace Hosterra\FluxBuilder\Type;
|
||||
|
||||
class BooleanType implements TypeInterface
|
||||
{
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
class BooleanType implements TypeInterface {
|
||||
public function __construct( $value ) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->value ? 'true' : 'false';
|
||||
}
|
||||
public function __toString(): string {
|
||||
return $this->value ? 'true' : 'false';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Type;
|
||||
namespace Hosterra\FluxBuilder\Type;
|
||||
|
||||
class CustomType implements TypeInterface
|
||||
{
|
||||
public function __construct(string $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
class CustomType implements TypeInterface {
|
||||
public function __construct( string $value ) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
public function __toString(): string {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Type;
|
||||
namespace Hosterra\FluxBuilder\Type;
|
||||
|
||||
class DurationType implements TypeInterface
|
||||
{
|
||||
public function __construct(string $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
class DurationType implements TypeInterface {
|
||||
public function __construct( string $value ) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
public function __toString(): string {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Type;
|
||||
namespace Hosterra\FluxBuilder\Type;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Settings;
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Settings;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class FieldRecordType implements TypeInterface
|
||||
{
|
||||
public const SETTING_IS_RECORD = 'isRecord';
|
||||
class FieldRecordType implements TypeInterface {
|
||||
public const SETTING_IS_RECORD = 'isRecord';
|
||||
|
||||
/**
|
||||
* @var array $value
|
||||
*/
|
||||
private $value;
|
||||
/**
|
||||
* @var array $value
|
||||
*/
|
||||
private $value;
|
||||
|
||||
public function __construct(array $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
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;
|
||||
}
|
||||
});
|
||||
public function __toString(): string {
|
||||
array_walk( $this->value, function ( &$value, $key ) {
|
||||
if ( is_string( $key ) ) {
|
||||
$value = $key . ': ' . $value;
|
||||
}
|
||||
} );
|
||||
|
||||
return '{' . implode(', ', $this->value) . '}';
|
||||
}
|
||||
return '{' . implode( ', ', $this->value ) . '}';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,51 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Type;
|
||||
namespace Hosterra\FluxBuilder\Type;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class FnType implements TypeInterface
|
||||
{
|
||||
/**
|
||||
* @var array $params
|
||||
*/
|
||||
protected $params;
|
||||
class FnType implements TypeInterface {
|
||||
/**
|
||||
* @var array $params
|
||||
*/
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* @var string $content
|
||||
*/
|
||||
protected $content;
|
||||
/**
|
||||
* @var string $content
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
private function __construct(array $params)
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
private function __construct( array $params ) {
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public static function params(array $params)
|
||||
{
|
||||
return new self($params);
|
||||
}
|
||||
public static function params( array $params ) {
|
||||
return new self( $params );
|
||||
}
|
||||
|
||||
public function withBody(string $content)
|
||||
{
|
||||
$this->content = $content;
|
||||
return $this;
|
||||
}
|
||||
public function withBody( string $content ) {
|
||||
$this->content = $content;
|
||||
|
||||
public function withBlock(string $content)
|
||||
{
|
||||
$this->content = '{ ' . $content . ' }';
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
array_walk($this->params, function (&$value, $key) {
|
||||
if (is_string($key)) {
|
||||
$value = $key . ' = ' . new Type($value);
|
||||
}
|
||||
});
|
||||
public function withBlock( string $content ) {
|
||||
$this->content = '{ ' . $content . ' }';
|
||||
|
||||
return '(' . implode(', ', $this->params) . ') => ' . $this->content;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString(): string {
|
||||
array_walk( $this->params, function ( &$value, $key ) {
|
||||
if ( is_string( $key ) ) {
|
||||
$value = $key . ' = ' . new Type( $value );
|
||||
}
|
||||
} );
|
||||
|
||||
return '(' . implode( ', ', $this->params ) . ') => ' . $this->content;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Type;
|
||||
namespace Hosterra\FluxBuilder\Type;
|
||||
|
||||
class MathType implements TypeInterface
|
||||
{
|
||||
public function __construct(string $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
class MathType implements TypeInterface {
|
||||
public function __construct( string $value ) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
public function __toString(): string {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,36 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Type;
|
||||
namespace Hosterra\FluxBuilder\Type;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
|
||||
class RecordType implements TypeInterface
|
||||
{
|
||||
/**
|
||||
* @var array $value
|
||||
*/
|
||||
private $value;
|
||||
class RecordType implements TypeInterface {
|
||||
/**
|
||||
* @var array $value
|
||||
*/
|
||||
private $value;
|
||||
|
||||
public function __construct(array $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
public function __construct( array $value ) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
array_walk($this->value, function (&$value, $key) {
|
||||
if (is_array($value)) {
|
||||
$value = $this->getPrefix($key) . new RecordType($value);
|
||||
} else {
|
||||
$value = $this->getPrefix($key) . new Type($value);
|
||||
}
|
||||
});
|
||||
public function __toString(): string {
|
||||
array_walk( $this->value, function ( &$value, $key ) {
|
||||
if ( is_array( $value ) ) {
|
||||
$value = $this->getPrefix( $key ) . new RecordType( $value );
|
||||
} else {
|
||||
$value = $this->getPrefix( $key ) . new Type( $value );
|
||||
}
|
||||
} );
|
||||
|
||||
return '{' . implode(', ', $this->value) . '}';
|
||||
}
|
||||
return '{' . implode( ', ', $this->value ) . '}';
|
||||
}
|
||||
|
||||
private function getPrefix($key): string
|
||||
{
|
||||
return is_string($key) ? $key . ': ' : '';
|
||||
}
|
||||
private function getPrefix( $key ): string {
|
||||
return is_string( $key ) ? $key . ': ' : '';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Type;
|
||||
namespace Hosterra\FluxBuilder\Type;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class TimeType implements TypeInterface
|
||||
{
|
||||
public function __construct(DateTime $dateTime)
|
||||
{
|
||||
$this->dateTime = $dateTime;
|
||||
}
|
||||
class TimeType implements TypeInterface {
|
||||
public function __construct( DateTime $dateTime ) {
|
||||
$this->dateTime = $dateTime;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return 'time(v: ' . $this->dateTime->format('Y-m-d\TH:i:s\Z') . ')';
|
||||
}
|
||||
public function __toString(): string {
|
||||
return 'time(v: ' . $this->dateTime->format( 'Y-m-d\TH:i:s\Z' ) . ')';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Type;
|
||||
namespace Hosterra\FluxBuilder\Type;
|
||||
|
||||
interface TypeInterface
|
||||
{
|
||||
public function __toString(): string;
|
||||
interface TypeInterface {
|
||||
public function __toString(): string;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue