/** * Add a LdapObjectSchema for a object type that will be selected for. Optionally specify a specific alias that is * used to reference it. If no alias is specified, then it uses the object type name for the schema. * * @param LdapObjectSchema $schema * @param null|string $alias */ public function addLdapObjectSchema(LdapObjectSchema $schema, $alias = null) { if (!is_null($alias) && !is_string($alias)) { throw new InvalidArgumentException(sprintf('The alias for type "%s" must be a string, but "%s" was given.', $schema->getObjectType(), is_string($alias) ? $alias : gettype($alias))); } $alias = $alias ?: $schema->getObjectType(); if (!preg_match(self::ALIAS_REGEX, $alias)) { throw new InvalidArgumentException(sprintf('The alias "%s" for type "%s" is invalid. Allowed characters are: A-Z, a-z, 0-9, -, _', $alias, $schema->getObjectType())); } $this->aliases[$alias] = $schema; }
/** * @param array $filter * @param BaseOperator|null $operator * @return BaseOperator */ protected function getOperatorForArray(array $filter, BaseOperator $operator = null) { $filter = !empty($filter) ? $this->filterBuilder->bAnd(...$this->parseFilterToOperators($filter)) : null; if (!$filter && !$operator) { throw new InvalidArgumentException(sprintf('Type "%s" for schema "%s" needs to have one of the following defined: objectClass, objectCategory, or filter.', $this->schema->getObjectType(), $this->schema->getSchemaName())); } elseif ($filter && $operator) { $operator = $this->filterBuilder->bAnd($operator, $filter); } else { $operator = $operator ?: $filter; } return $operator; }
/** * Validate that an object schema meets the minimum requirements. * * @param LdapObjectSchema $schema * @throws SchemaParserException */ protected function validateObjectSchema($schema) { if (empty($schema->getAttributeMap())) { throw new SchemaParserException(sprintf('Object type "%s" has no attributes defined.', $schema->getObjectType())); } elseif (!(bool) count(array_filter(array_keys($schema->getAttributeMap()), 'is_string'))) { throw new SchemaParserException('The attributes for a schema should be an associative array.'); } if ($schema->getScope() && !in_array($schema->getScope(), QueryOperation::SCOPE)) { throw new SchemaParserException(sprintf('The scope "%s" is not valid. Valid types are: %s', $schema->getScope(), implode(', ', QueryOperation::SCOPE))); } }
public function it_should_always_return_null_when_calling_get() { $item = new LdapObjectSchema('foo', 'bar'); $this->get($item->getCacheType(), $item->getSchemaName() . '.' . $item->getObjectType())->shouldBeNull(); }