Initial commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.devenv/
|
||||||
|
vendor/
|
||||||
|
.php-cs-fixer.cache
|
||||||
17
.php-cs-fixer.dist.php
Normal file
17
.php-cs-fixer.dist.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PhpCsFixer\Config;
|
||||||
|
use PhpCsFixer\Finder;
|
||||||
|
|
||||||
|
return (new Config())
|
||||||
|
->setRiskyAllowed(false)
|
||||||
|
->setRules([
|
||||||
|
'@PER-CS' => true
|
||||||
|
])
|
||||||
|
->setFinder(
|
||||||
|
(new Finder())
|
||||||
|
->in(__DIR__)
|
||||||
|
)
|
||||||
|
;
|
||||||
19
composer.json
Normal file
19
composer.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "armelnl/scandalous",
|
||||||
|
"description": "A wrapper around LiteParse for PDF extraction",
|
||||||
|
"type": "library",
|
||||||
|
"license": "MIT",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Scandalous\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^8.4",
|
||||||
|
"symfony/process": "^8.1"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"friendsofphp/php-cs-fixer": "^3.95",
|
||||||
|
"phpstan/phpstan": "^2.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
2926
composer.lock
generated
Normal file
2926
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
65
devenv.lock
Normal file
65
devenv.lock
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"devenv": {
|
||||||
|
"locked": {
|
||||||
|
"dir": "src/modules",
|
||||||
|
"lastModified": 1780630679,
|
||||||
|
"narHash": "sha256-hhQyVAYmNKziZ0T+T4Gsk0PYmnz4vdzOzpkJAmDASKM=",
|
||||||
|
"owner": "cachix",
|
||||||
|
"repo": "devenv",
|
||||||
|
"rev": "90ed6227ab389dd4e874a69a724f25dba312b754",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"dir": "src/modules",
|
||||||
|
"owner": "cachix",
|
||||||
|
"repo": "devenv",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs-src": "nixpkgs-src"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1778507786,
|
||||||
|
"narHash": "sha256-HzSQCKMsMr8r55LwM1JuzIOB+8bzk0FEv6sItKvsfoY=",
|
||||||
|
"owner": "cachix",
|
||||||
|
"repo": "devenv-nixpkgs",
|
||||||
|
"rev": "8f24a228a782e24576b155d1e39f0d914b380691",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "cachix",
|
||||||
|
"ref": "rolling",
|
||||||
|
"repo": "devenv-nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs-src": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1778274207,
|
||||||
|
"narHash": "sha256-I4puXmX1iovcCHZlRmztO3vW0mAbbRvq4F8wgIMQ1MM=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "b3da656039dc7a6240f27b2ef8cc6a3ef3bccae7",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"devenv": "devenv",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
20
devenv.nix
Normal file
20
devenv.nix
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
packages = [
|
||||||
|
pkgs.liteparse
|
||||||
|
];
|
||||||
|
|
||||||
|
languages = {
|
||||||
|
php = {
|
||||||
|
enable = true;
|
||||||
|
packages = {
|
||||||
|
composer = pkgs.phpPackages.composer;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
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