/** * @param $html string */ public function fromHtml($html) { $this->paragraphs->exchangeArray(array()); if (trim($html)) { $dom = new \DOMDocument(); $dom->loadHTML(trim($html)); /** @var \DOMElement $node */ foreach ($dom->getElementsByTagName('p') as $node) { $this->inputSystem = $node->getAttribute('lang'); $paragraph = new LexParagraph(); foreach (explode(' ', $node->getAttribute('class')) as $classValue) { if (StringUtil::startsWith($classValue, 'guid_')) { $guid = substr($classValue, 5); if ($guid) { $paragraph->guid = $guid; } } if (StringUtil::startsWith($classValue, 'styleName_')) { $styleName = substr($classValue, 10); if ($styleName) { $paragraph->styleName = $styleName; } } } $content = LiftDecoder::sanitizeSpans($node, $this->inputSystem); if ($content) { $paragraph->content = $content; } $this->paragraphs->append($paragraph); } } }
/** * Read LIFT entry with error reporting * * @param SimpleXMLElement $sxeNode * @param LexEntryModel $entry * @param LiftMergeRule $mergeRule */ private function readEntryWithErrorReport($sxeNode, $entry, $mergeRule = LiftMergeRule::CREATE_DUPLICATES) { try { $this->liftDecoder->readEntry($sxeNode, $entry, $mergeRule); $this->liftImportNodeError->addSubnodeError($this->liftDecoder->getImportNodeError()); } catch (Exception $e) { $this->liftImportNodeError->addSubnodeError($this->liftDecoder->getImportNodeError()); $this->report->nodeErrors[] = $this->liftImportNodeError; if ($this->report->hasError()) { error_log($this->report->toString()); } throw new \Exception($e); } }