You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
52 lines
1.1 KiB
<?php
|
|
|
|
namespace App\Ingest;
|
|
|
|
use App\Parser\ParseTextArray;
|
|
|
|
class TextConvertor extends AbstractConvertor
|
|
{
|
|
public function execute()
|
|
{
|
|
$textParser = new ParseTextArray();
|
|
|
|
$content = $textParser->fromFile($this->storage->path($this->path));
|
|
|
|
if ( ! $content) {
|
|
throw new \Exception('Could not read content.');
|
|
}
|
|
|
|
$content = $this->convertToUTF8($content);
|
|
|
|
$this->storeContent($content);
|
|
}
|
|
|
|
protected function convertToUTF8($content)
|
|
{
|
|
array_walk_recursive(
|
|
$content,
|
|
function (&$entry) {
|
|
$entry = mb_convert_encoding(
|
|
$entry,
|
|
'UTF-8'
|
|
);
|
|
}
|
|
);
|
|
|
|
return $content;
|
|
}
|
|
|
|
protected function storeContent($content)
|
|
{
|
|
$this->storeMD($content);
|
|
|
|
$this->deleteOriginalDocument();
|
|
}
|
|
|
|
protected function storeMD($content)
|
|
{
|
|
$convertor = new MDConvertor($content);
|
|
|
|
$this->storage->put("$this->directoryPath/document.md", $convertor->execute());
|
|
}
|
|
}
|