LdapTools\Ldif\LdifParser::parseCommonDirectives PHP Method

parseCommonDirectives() protected method

Parses directives that are potentially common to all entries and returns the LdifEntry object. Common directives include: changetype, control
protected parseCommonDirectives ( $dn ) : LdapTools\Ldif\Entry\LdifEntryInterface
$dn
return LdapTools\Ldif\Entry\LdifEntryInterface
    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;
    }