Read attributes of a given DN

@param   string  $dn  The DN of the object you want to read

@return  array|boolean  Array of attributes for the given DN or boolean false on failure

@since   1.0
504550
public function read($dn)
	{
		if (!$this->isBound || !$this->isConnected())
		{
			return false;
		}

		$base   = substr($dn, strpos($dn, ',') + 1);
		$cn     = substr($dn, 0, strpos($dn, ','));
		$result = ldap_read($this->resource, $base, $cn);

		if ($result === false)
		{
			return false;
		}

		return ldap_get_entries($this->resource, $result);
	}
904720
public function toString(bool $idn = false)
    {
        $o = "";
        if (!empty($this->scheme))
            $o .= $this->scheme . "://";
        
        if (!empty($this->username) && !empty($this->password))
            $o .= $this->username . ':' . $this->password . '@';

        // Check for IDN
        $host = $this->host;
        if ($idn && preg_match('/[^\x20-\x7f]/', $host))
            $host = \idn_to_ascii($host);
        $o .= $host;

        if (!empty($this->port))
        {
            if (!(
                ($this->scheme === "http"  && $this->port === 80) ||
                ($this->scheme === "https" && $this->port === 443) || 
                ($this->scheme === "ftp"   && $this->port === 21)
            ))
                $o .= ":" . $this->port;
        }

        $o .= $this->path;
        $query = $this->getQuery();

        if (!empty($query))
            $o .= '?' . $query;

        if (!empty($this->fragment))
            $o .= '#' . $this->fragment;

        return $o;
    }
729951
public function read($path) {
        $mapping = $this->mapper->get($path);

        if (!$mapping) {
            return false;
        }

        try {
            $file = $this->client->get($mapping['fid']);

            if (!$file) {
                return false;
            }

            return [
                'contents' => stream_get_contents($file)
            ];
        } catch (SeaweedFSException $e) {
            return false;
        }
    }
655163
function getDN($format = self::DN_ARRAY, $dn = null)
    {
        if (!isset($dn)) {
            $dn = isset($this->currentCert['tbsCertList']) ? $this->currentCert['tbsCertList']['issuer'] : $this->dn;
        }

        switch ((int) $format) {
            case self::DN_ARRAY:
                return $dn;
            case self::DN_ASN1:
                $asn1 = new ASN1();
                $asn1->loadOIDs($this->oids);
                $filters = array();
                $filters['rdnSequence']['value'] = array('type' => ASN1::TYPE_UTF8_STRING);
                $asn1->loadFilters($filters);
                $this->_mapOutDNs($dn, 'rdnSequence', $asn1);
                return $asn1->encodeDER($dn, $this->Name);
            case self::DN_CANON:
                //  No SEQUENCE around RDNs and all string values normalized as
                // trimmed lowercase UTF-8 with all spacing as one blank.
                // constructed RDNs will not be canonicalized
                $asn1 = new ASN1();
                $asn1->loadOIDs($this->oids);
                $filters = array();
                $filters['value'] = array('type' => ASN1::TYPE_UTF8_STRING);
                $asn1->loadFilters($filters);
                $result = '';
                $this->_mapOutDNs($dn, 'rdnSequence', $asn1);
                foreach ($dn['rdnSequence'] as $rdn) {
                    foreach ($rdn as $i => $attr) {
                        $attr = &$rdn[$i];
                        if (is_array($attr['value'])) {
                            foreach ($attr['value'] as $type => $v) {
                                $type = array_search($type, $asn1->ANYmap, true);
                                if ($type !== false && isset($asn1->stringTypeSize[$type])) {
                                    $v = $asn1->convert($v, $type);
                                    if ($v !== false) {
                                        $v = preg_replace('/\s+/', ' ', $v);
                                        $attr['value'] = strtolower(trim($v));
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    $result .= $asn1->encodeDER($rdn, $this->RelativeDistinguishedName);
                }
                return $result;
            case self::DN_HASH:
                $dn = $this->getDN(self::DN_CANON, $dn);
                $hash = new Hash('sha1');
                $hash = $hash->hash($dn);
                extract(unpack('Vhash', $hash));
                return strtolower(bin2hex(pack('N', $hash)));
        }

        // Default is to return a string.
        $start = true;
        $output = '';

        $result = array();
        $asn1 = new ASN1();
        $asn1->loadOIDs($this->oids);
        $filters = array();
        $filters['rdnSequence']['value'] = array('type' => ASN1::TYPE_UTF8_STRING);
        $asn1->loadFilters($filters);
        $this->_mapOutDNs($dn, 'rdnSequence', $asn1);

        foreach ($dn['rdnSequence'] as $field) {
            $prop = $field[0]['type'];
            $value = $field[0]['value'];

            $delim = ', ';
            switch ($prop) {
                case 'id-at-countryName':
                    $desc = 'C';
                    break;
                case 'id-at-stateOrProvinceName':
                    $desc = 'ST';
                    break;
                case 'id-at-organizationName':
                    $desc = 'O';
                    break;
                case 'id-at-organizationalUnitName':
                    $desc = 'OU';
                    break;
                case 'id-at-commonName':
                    $desc = 'CN';
                    break;
                case 'id-at-localityName':
                    $desc = 'L';
                    break;
                case 'id-at-surname':
                    $desc = 'SN';
                    break;
                case 'id-at-uniqueIdentifier':
                    $delim = '/';
                    $desc = 'x500UniqueIdentifier';
                    break;
                case 'id-at-postalAddress':
                    $delim = '/';
                    $desc = 'postalAddress';
                    break;
                default:
                    $delim = '/';
                    $desc = preg_replace('#.+-([^-]+)$#', '$1', $prop);
            }

            if (!$start) {
                $output.= $delim;
            }
            if (is_array($value)) {
                foreach ($value as $type => $v) {
                    $type = array_search($type, $asn1->ANYmap, true);
                    if ($type !== false && isset($asn1->stringTypeSize[$type])) {
                        $v = $asn1->convert($v, $type);
                        if ($v !== false) {
                            $value = $v;
                            break;
                        }
                    }
                }
                if (is_array($value)) {
                    $value = array_pop($value); // Always strip data type.
                }
            } elseif (is_object($value) && $value instanceof Element) {
                $callback = function ($x) {
                    return "\x" . bin2hex($x[0]);
                };
                $value = strtoupper(preg_replace_callback('#[^\x20-\x7E]#', $callback, $value->element));
            }
            $output.= $desc . '=' . $value;
            $result[$desc] = isset($result[$desc]) ?
                array_merge((array) $dn[$prop], array($value)) :
                $value;
            $start = false;
        }

        return $format == self::DN_OPENSSL ? $result : $output;
    }
1203290
public function read($n)
    {
        if (0 === $n) {
            return '';
        }

        $remaining = ($n - $this->length) + $this->position;

        while ($remaining > 0) {
            //$this->io->wait();
            if ($this->io->shouldEnableCrypto()) {
                $new = $this->io->read($remaining);
            } else {
                $new = $this->io->readChunk($remaining);
            }
            $this->bytes .= $new;
            $remaining -= strlen($new);
        }

        $this->length = strlen($this->bytes);
        $data = substr($this->bytes, $this->position, $n);
        $this->position += $n;

        return $data;
    }
907134
public static function getRdnFromDn($dn)
    {
        $rdn = self::explodeDn($dn, 0)[0];
        $rdn = explode('=', $rdn, 2);

        return $rdn[0].'='.self::escapeValue($rdn[1], null, LDAP_ESCAPE_DN);
    }
442379
public function setManagedBy($dn)
    {
        if ($dn instanceof Model) {
            $dn = $dn->getDn();
        }

        return $this->setFirstAttribute($this->schema->managedBy(), $dn);
    }
1004020
public function read($dn, $filter, array $fields)
    {
        if ($this->suppressErrors) {
            return @ldap_read($this->getConnection(), $dn, $filter, $fields);
        }

        return ldap_read($this->getConnection(), $dn, $filter, $fields);
    }
352473
public function read($bytes)
    {
        $read = 0;
        $parts = array();

        while ($read < $bytes) {
            $data = fread($this->socket, $bytes - $read);

            if ($data === false) {
                // server must have dropped the connection
                if (feof($this->socket)) {
                    $this->close();
                }

                return false;
            }

            $read += strlen($data);
            $parts[] = $data;
        }

        return implode($parts);
    }
368625
public function setDn($dn = null)
    {
        $this->dn = $dn instanceof Model ? $dn->getDn() : $dn;

        return $this;
    }
437352
public function readExact($n)
    {
        if ($n === 0) {
            return '';
        }
        if (!$this->bev || $this->bev->input->length < $n) {
            return false;
        }
        return $this->read($n);
    }
911500
protected function readClassMetadata($className)
	{
		/** @var DT\Metadata[] $result */
		$result = [];
		$reflection = new \ReflectionClass($className);
		$reader = new AnnotationReader();
		//Read property annotations
		$propertyFilter = \ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_PRIVATE;
		foreach ($reflection->getProperties($propertyFilter) as $property)
		{
			foreach (self::readPropertyAnnotations($property, $reader) as $subset => list($data, $strategy, $validators))
			{
				//Get or create metadata for subset
				$metadata = null;
				if (isset($result[$subset]))
				{
					$metadata = $result[$subset];
				}
				else
				{
					$metadata = new DT\Metadata();
					$metadata->className = $className;
					$metadata->subset = $subset;
					$result[$subset] = $metadata;
				}
				//Process field name
				$field = (empty($data->field)? $property->getName() : $data->field);
				if (in_array($field, $metadata->fields))
				{
					throw new \LogicException(
						sprintf('Invalid metadata for %s: duplicate field %s in subset "%s".', $className, $field, $data->subset)
					);
				}
				$metadata->fields[] = $field;
				//Process direct access property
				if ($property->isPublic())
				{
					$metadata->properties[$field] = $property->getName();
				}
				else
				{
					$methodNameBase = str_replace('_', '', ucwords($property->getName(), '_'));
					if ($data->getter === null)
					{
						$data->getter = 'get'. $methodNameBase;
					}
					if ($data->setter === null)
					{
						$data->setter = 'set'. $methodNameBase;
					}
				}
				//Process property getter
				if ((!empty($data->getter)) && self::isValidGetter($reflection, $data->getter))
				{
					$metadata->getters[$field] = $data->getter;
				}
				//Process property setter
				if ((!empty($data->setter)) && self::isValidSetter($reflection, $data->setter))
				{
					$metadata->setters[$field] = $data->setter;
				}
				//Copy strategy
				$metadata->strategies[$field] = $strategy;
				//Process nullable flag
				$metadata->nullables[$field] = $data->nullable;
				//Copy validators
				$metadata->validators[$field] = $validators;
			}
		}
		//Read class annotations
		foreach ($reader->getClassAnnotations($reflection) as $annotation)
		{
			if (($annotation instanceof DT\Annotation\Validator) && isset($result[$annotation->subset]))
			{
				$result[$annotation->subset]->validators[DT\Validator::GLOBAL_VALIDATOR_KEY][] = $annotation;
			}
		}
		return $result;
	}
817972
private static function parseDSN($dsn)
    {
        $matches = [];

        if (!preg_match(static::DSN_REGEX, $dsn, $matches)) {
            throw new PDOException(sprintf('Invalid DSN %s', $dsn));
        }

        return array_slice($matches, 1);
    }
14679
public function userUsernameFromDn($dn) {

    $ldap_entry = @$this->dnExists($dn, 'ldap_entry', array());
    if (!$ldap_entry || !is_array($ldap_entry)) {
      return FALSE;
    }
    else {
      return $this->userUsernameFromLdapEntry($ldap_entry);
    }

  }
1034852
public function getDomainInfo( $domain ) {
		$domain = $this->normalizeDomain( $domain );
		// Check cache and custom-registered domains
		if ( !isset( $this->domainInfos[ $domain ] ) ) {
			// Default to local domain
			$dir = $this->localBaseDir . '/language/messages/' . $domain;
			if ( !is_dir( $dir ) ) {
				// Domain does not exist
				return false;
			}
			$this->domainInfos[ $domain ] = [
				'dir' => $dir,
			];
		}
		return $this->domainInfos[ $domain ];
	}
1325970
public function delete($dn)
	{
		if (!$this->isBound || !$this->isConnected())
		{
			return false;
		}

		return ldap_delete($this->resource, $dn);
	}
1037257
public function load(DOMNode $node)
    {
        $return = true;

        $dom = new \DOMDocument('1.0');
        $dom->importNode($node, true);
        $dom->appendChild($node);

        $path = new \DOMXPath($dom);

        $this->setName($tableName = $path->evaluate('string((./value[@key="name"])[1])'));

        $comment = $path->evaluate('string((./value[@key="comment"])[1])');

        if ($comment) {
            $return = $this->loadAnnotations($comment);
        } // if

        if ($return) {
            $this->setId($tableId = $node->attributes->getNamedItem('id')->nodeValue);

            if (!$tableId || !$tableName) {
                throw new \LogicException('Table name or id could not be fond.');
            } // if

            $return = $this->loadMigrationFields($path);
        } // if

        return $return;
    }