Initial commit
This commit is contained in:
11
src/Contract/ProcessRunnerInterface.php
Normal file
11
src/Contract/ProcessRunnerInterface.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Scandalous\Contract;
|
||||
|
||||
interface ProcessRunnerInterface
|
||||
{
|
||||
/** @param string[] $command */
|
||||
public function run(array $command): string;
|
||||
}
|
||||
10
src/Contract/TextExtractorInterface.php
Normal file
10
src/Contract/TextExtractorInterface.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Scandalous\Contract;
|
||||
|
||||
interface TextExtractorInterface
|
||||
{
|
||||
public function extract(string $file): string;
|
||||
}
|
||||
21
src/Engine/LiteParseExtractor.php
Normal file
21
src/Engine/LiteParseExtractor.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Scandalous\Engine;
|
||||
|
||||
use Scandalous\Contract\ProcessRunnerInterface;
|
||||
use Scandalous\Contract\TextExtractorInterface;
|
||||
|
||||
final class LiteParseExtractor implements TextExtractorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private ProcessRunnerInterface $runner,
|
||||
private string $binary = 'lit',
|
||||
) {}
|
||||
|
||||
public function extract(string $file): string
|
||||
{
|
||||
return $this->runner->run([$this->binary, 'parse', $file]);
|
||||
}
|
||||
}
|
||||
20
src/Process/ProcessRunner.php
Normal file
20
src/Process/ProcessRunner.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Scandalous\Process;
|
||||
|
||||
use Scandalous\Contract\ProcessRunnerInterface;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
final class ProcessRunner implements ProcessRunnerInterface
|
||||
{
|
||||
/** @param string[] $command */
|
||||
public function run(array $command): string
|
||||
{
|
||||
$process = new Process($command);
|
||||
$process->mustRun();
|
||||
|
||||
return $process->getOutput();
|
||||
}
|
||||
}
|
||||
19
src/Scandalous.php
Normal file
19
src/Scandalous.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Scandalous;
|
||||
|
||||
use Scandalous\Contract\TextExtractorInterface;
|
||||
|
||||
class Scandalous
|
||||
{
|
||||
public function __construct(
|
||||
private readonly TextExtractorInterface $extractor,
|
||||
) {}
|
||||
|
||||
public function extract(string $pdfPath): string
|
||||
{
|
||||
return $this->extractor->extract($pdfPath);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user