match-column.php
6 years ago
match-context.php
6 years ago
match.php
6 years ago
preset.php
5 years ago
replace.php
6 years ago
result.php
6 years ago
search-flags.php
5 years ago
search.php
5 years ago
source-flags.php
5 years ago
source-manager.php
5 years ago
source.php
5 years ago
totals.php
6 years ago
search-flags.php
69 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex; |
| 4 | |
| 5 | /** |
| 6 | * Represents flags for a particular search |
| 7 | */ |
| 8 | class Search_Flags { |
| 9 | /** @var String[] */ |
| 10 | private $flags = []; |
| 11 | |
| 12 | /** |
| 13 | * Create a Source_Flags object with an array of flag strings |
| 14 | * |
| 15 | * @param Array $flags Array of flag values. |
| 16 | */ |
| 17 | public function __construct( array $flags = [] ) { |
| 18 | $allowed = [ |
| 19 | 'regex', |
| 20 | 'case', |
| 21 | ]; |
| 22 | |
| 23 | $this->flags = array_filter( $flags, function( $flag ) use ( $allowed ) { |
| 24 | return array_search( $flag, $allowed, true ) !== false; |
| 25 | } ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Is the flag set? |
| 30 | * |
| 31 | * @param String $flag Flag to check. |
| 32 | * @return boolean true if set, false otherwise |
| 33 | */ |
| 34 | public function has_flag( $flag ) { |
| 35 | return in_array( $flag, $this->flags, true ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Is the a regular expression search? |
| 40 | * |
| 41 | * @return boolean true if yes, false otherwise |
| 42 | */ |
| 43 | public function is_regex() { |
| 44 | return $this->has_flag( 'regex' ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Is the a case insensitive search? |
| 49 | * |
| 50 | * @return boolean true if yes, false otherwise |
| 51 | */ |
| 52 | public function is_case_insensitive() { |
| 53 | return $this->has_flag( 'case' ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Get all the flags |
| 58 | * |
| 59 | * @return Array Array of flags |
| 60 | */ |
| 61 | public function get_flags() { |
| 62 | return $this->flags; |
| 63 | } |
| 64 | |
| 65 | public function to_json() { |
| 66 | return $this->flags; |
| 67 | } |
| 68 | } |
| 69 |