LdapTools\Ldif\LdifParser::parse PHP Method

parse() public method

Parses a string containing LDIF data and returns an object with the entries it contains.
public parse ( string $ldif ) : Ldif
$ldif string
return Ldif
    public function parse($ldif)
    {
        $ldifObject = new Ldif();
        $this->setup($ldif);
        while (!$this->isEndOfLdif()) {
            if ($this->isComment()) {
                $this->addCommentToQueueOrLdif($ldifObject);
                $this->nextLine();
            } elseif ($this->isStartOfEntry()) {
                $ldifObject->addEntry($this->parseEntry());
            } elseif ($this->startsWith(Ldif::DIRECTIVE_VERSION . Ldif::KEY_VALUE_SEPARATOR)) {
                $this->setLdifVersion($ldifObject, $this->getKeyAndValue($this->currentLine())[1]);
                $this->nextLine();
            } elseif ($this->isEndOfEntry()) {
                $this->nextLine();
            } else {
                $this->throwException('Unexpected line in LDIF');
            }
        }
        $this->cleanup();
        return $ldifObject;
    }