Lines Matching refs:filter

22  * Parses LDAP filter strings. RFC 4515.
33 protected $filter = '';
52 * @param string $filter
54 public function __construct(string $filter)
56 $this->filter = $filter;
57 $this->length = strlen($filter);
61 * @param string $filter
66 public static function parse(string $filter): FilterInterface
68 if ($filter === '') {
69 throw new FilterParseException('The filter cannot be empty.');
72 return (new self($filter))->parseFilterString(0, true)[1];
85 [$endsAt, $filter] = $this->parseFilterContainer($startAt, $isRoot);
87 [$endsAt, $filter] = $this->parseComparisonFilter($startAt, $isRoot);
91 'Unexpected value at end of the filter: %s',
92 substr($this->filter, $endsAt)
96 return [$endsAt, $filter];
119 * Parse a filter container. Always returns the ending position followed by the filter container.
140 $operator = substr($this->filter, $startAt + 1, 1);
147 $filter = $operator === FilterInterface::OPERATOR_AND ? new AndFilter() : new OrFilter();
150 $filter->add($childFilter);
153 return [$endAt, $filter];
157 * Parse a comparison operator. Always returns the ending position followed by the filter.
175 if ($this->filter[$i] === $op) {
177 } elseif (($i + 1) < $endAt && $this->filter[$i] . $this->filter[$i + 1] === $op) {
193 $this->filter,
198 $this->filter,
205 'The attribute is missing in the filter near position %s.',
214 * Validates some initial filter logic and determines if the filter is wrapped in parenthesis (validly).
225 # A filter without an opening parenthesis is only valid if it is the root. And it cannot have a closing parenthesis.
236 # If this is not a root filter, it must start with an opening parenthesis.
240 $this->filter[$startAt],
249 * Validate some basic aspects of the filter after it is parsed.
261 'Expected one of "%s" in the filter after position %s, but received none.',
350 $filter = new SubstringFilter($attribute);
354 'Unable to parse the substring filter for attribute %s.',
365 $filter->setStartsWith($substring[0]);
367 $filter->setEndsWith($substring[0]);
372 $filter->setContains(...$contains);
374 return $filter;
388 'The "not" filter at position %s cannot contain multiple filters.',
395 'The value after the "not" filter value was unexpected: %s',
396 substr($this->filter, $info[0] + 1, $endAt - ((int) $info[0] + 1))
410 return isset($this->filter[$pos]) && $this->filter[$pos] === $char;
414 * This seems like a potential minefield. But the general idea is to loop through the complete filter to get the
417 * comparison filter is encountered to only capture beginning and end parenthesis of containers.
431 if ($this->filter[$i] === FilterInterface::PAREN_LEFT) {
434 } elseif ($this->filter[$i] === FilterInterface::PAREN_RIGHT) {
442 throw new FilterParseException('The filter has an unmatched "(".');
457 if ($this->filter[$i] === FilterInterface::PAREN_RIGHT) {
486 if (isset($this->filter[$i + 1]) && in_array($this->filter[$i + 1], FilterInterface::OPERATORS, true)) {
494 # Comparison filter inside the container...
495 } elseif (isset($this->filter[$i]) && $this->filter[$i] === FilterInterface::PAREN_LEFT) {
498 } elseif (isset($this->filter[$i]) && $this->filter[$i] === FilterInterface::PAREN_RIGHT) {
500 'The filter container near position %s is empty.',
503 # Any other conditions possible? This shouldn't happen unless the filter is malformed..
507 $this->filter[$i - 1] ?? '',
509 $this->filter[$i + 1] ?? ''
512 # If there is no operator this is a standard comparison filter, just find the next closing parenthesis