protected function getFilters($count, $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') { $filters = []; for ($i = 0; $i < $count; $i++) { $filters[] = FilterFactory::build(substr(str_shuffle($chars), 0, 10), substr(str_shuffle($chars), 0, 10)); } return $filters; }
/** * @expectedException \LdapQuery\Exceptions\GrammarException */ public function testInValidWildcardRaw() { $f = FilterFactory::buildRaw('attribute', 'value', '=', 'something'); }
public function testToArray() { $g = $this->newGroup(); $this->assertEquals([], $g->toArray()); $this->assertEquals([], $g->toArray(' ')); $g = $this->newGroup(); $g->push(FilterFactory::build('foo', 'bar')); $this->assertEquals(['(', ' foo=bar', ')'], $g->toArray()); $g = $this->newGroup('!'); $g->push(FilterFactory::build('foo', 'bar')); $this->assertEquals(['(!', ' (', ' foo=bar', ' )', ')'], $g->toArray()); $g = $this->newGroup(); $g->push(FilterFactory::build('foo', 'bar')); $g->push($g); $this->assertEquals(['(&', ' (', ' foo=bar', ' )', ' (', ' foo=bar', ' )', ')'], $g->toArray()); $g = $this->newGroup(); $g->push(FilterFactory::build('foo', 'bar')); $g->push(FilterFactory::build('foo', 'bar')); $g->push($g); $this->assertEquals(['(&', ' (', ' foo=bar', ' )', ' (', ' foo=bar', ' )', ' (&', ' (', ' foo=bar', ' )', ' (', ' foo=bar', ' )', ' )', ')'], $g->toArray()); }
/** * Add a where clause to the LDAP Query. Defaulted to & logical, acts like a andWhere. * * @param string|Closure $attribute * @param string|array|null $operator * @param string|array|null $value * @param string|null $wildcard * @param bool $escape * @param string $logical * * @return $this * * @throws GrammarException */ public function where($attribute, $operator = null, $value = null, $wildcard = null, $escape = true, $negation = false, $logical = '&') { // If value is null, we assume that value is allocated to $operator // and the we want default operator (=) if ($value === null) { $value = $operator; $operator = '='; } // If value is an array, use a closure to generate a or group with all the // values. if (is_array($value)) { return $this->where(function ($builder) use($attribute, $value, $wildcard, $escape) { foreach ($value as $v) { $builder->orWhere($attribute, '=', $v, $wildcard, $escape); } }, null, null, null, null, $negation, $logical); } // Solve context accordingly to the rules. $group = $this->solveContext($logical, $negation); // If the attribute is a closure then we assume that we want to create a new context // and push it into the current group if ($attribute instanceof Closure) { $closureBuilder = new self(); $attribute($closureBuilder); $group->push($closureBuilder->group); return $this; } $group->push(FilterFactory::build($attribute, $value, $operator, $wildcard, $escape)); return $this; }