Parses directives that are potentially common to all entries and returns the LdifEntry object. Common directives
include: changetype, control

@param $dn
@return LdifEntryInterface
@throws LdifParserException
174262
protected function parseCommonDirectives($dn)
    {
        $changeType = null;
        $controls = [];

        $this->nextLine();
        while ($this->isCommonDirective()) {
            if ($this->isComment()) {
                $this->nextLine();
                continue;
            // We need to exit the loop completely in this case...
            } elseif ($this->isEndOfLdif() || $this->isStartOfEntry()) {
                break;
            } elseif ($this->isCommonDirective()) {
                list($key, $value) = $this->getKeyAndValue($this->currentLine());

                if ($key == Ldif::DIRECTIVE_CHANGETYPE && is_null($changeType)) {
                    $changeType = $value;
                } elseif ($key == Ldif::DIRECTIVE_CHANGETYPE && !is_null($changeType)) {
                    $this->throwException('The changetype directive has already been defined');
                } else {
                    $controls[] = $this->getLdapControl($value);
                }
            }
            $this->nextLine();
        }
        $changeType = $changeType ?: LdifEntryInterface::TYPE_ADD;
        $entry = $this->getLdifEntryObject($dn, $changeType);

        foreach ($controls as $control) {
            $entry->addControl($control);
        }

        return $entry;
    }
559262
public function delete($dn)
    {
        if ($this->suppressErrors) {
            return @ldap_delete($this->getConnection(), $dn);
        }

        return ldap_delete($this->getConnection(), $dn);
    }
579764
public function parse($definition)
    {
        $values = explode(' ', $definition);
        $direction = $this->getDirection($values);
        $values = explode('/', $values[0]);
        $type = $values[0];

        switch (strtolower($type)) {
            case 'depth':
                return new Depth($direction);
            case 'field':
                return $this->buildFieldSortClause($values, $direction);
            case 'modified':
                return new DateModified($direction);
            case 'name':
                return new ContentName($direction);
            case 'priority':
                return new Priority($direction);
            case 'published':
                return new DatePublished($direction);
        }

        throw new InvalidArgumentException(
            "Could not handle sort type '{$type}'"
        );
    }
611516
protected function getLdifEntryObject($dn, $changeType)
    {
        if (!array_key_exists($changeType, $this->changeTypeMap)) {
            $this->throwException(sprintf('The changetype "%s" is invalid', $changeType));
        }

        return new $this->changeTypeMap[$changeType]($dn);
    }
993435
public function handle(TypeDefinitionNode $definition): Type
    {
        $nodeValue = new NodeValue($definition);

        return $this->pipeline
            ->send($nodeValue)
            ->through(
                $this->directiveFactory->createNodeMiddleware($definition)
            )
            ->via('handleNode')
            ->then(function (NodeValue $value) use ($definition): Type {
                $nodeResolver = $this->directiveFactory->createNodeResolver($definition);

                if ($nodeResolver) {
                    return $nodeResolver->resolveNode($value);
                }

                return $this->resolveType($definition);
            });
    }
342741
protected function parseDirectoryDo(\Gettext\Translations $translations, $rootDirectory, $relativePath, $subParsersFilter, $exclude3rdParty)
    {
        switch ($relativePath) {
            case '':
                $directoryAlternatives = array('application/config/generated_overrides', 'application/config', 'concrete/config');
                break;
            case 'application':
                $directoryAlternatives = array('config/generated_overrides', 'config');
                break;
            case 'concrete':
                $directoryAlternatives = array('config');
                break;
            default:
                return;
        }
        $prefix = ($relativePath === '') ? '' : "$relativePath/";
        $this->parseFileTypes($translations, $rootDirectory, $prefix, $directoryAlternatives);
        $this->parseTranslatableStrings($translations, $rootDirectory, $prefix, $directoryAlternatives);
    }
1053214
public function dnStrToArr($dnStr, $excludeBaseDn = true, $includeAttributes = false)
    {
        if ($excludeBaseDn) {
            return ldap_explode_dn($dnStr, ($includeAttributes ? 0 : 1));
        } else {
            return ldap_explode_dn($this->adldap->getBaseDn().$dnStr, ($includeAttributes ? 0 : 1));
        }
    }
801819
public function modifyBatch($dn, array $entry)
    {
        if ($this->suppressErrors) {
            return @ldap_modify_batch($this->getConnection(), $dn, $entry);
        }

        return ldap_modify_batch($this->getConnection(), $dn, $entry);
    }
1183267
public function mod_replace($dn, $entry)
    {
        $this->_debug("C: Replace $dn: ".print_r($entry, true));

        if (!ldap_mod_replace($this->conn, $dn, $entry)) {
            $this->_error("ldap_mod_replace() failed with " . ldap_error($this->conn));
            return false;
        }

        $this->_debug("S: OK");
        return true;
    }
650022
public static function parse($filename, $del=".")
    {
        if (is_null(self::$_instance)) {
            self::$_instance = new self($filename, $del);
        }
        return self::$_instance->getObj();
        //return self::$_instance;
    }
669956
public function schema($dn = null)
    {
        // Schema caching by Knut-Olav Hoven
        // If a schema caching object is registered, we use that to fetch
        // a schema object.
        // See registerSchemaCache() for more info on this.
        if ($this->_schema === null) {
            if ($this->_schema_cache) {
               $cached_schema = $this->_schema_cache->loadSchema();
               if ($cached_schema instanceof Net_LDAP2_Error) {
                   return $cached_schema; // route error to client
               } else {
                   if ($cached_schema instanceof Net_LDAP2_Schema) {
                       $this->_schema = $cached_schema;
                   }
               }
            }
        }

        // Fetch schema, if not tried before and no cached version available.
        // If we are already fetching the schema, we will skip fetching.
        if ($this->_schema === null) {
            // store a temporary error message so subsequent calls to schema() can
            // detect, that we are fetching the schema already.
            // Otherwise we will get an infinite loop at Net_LDAP2_Schema::fetch()
            $this->_schema = new Net_LDAP2_Error('Schema not initialized');
            $this->_schema = Net_LDAP2_Schema::fetch($this, $dn);

            // If schema caching is active, advise the cache to store the schema
            if ($this->_schema_cache) {
                $caching_result = $this->_schema_cache->storeSchema($this->_schema);
                if ($caching_result instanceof Net_LDAP2_Error) {
                    return $caching_result; // route error to client
                }
            }
        }
        return $this->_schema;
    }
63955
protected function type(\DOMNode $node)
    {
        $type = null;
        if ($node instanceof \DOMText) {
            $type = WordType::TEXT;
        } elseif ($node instanceof \DOMAttr) {
            $type = WordType::VALUE;
        } else {
            throw new ParserCrawlerAfterListenerException('No word type set for this kind of node.');
        }
        return $type;
    }
169436
public static function explodeDn($dn, $withAttributes = 1)
    {
        $pieces = ldap_explode_dn($dn, $withAttributes);

        if ($pieces === false || !isset($pieces['count']) || $pieces['count'] == 0) {
            throw new InvalidArgumentException(sprintf('Unable to parse DN "%s".', $dn));
        }
        for ($i = 0; $i < $pieces['count']; $i++) {
            $pieces[$i] = self::unescapeValue($pieces[$i]);
        }
        unset($pieces['count']);

        return $pieces;
    }
947702
public function deleteEntry($dn)
    {
        if (! (@ldap_delete($this->connection, $dn))) {
            $code = @ldap_errno($this->connection);
            throw new PersistenceException(
                sprintf(
                    'Could not delete entry %s: Ldap Error Code=%s - %s',
                    $dn,
                    $code,
                    ldap_err2str($code)
                )
            );
        }
    }
809604
public function create($dn, array $entries)
	{
		if (!$this->isBound || !$this->isConnected())
		{
			return false;
		}

		return ldap_add($this->resource, $dn, $entries);
	}
241905
public static function Connect ($dsn) {
		try {
			$dsn = static::AdjustDsn($dsn);

			static::ValidateDsn($dsn);

			return new static (
				static::MakeDsn($dsn),
				$dsn['username'] ?? null,
				$dsn['password'] ?? null,
				static::MakeOptionList($dsn['options'] ?? [])
			);
		} catch (\PDOException $pdo_e) {
 			throw new \Exception(sprintf(
 				'%s dsn=%s user=%s password=%s options=%s',
 				$pdo_e->getMessage(),
 				static::MakeDsn($dsn),
 				$dsn['username'] ?? '',
 				$dsn['password'] ?? '',
 				implode(', ', static::MakeOptionList($dsn['options'] ?? []))
 			), 0, $pdo_e);
		}
	}
407969
public function replace($dn, $attribute)
	{
		if (!$this->isBound || !$this->isConnected())
		{
			return false;
		}

		return ldap_mod_replace($this->resource, $dn, $attribute);
	}