file = $file; $this->searchers = $searchers; $this->type = $type; } public function execute() { $this->applySD(); $this->convertToOriginalFileType(); } protected function convertToOriginalFileType() { (new Process(['soffice', '--convert-to', $this->type, $this->file, '--outdir', storage_path('app/tmp/')]))->run(); } protected function applySD() { $dom = new \DOMDocument(); $dom->load($this->file); foreach($dom->getElementsByTagName('span') as $p) { $search = new SearchAndDisplace( stripslashes($p->textContent), [ 'searchers' => $this->searchers, ], false, true ); $changed = $search->execute(); if(!$changed) { continue; } $p->textContent = $changed['content']; } $dom->save($this->file); } }