Skip to content

Commit

Permalink
Add option apply to sort
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Kęska committed Apr 15, 2021
1 parent 59aad64 commit dee88c9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Reader/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
*/
final class Sort
{
const APPLY_ALWAYS = 1;
const APPLY_IF_SPECIFIED = 2;

/**
* Logical fields config.
*
Expand Down Expand Up @@ -83,6 +86,7 @@ private function __construct(bool $ignoreExtraFields, array $config)
'asc' => [$fieldName => SORT_ASC],
'desc' => [$fieldName => SORT_DESC],
'default' => 'asc',
'apply' => self::APPLY_IF_SPECIFIED

This comment has been minimized.

Copy link
@samdark

samdark Apr 15, 2021

Hmm. Maybe we should not add this option but instead not specify default?

], $fieldConfig);
}

Expand Down Expand Up @@ -265,7 +269,8 @@ public function getCriteria(): array
}

foreach ($config as $field => $fieldConfig) {
$criteria += $fieldConfig[$fieldConfig['default']];
if($fieldConfig['apply'] === self::APPLY_ALWAYS)

This comment has been minimized.

Copy link
@samdark

samdark Apr 15, 2021

if (array_key_exists('default', $fieldConfig))

$criteria += $fieldConfig[$fieldConfig['default']];
}

return $criteria;
Expand Down

0 comments on commit dee88c9

Please sign in to comment.