aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Search/Filter/BooleanFilter.php
blob: 894dc13b657469d0a250ebed24c27b9f6210acf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace OC\Search\Filter;

use InvalidArgumentException;
use OCP\Search\IFilter;

class BooleanFilter implements IFilter {
	private bool $value;

	public function __construct(string $value) {
		$this->value = match ($value) {
			'true', 'yes', 'y', '1' => true,
			'false', 'no', 'n', '0', '' => false,
			default => throw new InvalidArgumentException('Invalid boolean value ' . $value),
		};
	}

	public function get(): bool {
		return $this->value;
	}
}