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
6 years ago
source.php
5 years ago
totals.php
6 years ago
source-flags.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex; |
| 4 | |
| 5 | /** |
| 6 | * Represents flags for a particular source |
| 7 | */ |
| 8 | class Source_Flags { |
| 9 | /** @var Array */ |
| 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 | $this->flags = $flags; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Set which flags are allowed, and remove any existing flags that don't match |
| 23 | * |
| 24 | * @param Array $allowed Array of allowed flags. |
| 25 | * @return void |
| 26 | */ |
| 27 | public function set_allowed_flags( array $allowed ) { |
| 28 | $this->flags = array_filter( $this->flags, function( $flag ) use ( $allowed ) { |
| 29 | return array_search( $flag, $allowed, true ) !== false; |
| 30 | } ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Is the flag set? |
| 35 | * |
| 36 | * @param String $flag Flag to check. |
| 37 | * @return boolean true if set, false otherwise |
| 38 | */ |
| 39 | public function has_flag( $flag ) { |
| 40 | return in_array( $flag, $this->flags, true ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get all the flags |
| 45 | * |
| 46 | * @return Array Array of flags |
| 47 | */ |
| 48 | public function get_flags() { |
| 49 | return $this->flags; |
| 50 | } |
| 51 | |
| 52 | public function to_json() { |
| 53 | return $this->flags; |
| 54 | } |
| 55 | } |
| 56 |