/** * Add object types used to narrow the query. This can either be a string name representing the object type from the * schema, such as 'user' or 'group' or you can pass the LdapObjectSchema for the type. If you are using this class * without a schema then construct the query manually by just using the "where" and "andWhere" methods. * * @param mixed $type The string schema type name or a LdapObjectSchema * @param null|string $alias The alias name to refer to the type being selected * @return $this * @throws \LdapTools\Exception\LdapQueryException * @todo The LdapObjectSchema should require the filter on construction so the exception is not needed */ public function from($type, $alias = null) { $type = $this->getSchemaFromType($type); if (is_null($type->getFilter())) { throw new InvalidArgumentException(sprintf('The schema type "%s" needs a filter defined to query LDAP with it.', $type->getObjectType())); } $this->operation->getFilter()->addLdapObjectSchema($type, $alias); $this->hydrator->setLdapObjectSchema($type); return $this; }
/** * Get the add operation and take care of the hydration process. * * @return AddOperation */ protected function getAddOperation() { $operation = new AddOperation($this->dn, $this->attributes); $operation->setLocation($this->container); foreach ($this->parameters as $parameter => $value) { $this->hydrator->setParameter($parameter, $value); } $this->hydrator->setLdapObjectSchema($this->schema); $this->hydrator->setLdapConnection($this->connection); $this->hydrator->setOperationType(AttributeConverterInterface::TYPE_CREATE); return $this->hydrator->hydrateToLdap($operation); }
/** * @param OperationHydrator $hydrator * @param LdapOperationInterface $operation * @return LdapOperationInterface */ protected function hydrateOperation(OperationHydrator $hydrator, LdapOperationInterface $operation) { if ($this instanceof SchemaAwareInterface) { $hydrator->setLdapObjectSchema($this->getLdapObjectSchema()); } if ($this instanceof LdapAwareInterface) { $hydrator->setLdapConnection($this->getLdapConnection()); } return $hydrator->hydrateToLdap($operation); }
/** * @param QueryOperation $operation * @param string $hydratorType * @param null|LdapObjectSchema $schema * @param null|string $alias * @return mixed */ protected function getResultsFromLdap(QueryOperation $operation, $hydratorType, $schema = null, $alias = null) { $hydrator = $this->hydratorFactory->get($hydratorType); $hydrator->setLdapConnection($this->ldap); $hydrator->setOperationType(AttributeConverterInterface::TYPE_SEARCH_FROM); $hydrator->setLdapObjectSchema($schema); $hydrator->setSelectedAttributes($this->getAttributesToLdap($operation->getAttributes(), false, $schema, $alias)); $opHydrator = new OperationHydrator($this->ldap); $opHydrator->setAlias($alias); $opHydrator->setOrderBy($this->orderBy); $opHydrator->setLdapObjectSchema($schema); $opHydrator->hydrateToLdap($operation); return $hydrator->hydrateAllFromLdap($this->ldap->execute($operation)); }