This repository has been archived by the owner on Jun 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from lexik/regroup_constants
Regroup constants
- Loading branch information
Showing
9 changed files
with
182 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\FormFilterBundle\Filter; | ||
|
||
/** | ||
* This class aim to regroup constants used in form filter types and in expression classes. | ||
* | ||
* @author Cédric Girard <c.girard@lexik.fr> | ||
*/ | ||
final class FilterOperands | ||
{ | ||
const OPERATOR_EQUAL = 'eq'; | ||
const OPERATOR_GREATER_THAN = 'gt'; | ||
const OPERATOR_GREATER_THAN_EQUAL = 'gte'; | ||
const OPERATOR_LOWER_THAN = 'lt'; | ||
const OPERATOR_LOWER_THAN_EQUAL = 'lte'; | ||
|
||
const STRING_STARTS = 1; | ||
const STRING_ENDS = 2; | ||
const STRING_EQUALS = 3; | ||
const STRING_BOTH = 4; | ||
|
||
const OPERAND_SELECTOR = 'selection'; | ||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* Returns all available number operands. | ||
* | ||
* @param boolean $includeSelector | ||
* @return array | ||
*/ | ||
public static function getNumberOperands($includeSelector = false) | ||
{ | ||
$values = array( | ||
self::OPERATOR_EQUAL, | ||
self::OPERATOR_GREATER_THAN, | ||
self::OPERATOR_GREATER_THAN_EQUAL, | ||
self::OPERATOR_LOWER_THAN, | ||
self::OPERATOR_LOWER_THAN_EQUAL, | ||
); | ||
|
||
if ($includeSelector) { | ||
$values[] = self::OPERAND_SELECTOR; | ||
} | ||
|
||
return $values; | ||
} | ||
|
||
/** | ||
* Returns all available string operands. | ||
* | ||
* @param boolean $includeSelector | ||
* @return array | ||
*/ | ||
public static function getStringOperands($includeSelector = false) | ||
{ | ||
$values = array( | ||
self::STRING_STARTS, | ||
self::STRING_ENDS, | ||
self::STRING_EQUALS, | ||
self::STRING_BOTH, | ||
); | ||
|
||
if ($includeSelector) { | ||
$values[] = self::OPERAND_SELECTOR; | ||
} | ||
|
||
return $values; | ||
} | ||
|
||
/** | ||
* Retruns an array of available conditions operator for numbers. | ||
* | ||
* @return array | ||
*/ | ||
public static function getNumberOperandsChoices() | ||
{ | ||
$choices = array(); | ||
|
||
$reflection = new \ReflectionClass(__CLASS__); | ||
foreach ($reflection->getConstants() as $name => $value) { | ||
if ('OPERATOR_' === substr($name, 0, 9)) { | ||
$choices[$value] = strtolower(str_replace(array('OPERATOR_', '_'), array('', ' '), $name)); | ||
} | ||
} | ||
|
||
return $choices; | ||
} | ||
|
||
/** | ||
* Retruns an array of available conditions patterns for string. | ||
* | ||
* @return array | ||
*/ | ||
public static function getStringOperandsChoices() | ||
{ | ||
$choices = array(); | ||
|
||
$reflection = new \ReflectionClass(__CLASS__); | ||
foreach ($reflection->getConstants() as $name => $value) { | ||
if ('STRING_' === substr($name, 0, 7)) { | ||
$choices[$value] = strtolower(str_replace(array('STRING_', '_'), array('', ' '), $name)); | ||
} | ||
} | ||
|
||
return $choices; | ||
} | ||
} |
Oops, something went wrong.