protected function getAttributeFromLdapQuery($value, $toSelect)
    {
        $query = $this->buildLdapQuery($this->options['filter'], $this->options['or_filter'], $toSelect);

        $bOr = $this->getQueryOrStatement($query, $value);
        $eq = $this->getQueryComparisonStatement($value, $query);

        if (!empty($bOr->getChildren())) {
            $bOr->add($eq);
            $query->where($bOr);
        } else {
            $query->where($eq);
        }
        $query->setBaseDn($this->options['base_dn']);

        try {
            return $query->getLdapQuery()->getSingleScalarResult();
        } catch (EmptyResultException $e) {
            throw new AttributeConverterException(sprintf(
                'Unable to convert value "%s" to a %s for attribute "%s"',
                $value,
                $toSelect,
                $this->getAttribute()
            ));
        }
    }