Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions DSL/Filter/HasChildFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class HasChildFilter implements BuilderInterface
{
use ParametersTrait;

const INNER_QUERY = 'query';
const INNER_FILTER = 'filter';

/**
* @var string
*/
Expand All @@ -31,15 +34,34 @@ class HasChildFilter implements BuilderInterface
*/
private $filter;

/**
* @var BuilderInterface
*/
private $query;

/**
* @param string $type
* @param BuilderInterface $filter
* @param BuilderInterface $block
* @param array $parameters
* @param string $inner
*
* @throws \InvalidArgumentException
*/
public function __construct($type, BuilderInterface $filter, array $parameters = [])
public function __construct($type, BuilderInterface $block, array $parameters = [], $inner = self::INNER_FILTER)
{
$this->type = $type;
$this->filter = $filter;

switch ($inner) {
case 'filter':
$this->filter = $block;
break;
case 'query':
$this->query = $block;
break;
default:
throw new \InvalidArgumentException('Not supported argument type');
}

$this->setParameters($parameters);
}

Expand All @@ -56,12 +78,17 @@ public function getType()
*/
public function toArray()
{
$query = [
'type' => $this->type,
'filter' => [
$this->filter->getType() => $this->filter->toArray(),
],
];
$query = [ 'type' => $this->type ];

$queries = ['filter', 'query'];

foreach ($queries as $type) {
if ($this->{$type}) {
$query[$type] = [
$this->{$type}->getType() => $this->{$type}->toArray(),
];
}
}

$output = $this->processArray($query);

Expand Down
51 changes: 41 additions & 10 deletions DSL/Filter/HasParentFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class HasParentFilter implements BuilderInterface
{
use ParametersTrait;

const INNER_QUERY = 'query';
const INNER_FILTER = 'filter';

/**
* @var string
*/
Expand All @@ -31,15 +34,38 @@ class HasParentFilter implements BuilderInterface
*/
private $filter;

/**
* @var BuilderInterface
*/
private $query;

/**
* @param string $parentType
* @param BuilderInterface $filter
* @param BuilderInterface $block
* @param array $parameters
* @param string $inner
*
* @throws \InvalidArgumentException
*/
public function __construct($parentType, BuilderInterface $filter, array $parameters = [])
{
public function __construct(
$parentType,
BuilderInterface $block,
array $parameters = [],
$inner = self::INNER_FILTER
) {
$this->parentType = $parentType;
$this->filter = $filter;

switch ($inner) {
case 'filter':
$this->filter = $block;
break;
case 'query':
$this->query = $block;
break;
default:
throw new \InvalidArgumentException('Not supported argument type');
}

$this->setParameters($parameters);
}

Expand All @@ -56,12 +82,17 @@ public function getType()
*/
public function toArray()
{
$query = [
'parent_type' => $this->parentType,
'filter' => [
$this->filter->getType() => $this->filter->toArray(),
],
];
$query = [ 'parent_type' => $this->parentType ];

$queries = ['filter', 'query'];

foreach ($queries as $type) {
if ($this->{$type}) {
$query[$type] = [
$this->{$type}->getType() => $this->{$type}->toArray(),
];
}
}

$output = $this->processArray($query);

Expand Down