From d5a148d251943b7cae39333f162f746fa2cfbd5e Mon Sep 17 00:00:00 2001
From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com>
Date: Wed, 27 May 2026 14:50:14 +0200
Subject: [PATCH 1/4] :recycle: cleanup lingering issues
---
bin/DocumentCommandConfig.php | 2 +-
bin/MindeeCLICommand.php | 25 ++---
bin/MindeeCLIDocuments.php | 2 +-
bin/cli.php | 2 +-
docs/code_samples/bank_account_details_v1.txt | 3 +-
docs/code_samples/bank_account_details_v2.txt | 3 +-
docs/code_samples/bank_check_v1.txt | 3 +-
docs/code_samples/barcode_reader_v1.txt | 3 +-
docs/code_samples/bill_of_lading_v1_async.txt | 3 +-
docs/code_samples/business_card_v1_async.txt | 3 +-
docs/code_samples/carte_grise_v1.txt | 3 +-
docs/code_samples/cropper_v1.txt | 3 +-
docs/code_samples/custom_v1.txt | 2 +-
docs/code_samples/default.txt | 3 +-
docs/code_samples/default_async.txt | 3 +-
docs/code_samples/delivery_notes_v1_async.txt | 3 +-
docs/code_samples/driver_license_v1_async.txt | 3 +-
.../code_samples/energy_bill_fra_v1_async.txt | 3 +-
docs/code_samples/expense_receipts_v5.txt | 3 +-
.../expense_receipts_v5_async.txt | 3 +-
docs/code_samples/financial_document_v1.txt | 3 +-
.../financial_document_v1_async.txt | 3 +-
.../french_healthcard_v1_async.txt | 3 +-
docs/code_samples/idcard_fr_v1.txt | 3 +-
docs/code_samples/idcard_fr_v2.txt | 3 +-
docs/code_samples/ind_passport_v1_async.txt | 3 +-
.../international_id_v2_async.txt | 3 +-
.../invoice_splitter_v1_async.txt | 3 +-
docs/code_samples/invoices_v4.txt | 3 +-
docs/code_samples/invoices_v4_async.txt | 3 +-
.../multi_receipts_detector_v1.txt | 3 +-
.../code_samples/nutrition_facts_v1_async.txt | 3 +-
docs/code_samples/passport_v1.txt | 3 +-
docs/code_samples/payslip_fra_v3_async.txt | 3 +-
docs/code_samples/resume_v1_async.txt | 3 +-
.../us_healthcare_cards_v1_async.txt | 3 +-
docs/code_samples/us_mail_v3_async.txt | 3 +-
docs/code_samples/workflow_execution.txt | 2 +-
docs/code_samples/workflow_polling.txt | 2 +-
src/Error/MindeeHttpClientException.php | 12 --
src/Error/MindeeHttpServerException.php | 17 ---
.../MindeeV1ClientException.php} | 6 +-
.../MindeeV1HttpException.php} | 11 +-
src/Error/{ => V2}/MindeeV2HttpException.php | 7 +-
.../{ => V2}/MindeeV2HttpUnknownException.php | 4 +-
src/{Extraction => Image}/ExtractedImage.php | 6 +-
src/{Extraction => Image}/ImageExtractor.php | 6 +-
src/Input/Base64Input.php | 5 +-
src/Input/BytesInput.php | 5 +-
src/Input/FileInput.php | 5 +-
src/Input/LocalInputSource.php | 6 +-
src/Input/PathInput.php | 5 +-
src/{Extraction => Pdf}/ExtractedPdf.php | 2 +-
src/{Extraction => Pdf}/PdfExtractor.php | 8 +-
src/V1/Client.php | 105 ++----------------
src/V1/Image/ImageExtractor.php | 2 +-
src/V2/Client.php | 19 +---
src/V2/FileOperations/Crop.php | 4 +-
src/V2/FileOperations/CropFiles.php | 4 +-
src/V2/FileOperations/Split.php | 4 +-
src/V2/FileOperations/SplitFiles.php | 4 +-
src/V2/Http/MindeeApiV2.php | 8 +-
src/V2/Parsing/{ => Error}/ErrorItem.php | 2 +-
src/V2/Parsing/{ => Error}/ErrorResponse.php | 2 +-
.../Parsing/{ => Inference}/BaseInference.php | 5 +-
src/V2/Parsing/{ => Job}/Job.php | 3 +-
src/V2/Parsing/{ => Job}/JobResponse.php | 2 +-
src/V2/Parsing/{ => Job}/JobWebhook.php | 3 +-
.../ClassificationInference.php | 2 +-
src/V2/Product/Crop/CropInference.php | 2 +-
.../Extraction/ExtractionInference.php | 2 +-
src/V2/Product/Ocr/OcrInference.php | 2 +-
src/V2/Product/Split/SplitInference.php | 2 +-
tests/ClientTest.php | 37 +++---
.../DependencyCheckerNoExtendedTestPdf.php | 11 +-
tests/Input/LocalInputSourceTest.php | 24 ++--
tests/Input/UrlInputSourceTest.php | 6 +-
.../V1/CLI/MindeeCLICommandTestFunctional.php | 2 +-
tests/V1/Error/MindeeHttpExceptionTest.php | 33 +++---
.../ImageExtractorTest.php | 2 +-
...ceSplitterAutoExtractionTestFunctional.php | 4 +-
.../V1/Input/UrlInputSourceTestFunctional.php | 8 +-
.../Extras/ExtrasIntegrationFunctional.php | 5 +-
.../{Extraction => Pdf}/PdfExtractorTest.php | 4 +-
tests/V1/Workflow/WorkflowTestFunctional.php | 3 +-
tests/V2/ClientV2Test.php | 6 +-
tests/V2/ClientV2TestFunctional.php | 8 +-
tests/V2/Parsing/ExtractionResponseTest.php | 6 +-
tests/V2/Parsing/JobResponseTest.php | 6 +-
tests/resources | 2 +-
90 files changed, 250 insertions(+), 332 deletions(-)
delete mode 100644 src/Error/MindeeHttpClientException.php
delete mode 100644 src/Error/MindeeHttpServerException.php
rename src/Error/{MindeeClientException.php => V1/MindeeV1ClientException.php} (52%)
rename src/Error/{MindeeHttpException.php => V1/MindeeV1HttpException.php} (95%)
rename src/Error/{ => V2}/MindeeV2HttpException.php (89%)
rename src/Error/{ => V2}/MindeeV2HttpUnknownException.php (89%)
rename src/{Extraction => Image}/ExtractedImage.php (99%)
rename src/{Extraction => Image}/ImageExtractor.php (99%)
rename src/{Extraction => Pdf}/ExtractedPdf.php (98%)
rename src/{Extraction => Pdf}/PdfExtractor.php (99%)
rename src/V2/Parsing/{ => Error}/ErrorItem.php (94%)
rename src/V2/Parsing/{ => Error}/ErrorResponse.php (97%)
rename src/V2/Parsing/{ => Inference}/BaseInference.php (88%)
rename src/V2/Parsing/{ => Job}/Job.php (97%)
rename src/V2/Parsing/{ => Job}/JobResponse.php (94%)
rename src/V2/Parsing/{ => Job}/JobWebhook.php (94%)
rename tests/V1/{Extraction => Image}/ImageExtractorTest.php (99%)
rename tests/V1/{Extraction => Image}/InvoiceSplitterAutoExtractionTestFunctional.php (97%)
rename tests/V1/{Extraction => Pdf}/PdfExtractorTest.php (98%)
diff --git a/bin/DocumentCommandConfig.php b/bin/DocumentCommandConfig.php
index 5bea3c95..1ec30794 100644
--- a/bin/DocumentCommandConfig.php
+++ b/bin/DocumentCommandConfig.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Mindee\CLI;
+namespace Mindee\Cli;
/**
* Document configuration class for CLI usage.
diff --git a/bin/MindeeCLICommand.php b/bin/MindeeCLICommand.php
index 23c358ad..c2e0636d 100644
--- a/bin/MindeeCLICommand.php
+++ b/bin/MindeeCLICommand.php
@@ -2,9 +2,10 @@
declare(strict_types=1);
-namespace Mindee\CLI;
+namespace Mindee\Cli;
-use Mindee\Error\MindeeHttpException;
+use Exception;
+use Mindee\Error\V1\MindeeV1HttpException;
use Mindee\Input\InputSource;
use Mindee\Input\PageOptions;
use Mindee\Input\PathInput;
@@ -19,7 +20,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Exception;
use function count;
use function in_array;
@@ -253,7 +253,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
$filePathOrUrl = $input->getArgument('file_path_or_url');
- $file = $this->getFileSource($filePathOrUrl, $client, $output);
+ $file = $this->getFileSource($filePathOrUrl, $output);
if (!$file) {
return Command::FAILURE;
}
@@ -347,7 +347,7 @@ private function areMutuallyExclusivePagesOptions(InputInterface $input, OutputI
$pagesRemove = $input->getOption('pages_remove');
$pagesKeep = $input->getOption('pages_keep');
if ($pagesKeep && $pagesRemove) {
- $output->writeln("Page cut & page keep operations are mutually exclusive.");
+ $output->writeln("Page cut and page keep operations are mutually exclusive.");
return true;
}
return false;
@@ -357,21 +357,20 @@ private function areMutuallyExclusivePagesOptions(InputInterface $input, OutputI
* Retrieves a source file from a URL or a path.
*
* @param string $filePathOrUrl Path of the file, or URL if it's remote.
- * @param Client $client Mindee Client.
* @param OutputInterface $output Output interface of the CLI.
* @return PathInput|UrlInputSource|null A valid InputSource.
*/
- private function getFileSource(string $filePathOrUrl, Client $client, OutputInterface $output)
+ private function getFileSource(string $filePathOrUrl, OutputInterface $output): PathInput|UrlInputSource|null
{
- if (substr($filePathOrUrl, 0, 8) !== 'https://') {
+ if (!str_starts_with($filePathOrUrl, 'https://')) {
if (@file_exists($filePathOrUrl) || @file_get_contents($filePathOrUrl)) {
- return $client->sourceFromPath($filePathOrUrl);
+ return new PathInput($filePathOrUrl);
} else {
$output->writeln("Invalid path or url provided '$filePathOrUrl'.");
return null;
}
}
- return $client->sourceFromUrl($filePathOrUrl);
+ return new UrlInputSource($filePathOrUrl);
}
/**
@@ -493,7 +492,7 @@ private function executePrediction(
$debug = $input->getOption('debug');
try {
$result = $this->runClientPrediction($client, $product, $file, $predictMethodOptions, $isAsync, $debug);
- } catch (MindeeHttpException $e) {
+ } catch (MindeeV1HttpException $e) {
$output->writeln($e->getMessage());
return Command::FAILURE;
} catch (Exception $e) {
@@ -524,7 +523,7 @@ private function runClientPrediction(
PredictMethodOptions $predictMethodOptions,
bool $isAsync,
bool $debug
- ) {
+ ): AsyncPredictResponse|PredictResponse|string {
if ($debug) {
return "Command executed successfully.";
}
@@ -544,7 +543,7 @@ private function runClientPrediction(
* @return integer Command execution code return.
*/
private function outputResult(
- $result,
+ PredictResponse|AsyncPredictResponse|string $result,
?string $outputType,
OutputInterface $output
): int {
diff --git a/bin/MindeeCLIDocuments.php b/bin/MindeeCLIDocuments.php
index d2041c43..5ce217ab 100644
--- a/bin/MindeeCLIDocuments.php
+++ b/bin/MindeeCLIDocuments.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Mindee\CLI;
+namespace Mindee\Cli;
use Mindee\V1\Product\BarcodeReader\BarcodeReaderV1;
use Mindee\V1\Product\BillOfLading\BillOfLadingV1;
diff --git a/bin/cli.php b/bin/cli.php
index 29c185f9..859d9766 100755
--- a/bin/cli.php
+++ b/bin/cli.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Mindee\CLI;
+namespace Mindee\Cli;
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/MindeeCLIDocuments.php';
diff --git a/docs/code_samples/bank_account_details_v1.txt b/docs/code_samples/bank_account_details_v1.txt
index af944d38..eaf56aa0 100644
--- a/docs/code_samples/bank_account_details_v1.txt
+++ b/docs/code_samples/bank_account_details_v1.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(BankAccountDetailsV1::class, $inputSource);
diff --git a/docs/code_samples/bank_account_details_v2.txt b/docs/code_samples/bank_account_details_v2.txt
index 6dd87cf4..b3f4ce74 100644
--- a/docs/code_samples/bank_account_details_v2.txt
+++ b/docs/code_samples/bank_account_details_v2.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(BankAccountDetailsV2::class, $inputSource);
diff --git a/docs/code_samples/bank_check_v1.txt b/docs/code_samples/bank_check_v1.txt
index 2dd0bf71..48c14547 100644
--- a/docs/code_samples/bank_check_v1.txt
+++ b/docs/code_samples/bank_check_v1.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(BankCheckV1::class, $inputSource);
diff --git a/docs/code_samples/barcode_reader_v1.txt b/docs/code_samples/barcode_reader_v1.txt
index 4cc5924a..2075e019 100644
--- a/docs/code_samples/barcode_reader_v1.txt
+++ b/docs/code_samples/barcode_reader_v1.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(BarcodeReaderV1::class, $inputSource);
diff --git a/docs/code_samples/bill_of_lading_v1_async.txt b/docs/code_samples/bill_of_lading_v1_async.txt
index 8d1e4d2f..b277246d 100644
--- a/docs/code_samples/bill_of_lading_v1_async.txt
+++ b/docs/code_samples/bill_of_lading_v1_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(BillOfLadingV1::class, $inputSource);
diff --git a/docs/code_samples/business_card_v1_async.txt b/docs/code_samples/business_card_v1_async.txt
index cac0c8ce..bd9a62a5 100644
--- a/docs/code_samples/business_card_v1_async.txt
+++ b/docs/code_samples/business_card_v1_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(BusinessCardV1::class, $inputSource);
diff --git a/docs/code_samples/carte_grise_v1.txt b/docs/code_samples/carte_grise_v1.txt
index 53779d73..585489aa 100644
--- a/docs/code_samples/carte_grise_v1.txt
+++ b/docs/code_samples/carte_grise_v1.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(CarteGriseV1::class, $inputSource);
diff --git a/docs/code_samples/cropper_v1.txt b/docs/code_samples/cropper_v1.txt
index 684decd9..99fdf2bd 100644
--- a/docs/code_samples/cropper_v1.txt
+++ b/docs/code_samples/cropper_v1.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(CropperV1::class, $inputSource);
diff --git a/docs/code_samples/custom_v1.txt b/docs/code_samples/custom_v1.txt
index 4a19629d..3cacc1d4 100644
--- a/docs/code_samples/custom_v1.txt
+++ b/docs/code_samples/custom_v1.txt
@@ -14,7 +14,7 @@ use Mindee\V1\ClientOptions\PredictMethodOptions;
$mindeeClient = new Client("my-api-key");
// Load a file from disk
-$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Create a custom endpoint
$customEndpoint = $mindeeClient->createEndpoint(
diff --git a/docs/code_samples/default.txt b/docs/code_samples/default.txt
index b6e7b3c4..b917270c 100644
--- a/docs/code_samples/default.txt
+++ b/docs/code_samples/default.txt
@@ -1,6 +1,7 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Create a custom endpoint
$customEndpoint = $mindeeClient->createEndpoint(
diff --git a/docs/code_samples/default_async.txt b/docs/code_samples/default_async.txt
index c1f5e632..d05972b7 100644
--- a/docs/code_samples/default_async.txt
+++ b/docs/code_samples/default_async.txt
@@ -1,6 +1,7 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Create a custom endpoint
$customEndpoint = $mindeeClient->createEndpoint(
diff --git a/docs/code_samples/delivery_notes_v1_async.txt b/docs/code_samples/delivery_notes_v1_async.txt
index e3f7862a..d6716398 100644
--- a/docs/code_samples/delivery_notes_v1_async.txt
+++ b/docs/code_samples/delivery_notes_v1_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(DeliveryNoteV1::class, $inputSource);
diff --git a/docs/code_samples/driver_license_v1_async.txt b/docs/code_samples/driver_license_v1_async.txt
index 1c4d22c6..126c06da 100644
--- a/docs/code_samples/driver_license_v1_async.txt
+++ b/docs/code_samples/driver_license_v1_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(DriverLicenseV1::class, $inputSource);
diff --git a/docs/code_samples/energy_bill_fra_v1_async.txt b/docs/code_samples/energy_bill_fra_v1_async.txt
index 2369c300..35d624a6 100644
--- a/docs/code_samples/energy_bill_fra_v1_async.txt
+++ b/docs/code_samples/energy_bill_fra_v1_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(EnergyBillV1::class, $inputSource);
diff --git a/docs/code_samples/expense_receipts_v5.txt b/docs/code_samples/expense_receipts_v5.txt
index e8d5dcfc..09c31587 100644
--- a/docs/code_samples/expense_receipts_v5.txt
+++ b/docs/code_samples/expense_receipts_v5.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(ReceiptV5::class, $inputSource);
diff --git a/docs/code_samples/expense_receipts_v5_async.txt b/docs/code_samples/expense_receipts_v5_async.txt
index c91066d8..49254892 100644
--- a/docs/code_samples/expense_receipts_v5_async.txt
+++ b/docs/code_samples/expense_receipts_v5_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(ReceiptV5::class, $inputSource);
diff --git a/docs/code_samples/financial_document_v1.txt b/docs/code_samples/financial_document_v1.txt
index d18d8911..71a2087d 100644
--- a/docs/code_samples/financial_document_v1.txt
+++ b/docs/code_samples/financial_document_v1.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(FinancialDocumentV1::class, $inputSource);
diff --git a/docs/code_samples/financial_document_v1_async.txt b/docs/code_samples/financial_document_v1_async.txt
index 6b9ea7d4..045a5572 100644
--- a/docs/code_samples/financial_document_v1_async.txt
+++ b/docs/code_samples/financial_document_v1_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(FinancialDocumentV1::class, $inputSource);
diff --git a/docs/code_samples/french_healthcard_v1_async.txt b/docs/code_samples/french_healthcard_v1_async.txt
index 15d41073..1ee85173 100644
--- a/docs/code_samples/french_healthcard_v1_async.txt
+++ b/docs/code_samples/french_healthcard_v1_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(HealthCardV1::class, $inputSource);
diff --git a/docs/code_samples/idcard_fr_v1.txt b/docs/code_samples/idcard_fr_v1.txt
index e55fafe7..574c3e21 100644
--- a/docs/code_samples/idcard_fr_v1.txt
+++ b/docs/code_samples/idcard_fr_v1.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(IdCardV1::class, $inputSource);
diff --git a/docs/code_samples/idcard_fr_v2.txt b/docs/code_samples/idcard_fr_v2.txt
index 35187fd0..19c20c15 100644
--- a/docs/code_samples/idcard_fr_v2.txt
+++ b/docs/code_samples/idcard_fr_v2.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(IdCardV2::class, $inputSource);
diff --git a/docs/code_samples/ind_passport_v1_async.txt b/docs/code_samples/ind_passport_v1_async.txt
index 7739a3cd..40523afe 100644
--- a/docs/code_samples/ind_passport_v1_async.txt
+++ b/docs/code_samples/ind_passport_v1_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(IndianPassportV1::class, $inputSource);
diff --git a/docs/code_samples/international_id_v2_async.txt b/docs/code_samples/international_id_v2_async.txt
index 82f8c7d6..d3924b9f 100644
--- a/docs/code_samples/international_id_v2_async.txt
+++ b/docs/code_samples/international_id_v2_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(InternationalIdV2::class, $inputSource);
diff --git a/docs/code_samples/invoice_splitter_v1_async.txt b/docs/code_samples/invoice_splitter_v1_async.txt
index 6fdeaf4e..0cca340d 100644
--- a/docs/code_samples/invoice_splitter_v1_async.txt
+++ b/docs/code_samples/invoice_splitter_v1_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(InvoiceSplitterV1::class, $inputSource);
diff --git a/docs/code_samples/invoices_v4.txt b/docs/code_samples/invoices_v4.txt
index 4d6206a5..ecb488a2 100644
--- a/docs/code_samples/invoices_v4.txt
+++ b/docs/code_samples/invoices_v4.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(InvoiceV4::class, $inputSource);
diff --git a/docs/code_samples/invoices_v4_async.txt b/docs/code_samples/invoices_v4_async.txt
index e8ef2341..b2d9d9bd 100644
--- a/docs/code_samples/invoices_v4_async.txt
+++ b/docs/code_samples/invoices_v4_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(InvoiceV4::class, $inputSource);
diff --git a/docs/code_samples/multi_receipts_detector_v1.txt b/docs/code_samples/multi_receipts_detector_v1.txt
index c8c11e31..31ba3e57 100644
--- a/docs/code_samples/multi_receipts_detector_v1.txt
+++ b/docs/code_samples/multi_receipts_detector_v1.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(MultiReceiptsDetectorV1::class, $inputSource);
diff --git a/docs/code_samples/nutrition_facts_v1_async.txt b/docs/code_samples/nutrition_facts_v1_async.txt
index 765f097c..197344e8 100644
--- a/docs/code_samples/nutrition_facts_v1_async.txt
+++ b/docs/code_samples/nutrition_facts_v1_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(NutritionFactsLabelV1::class, $inputSource);
diff --git a/docs/code_samples/passport_v1.txt b/docs/code_samples/passport_v1.txt
index 6968280c..24b47060 100644
--- a/docs/code_samples/passport_v1.txt
+++ b/docs/code_samples/passport_v1.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file
$apiResponse = $mindeeClient->parse(PassportV1::class, $inputSource);
diff --git a/docs/code_samples/payslip_fra_v3_async.txt b/docs/code_samples/payslip_fra_v3_async.txt
index 8e6c9f89..d185d728 100644
--- a/docs/code_samples/payslip_fra_v3_async.txt
+++ b/docs/code_samples/payslip_fra_v3_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(PayslipV3::class, $inputSource);
diff --git a/docs/code_samples/resume_v1_async.txt b/docs/code_samples/resume_v1_async.txt
index 36d9c8b4..5efcda28 100644
--- a/docs/code_samples/resume_v1_async.txt
+++ b/docs/code_samples/resume_v1_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(ResumeV1::class, $inputSource);
diff --git a/docs/code_samples/us_healthcare_cards_v1_async.txt b/docs/code_samples/us_healthcare_cards_v1_async.txt
index bedbf8f2..d0f21100 100644
--- a/docs/code_samples/us_healthcare_cards_v1_async.txt
+++ b/docs/code_samples/us_healthcare_cards_v1_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(HealthcareCardV1::class, $inputSource);
diff --git a/docs/code_samples/us_mail_v3_async.txt b/docs/code_samples/us_mail_v3_async.txt
index 3cc99840..442e74a3 100644
--- a/docs/code_samples/us_mail_v3_async.txt
+++ b/docs/code_samples/us_mail_v3_async.txt
@@ -1,13 +1,14 @@
sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(UsMailV3::class, $inputSource);
diff --git a/docs/code_samples/workflow_execution.txt b/docs/code_samples/workflow_execution.txt
index cf8ca9be..ab95020c 100644
--- a/docs/code_samples/workflow_execution.txt
+++ b/docs/code_samples/workflow_execution.txt
@@ -10,7 +10,7 @@ $workflowId = "workflow-id";
$mindeeClient = new Client("my-api-key");
// Load a file from disk
-$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
// Send the file to the workflow
diff --git a/docs/code_samples/workflow_polling.txt b/docs/code_samples/workflow_polling.txt
index 3271bdaa..5b542eb2 100644
--- a/docs/code_samples/workflow_polling.txt
+++ b/docs/code_samples/workflow_polling.txt
@@ -11,7 +11,7 @@ $workflowId = "workflow-id";
$mindeeClient = new Client("my-api-key");
// Load a file from disk
-$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");
+$inputSource = new PathInput("/path/to/the/file.ext");
$customEndpoint = $mindeeClient->createEndpoint(
"my-endpoint",
diff --git a/src/Error/MindeeHttpClientException.php b/src/Error/MindeeHttpClientException.php
deleted file mode 100644
index f105efc2..00000000
--- a/src/Error/MindeeHttpClientException.php
+++ /dev/null
@@ -1,12 +0,0 @@
-= 400 && $code <= 499) {
- return new MindeeHttpClientException($errorObj, $url, $code);
+ return new self($errorObj, $url, $code);
}
if ($code >= 500 && $code <= 599) {
- return new MindeeHttpClientException($errorObj, $url, $code);
+ return new self($errorObj, $url, $code);
}
return new self($errorObj, $url, $code);
diff --git a/src/Error/MindeeV2HttpException.php b/src/Error/V2/MindeeV2HttpException.php
similarity index 89%
rename from src/Error/MindeeV2HttpException.php
rename to src/Error/V2/MindeeV2HttpException.php
index 75f23d01..21be8d06 100644
--- a/src/Error/MindeeV2HttpException.php
+++ b/src/Error/V2/MindeeV2HttpException.php
@@ -2,10 +2,11 @@
declare(strict_types=1);
-namespace Mindee\Error;
+namespace Mindee\Error\V2;
-use Mindee\V2\Parsing\ErrorItem;
-use Mindee\V2\Parsing\ErrorResponse;
+use Mindee\Error\MindeeException;
+use Mindee\V2\Parsing\Error\ErrorItem;
+use Mindee\V2\Parsing\Error\ErrorResponse;
/**
* Exceptions relating to HTTP errors for the V2 API.
diff --git a/src/Error/MindeeV2HttpUnknownException.php b/src/Error/V2/MindeeV2HttpUnknownException.php
similarity index 89%
rename from src/Error/MindeeV2HttpUnknownException.php
rename to src/Error/V2/MindeeV2HttpUnknownException.php
index 3ab851fc..66bc0c84 100644
--- a/src/Error/MindeeV2HttpUnknownException.php
+++ b/src/Error/V2/MindeeV2HttpUnknownException.php
@@ -2,9 +2,9 @@
declare(strict_types=1);
-namespace Mindee\Error;
+namespace Mindee\Error\V2;
-use Mindee\V2\Parsing\ErrorResponse;
+use Mindee\V2\Parsing\Error\ErrorResponse;
/**
* Unknown HTTP error for the V2 API.
diff --git a/src/Extraction/ExtractedImage.php b/src/Image/ExtractedImage.php
similarity index 99%
rename from src/Extraction/ExtractedImage.php
rename to src/Image/ExtractedImage.php
index 5ba66a81..794cc2d7 100644
--- a/src/Extraction/ExtractedImage.php
+++ b/src/Image/ExtractedImage.php
@@ -2,13 +2,13 @@
declare(strict_types=1);
-namespace Mindee\Extraction;
+namespace Mindee\Image;
+use Imagick;
+use ImagickException;
use Mindee\Dependency\DependencyChecker;
use Mindee\Error\MindeeUnhandledException;
use Mindee\Input\BytesInput;
-use Imagick;
-use ImagickException;
use function in_array;
diff --git a/src/Extraction/ImageExtractor.php b/src/Image/ImageExtractor.php
similarity index 99%
rename from src/Extraction/ImageExtractor.php
rename to src/Image/ImageExtractor.php
index 764922e4..6d72ebb6 100644
--- a/src/Extraction/ImageExtractor.php
+++ b/src/Image/ImageExtractor.php
@@ -2,9 +2,11 @@
declare(strict_types=1);
-namespace Mindee\Extraction;
+namespace Mindee\Image;
use Exception;
+use Imagick;
+use ImagickException;
use Mindee\Dependency\DependencyChecker;
use Mindee\Error\ErrorCode;
use Mindee\Error\MindeeGeometryException;
@@ -16,8 +18,6 @@
use Mindee\Geometry\Polygon;
use Mindee\Input\LocalInputSource;
use Mindee\V1\Parsing\Standard\BaseField;
-use Imagick;
-use ImagickException;
use function count;
use function sprintf;
diff --git a/src/Input/Base64Input.php b/src/Input/Base64Input.php
index cadbcbe3..72c62860 100644
--- a/src/Input/Base64Input.php
+++ b/src/Input/Base64Input.php
@@ -19,8 +19,9 @@ class Base64Input extends LocalInputSource
/**
* @param string $strBase64 Raw data as a base64-encoded string.
* @param string $fileName File name of the input.
+ * @param boolean $fixPdf Whether to try to fix a broken PDF.
*/
- public function __construct(string $strBase64, string $fileName)
+ public function __construct(string $strBase64, string $fileName, bool $fixPdf = false)
{
$this->tempFile = tempnam(sys_get_temp_dir(), 'b64_');
$this->fileName = $fileName;
@@ -29,7 +30,7 @@ public function __construct(string $strBase64, string $fileName)
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$this->fileMimetype = finfo_buffer($finfo, base64_decode($strBase64, true));
$this->fileObject = new CURLFile($this->tempFile, $this->fileMimetype, $this->fileName);
- parent::__construct();
+ parent::__construct($fixPdf);
}
diff --git a/src/Input/BytesInput.php b/src/Input/BytesInput.php
index bc5ad5b4..c427f995 100644
--- a/src/Input/BytesInput.php
+++ b/src/Input/BytesInput.php
@@ -19,8 +19,9 @@ class BytesInput extends LocalInputSource
/**
* @param string $fileBytes Raw data as bytes.
* @param string $fileName File name of the input.
+ * @param boolean $fixPdf Whether to try to fix a broken PDF.
*/
- public function __construct(string $fileBytes, string $fileName)
+ public function __construct(string $fileBytes, string $fileName, bool $fixPdf = false)
{
$this->tempFile = tempnam(sys_get_temp_dir(), 'b64_');
$this->fileName = $fileName;
@@ -29,7 +30,7 @@ public function __construct(string $fileBytes, string $fileName)
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$this->fileMimetype = finfo_buffer($finfo, $fileBytes);
$this->fileObject = new CURLFile($this->tempFile, $this->fileMimetype, $this->fileName);
- parent::__construct();
+ parent::__construct($fixPdf);
}
diff --git a/src/Input/FileInput.php b/src/Input/FileInput.php
index f2bbff0e..5f725b4b 100644
--- a/src/Input/FileInput.php
+++ b/src/Input/FileInput.php
@@ -20,15 +20,16 @@ class FileInput extends LocalInputSource
/**
* @param resource &$file File reference.
+ * @param boolean $fixPdf Whether to try to fix a broken PDF.
*/
- public function __construct(&$file)
+ public function __construct(&$file, bool $fixPdf = false)
{
$this->file = &$file;
$this->filePath = stream_get_meta_data($this->file)['uri'];
$this->fileName = basename($this->filePath);
$this->fileMimetype = mime_content_type($this->filePath);
$this->fileObject = new CURLFile($this->filePath, $this->fileName, $this->fileMimetype);
- parent::__construct();
+ parent::__construct($fixPdf);
}
/**
diff --git a/src/Input/LocalInputSource.php b/src/Input/LocalInputSource.php
index 9963f2b0..d53b6b72 100644
--- a/src/Input/LocalInputSource.php
+++ b/src/Input/LocalInputSource.php
@@ -97,9 +97,13 @@ private function checkMimeType(): void
/**
* Base constructor, mostly used for Mime type checking.
+ * @param boolean $fixPdf Whether to attempt to fix the PDF.
*/
- public function __construct()
+ public function __construct(bool $fixPdf = false)
{
+ if ($fixPdf) {
+ $this->fixPdf();
+ }
$this->checkMimeType();
}
diff --git a/src/Input/PathInput.php b/src/Input/PathInput.php
index c41a4f93..648bedca 100644
--- a/src/Input/PathInput.php
+++ b/src/Input/PathInput.php
@@ -13,8 +13,9 @@ class PathInput extends LocalInputSource
{
/**
* @param string $filePath Path to open.
+ * @param boolean $fixPdf Whether to try to fix a broken PDF.
*/
- public function __construct(string $filePath)
+ public function __construct(string $filePath, bool $fixPdf = false)
{
$this->filePath = $filePath;
$this->fileName = basename($filePath);
@@ -24,6 +25,6 @@ public function __construct(string $filePath)
$this->fileMimetype = $mimeType;
$this->fileObject = new CURLFile($this->filePath, $mimeType, $this->fileName);
finfo_close($file);
- parent::__construct();
+ parent::__construct($fixPdf);
}
}
diff --git a/src/Extraction/ExtractedPdf.php b/src/Pdf/ExtractedPdf.php
similarity index 98%
rename from src/Extraction/ExtractedPdf.php
rename to src/Pdf/ExtractedPdf.php
index ba738442..d23f3f67 100644
--- a/src/Extraction/ExtractedPdf.php
+++ b/src/Pdf/ExtractedPdf.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Mindee\Extraction;
+namespace Mindee\Pdf;
use Mindee\Dependency\DependencyChecker;
use Mindee\Error\ErrorCode;
diff --git a/src/Extraction/PdfExtractor.php b/src/Pdf/PdfExtractor.php
similarity index 99%
rename from src/Extraction/PdfExtractor.php
rename to src/Pdf/PdfExtractor.php
index 25bf10cb..d819bda9 100644
--- a/src/Extraction/PdfExtractor.php
+++ b/src/Pdf/PdfExtractor.php
@@ -2,8 +2,11 @@
declare(strict_types=1);
-namespace Mindee\Extraction;
+namespace Mindee\Pdf;
+use Imagick;
+use ImagickException;
+use InvalidArgumentException;
use Mindee\Dependency\DependencyChecker;
use Mindee\Error\MindeePdfException;
use Mindee\Input\LocalInputSource;
@@ -13,9 +16,6 @@
use setasign\Fpdi\PdfParser\Filter\FilterException;
use setasign\Fpdi\PdfParser\PdfParserException;
use setasign\Fpdi\PdfReader\PdfReaderException;
-use Imagick;
-use ImagickException;
-use InvalidArgumentException;
use function count;
use function is_array;
diff --git a/src/V1/Client.php b/src/V1/Client.php
index b187b962..21b8a02a 100644
--- a/src/V1/Client.php
+++ b/src/V1/Client.php
@@ -10,24 +10,18 @@
namespace Mindee\V1;
-use CURLFile;
use Exception;
use Mindee\ClientOptions\PollingOptions;
use Mindee\CustomSleepMixin;
use Mindee\Error\ErrorCode;
use Mindee\Error\MindeeApiException;
-use Mindee\Error\MindeeClientException;
use Mindee\Error\MindeeException;
-use Mindee\Error\MindeeHttpException;
-use Mindee\Input\Base64Input;
-use Mindee\Input\BytesInput;
-use Mindee\Input\FileInput;
+use Mindee\Error\V1\MindeeV1ClientException;
+use Mindee\Error\V1\MindeeV1HttpException;
use Mindee\Input\InputSource;
use Mindee\Input\LocalInputSource;
use Mindee\Input\LocalResponse;
use Mindee\Input\PageOptions;
-use Mindee\Input\PathInput;
-use Mindee\Input\UrlInputSource;
use Mindee\V1\ClientOptions\PredictMethodOptions;
use Mindee\V1\ClientOptions\WorkflowOptions;
use Mindee\V1\Http\Endpoint;
@@ -41,9 +35,6 @@
use Mindee\V1\Product\Generated\GeneratedV1;
use ReflectionClass;
use ReflectionException;
-use SplFileObject;
-
-use function strlen;
/**
* Main entrypoint for Mindee operations.
@@ -73,78 +64,6 @@ public function __construct(?string $apiKey = null)
$this->apiKey = $apiKey ?: getenv('MINDEE_API_KEY');
}
- /**
- * Load a document from an absolute path, as a string.
- *
- * @param string $filePath Path of the file.
- * @param boolean $fixPdf Whether the PDF should be fixed or not.
- */
- public function sourceFromPath(string $filePath, bool $fixPdf = false): PathInput
- {
- $input = new PathInput($filePath);
- if ($fixPdf) {
- $input->fixPdf();
- }
- return $input;
- }
-
- /**
- * Load a document from a normal PHP file object.
- *
- * @param SplFileObject|CURLFile|string|resource $file File object as created from the file() function.
- * @param boolean $fixPdf Whether the PDF should be fixed or not.
- */
- public function sourceFromFile(mixed $file, bool $fixPdf = false): FileInput
- {
- $input = new FileInput($file);
- if ($fixPdf) {
- $input->fixPdf();
- }
- return $input;
- }
-
- /**
- * Load a document from raw bytes.
- *
- * @param string $fileBytes File object in raw bytes.
- * @param string $fileName File name, mandatory.
- * @param boolean $fixPdf Whether the PDF should be fixed or not.
- */
- public function sourceFromBytes(string $fileBytes, string $fileName, bool $fixPdf = false): BytesInput
- {
- $input = new BytesInput($fileBytes, $fileName);
- if ($fixPdf) {
- $input->fixPdf();
- }
- return $input;
- }
-
- /**
- * Load a document from a base64 encoded string.
- *
- * @param string $fileB64 File object in Base64.
- * @param string $fileName File name, mandatory.
- * @param boolean $fixPdf Whether the PDF should be fixed or not.
- */
- public function sourceFromB64String(string $fileB64, string $fileName, bool $fixPdf = false): Base64Input
- {
- $input = new Base64Input($fileB64, $fileName);
- if ($fixPdf) {
- $input->fixPdf();
- }
- return $input;
- }
-
- /**
- * Load a document from an URL.
- *
- * @param string $url File URL. Must start with "https://".
- */
- public function sourceFromUrl(string $url): UrlInputSource
- {
- return new UrlInputSource($url);
- }
-
/**
* Builds a custom endpoint.
*
@@ -216,12 +135,12 @@ private function constructOTSEndpoint(string $product): Endpoint
* @param string $endpointName URL of the endpoint.
* @param string $accountName Name of the endpoint's owner.
* @param string|null $version Version of the endpoint.
- * @throws MindeeClientException Throws if a custom endpoint name isn't provided.
+ * @throws MindeeV1ClientException Throws if a custom endpoint name isn't provided.
*/
public function createEndpoint(string $endpointName, string $accountName, ?string $version = null): Endpoint
{
if (mb_strlen($endpointName, "UTF-8") === 0) {
- throw new MindeeClientException(
+ throw new MindeeV1ClientException(
"Custom endpoint requires a valid 'endpoint_name'.",
ErrorCode::USER_INPUT_ERROR
);
@@ -251,7 +170,7 @@ private function cutDocPages(LocalInputSource $inputDoc, PageOptions $pageOption
* @param string $predictionType Name of the product's class.
* @param string $queueId ID of the queue.
* @param Endpoint $endpoint Endpoint to poll.
- * @throws MindeeHttpException Throws if the API sent an error.
+ * @throws MindeeV1HttpException Throws if the API sent an error.
*/
private function makeParseQueuedRequest(
string $predictionType,
@@ -260,7 +179,7 @@ private function makeParseQueuedRequest(
): AsyncPredictResponse {
$queuedResponse = ResponseValidation::cleanRequestData($endpoint->documentQueueReqGet($queueId));
if (!ResponseValidation::isValidAsyncResponse($queuedResponse)) {
- throw MindeeHttpException::handleError(
+ throw MindeeV1HttpException::handleError(
$endpoint->settings->endpointName,
$queuedResponse
);
@@ -274,7 +193,7 @@ private function makeParseQueuedRequest(
* @param string $predictionType Name of the product's class.
* @param InputSource $inputDoc Input file.
* @param PredictMethodOptions $options Prediction Options.
- * @throws MindeeHttpException Throws if the API sent an error.
+ * @throws MindeeV1HttpException Throws if the API sent an error.
* @throws MindeeApiException Throws if one attempts to edit remote resources.
*/
private function makeEnqueueRequest(
@@ -299,7 +218,7 @@ private function makeEnqueueRequest(
)
);
if (!ResponseValidation::isValidAsyncResponse($response)) {
- throw MindeeHttpException::handleError(
+ throw MindeeV1HttpException::handleError(
$options->endpoint->settings->endpointName,
$response
);
@@ -314,7 +233,7 @@ private function makeEnqueueRequest(
* @param InputSource $inputDoc Input file.
* @param string $workflowId ID of the workflow.
* @param PredictMethodOptions $options Prediction Options.
- * @throws MindeeHttpException Throws if the API sent an error.
+ * @throws MindeeV1HttpException Throws if the API sent an error.
* @throws MindeeApiException Throws if the API sent an error,
* or if the prediction type isn't recognized or if a field can't be deserialized.
*/
@@ -341,7 +260,7 @@ private function makeWorkflowExecutionRequest(
$options->workflowOptions
));
if (!ResponseValidation::isValidWorkflowResponse($response)) {
- throw MindeeHttpException::handleError(
+ throw MindeeV1HttpException::handleError(
"workflows/$workflowId/executions",
$response
);
@@ -363,7 +282,7 @@ private function makeWorkflowExecutionRequest(
* @param string $predictionType Name of the product's class.
* @param InputSource $inputDoc Input file.
* @param PredictMethodOptions $options Prediction Options.
- * @throws MindeeHttpException Throws if the API sent an error.
+ * @throws MindeeV1HttpException Throws if the API sent an error.
* @throws MindeeApiException Throws if one attempts to edit remote resources.
*/
private function makeParseRequest(
@@ -386,7 +305,7 @@ private function makeParseRequest(
$options,
));
if (!ResponseValidation::isValidSyncResponse($response)) {
- throw MindeeHttpException::handleError(
+ throw MindeeV1HttpException::handleError(
$options->endpoint->settings->endpointName,
$response
);
diff --git a/src/V1/Image/ImageExtractor.php b/src/V1/Image/ImageExtractor.php
index 04ae6de3..aa8a88d7 100644
--- a/src/V1/Image/ImageExtractor.php
+++ b/src/V1/Image/ImageExtractor.php
@@ -4,7 +4,7 @@
namespace Mindee\V1\Image;
-use Mindee\Extraction\ImageExtractor as BaseImageExtractor;
+use Mindee\Image\ImageExtractor as BaseImageExtractor;
/**
* Wrapper class for V1 of the BaseImageExtractor.
diff --git a/src/V2/Client.php b/src/V2/Client.php
index 649bb553..5b0e57d6 100644
--- a/src/V2/Client.php
+++ b/src/V2/Client.php
@@ -11,8 +11,7 @@
use Mindee\V2\ClientOptions\BaseParameters;
use Mindee\V2\Http\MindeeApiV2;
use Mindee\V2\Parsing\Inference\BaseResponse;
-use Mindee\V2\Parsing\JobResponse;
-use Mindee\V2\Product\Extraction\Params\ExtractionParameters;
+use Mindee\V2\Parsing\Job\JobResponse;
/**
* Mindee Client V2.
@@ -36,22 +35,6 @@ public function __construct(?string $apiKey = null)
$this->mindeeApi = new MindeeApiV2($apiKey ?: getenv('MINDEE_V2_API_KEY'));
}
- /**
- * Send the document to an asynchronous endpoint and return its ID in the queue.
- *
- * @param InputSource $inputSource File to parse.
- * @param ExtractionParameters $params Parameters relating to prediction options.
- * @return JobResponse A JobResponse containing the job (queue) corresponding to a document.
- * @throws MindeeException Throws if the input document is not provided.
- * @category Asynchronous
- */
- public function enqueueInference(
- InputSource $inputSource,
- ExtractionParameters $params
- ): JobResponse {
- return $this->enqueue($inputSource, $params);
- }
-
/**
* Send the document to an asynchronous endpoint and return its ID in the queue.
* @param InputSource $inputSource File to parse.
diff --git a/src/V2/FileOperations/Crop.php b/src/V2/FileOperations/Crop.php
index 1240d982..2004e009 100644
--- a/src/V2/FileOperations/Crop.php
+++ b/src/V2/FileOperations/Crop.php
@@ -4,8 +4,8 @@
namespace Mindee\V2\FileOperations;
-use Mindee\Extraction\ExtractedImage;
-use Mindee\Extraction\ImageExtractor;
+use Mindee\Image\ExtractedImage;
+use Mindee\Image\ImageExtractor;
use Mindee\Input\LocalInputSource;
use Mindee\V2\Product\Crop\CropItem;
diff --git a/src/V2/FileOperations/CropFiles.php b/src/V2/FileOperations/CropFiles.php
index 9f522535..c493a1c9 100644
--- a/src/V2/FileOperations/CropFiles.php
+++ b/src/V2/FileOperations/CropFiles.php
@@ -4,10 +4,10 @@
namespace Mindee\V2\FileOperations;
-use Mindee\Error\MindeeException;
-use Mindee\Extraction\ExtractedImage;
use ArrayObject;
use ImagickException;
+use Mindee\Error\MindeeException;
+use Mindee\Image\ExtractedImage;
use function sprintf;
diff --git a/src/V2/FileOperations/Split.php b/src/V2/FileOperations/Split.php
index a8a55689..eff71136 100644
--- a/src/V2/FileOperations/Split.php
+++ b/src/V2/FileOperations/Split.php
@@ -5,9 +5,9 @@
namespace Mindee\V2\FileOperations;
use Mindee\Error\MindeeInputException;
-use Mindee\Extraction\ExtractedPdf;
-use Mindee\Extraction\PdfExtractor;
use Mindee\Input\LocalInputSource;
+use Mindee\Pdf\ExtractedPdf;
+use Mindee\Pdf\PdfExtractor;
/**
* V2 Split operation.
diff --git a/src/V2/FileOperations/SplitFiles.php b/src/V2/FileOperations/SplitFiles.php
index 20a8146c..a8c2b1bd 100644
--- a/src/V2/FileOperations/SplitFiles.php
+++ b/src/V2/FileOperations/SplitFiles.php
@@ -4,10 +4,10 @@
namespace Mindee\V2\FileOperations;
-use Mindee\Error\MindeeException;
-use Mindee\Extraction\ExtractedPdf;
use ArrayObject;
use Exception;
+use Mindee\Error\MindeeException;
+use Mindee\Pdf\ExtractedPdf;
use function sprintf;
diff --git a/src/V2/Http/MindeeApiV2.php b/src/V2/Http/MindeeApiV2.php
index 34e86328..2d3fbfa1 100644
--- a/src/V2/Http/MindeeApiV2.php
+++ b/src/V2/Http/MindeeApiV2.php
@@ -13,15 +13,15 @@
use Mindee\Error\ErrorCode;
use Mindee\Error\MindeeApiException;
use Mindee\Error\MindeeException;
-use Mindee\Error\MindeeV2HttpException;
-use Mindee\Error\MindeeV2HttpUnknownException;
+use Mindee\Error\V2\MindeeV2HttpException;
+use Mindee\Error\V2\MindeeV2HttpUnknownException;
use Mindee\Input\InputSource;
use Mindee\Input\LocalInputSource;
use Mindee\Input\UrlInputSource;
use Mindee\V2\ClientOptions\BaseParameters;
-use Mindee\V2\Parsing\ErrorResponse;
+use Mindee\V2\Parsing\Error\ErrorResponse;
use Mindee\V2\Parsing\Inference\BaseResponse;
-use Mindee\V2\Parsing\JobResponse;
+use Mindee\V2\Parsing\Job\JobResponse;
use ReflectionClass;
use ReflectionException;
use ReflectionProperty;
diff --git a/src/V2/Parsing/ErrorItem.php b/src/V2/Parsing/Error/ErrorItem.php
similarity index 94%
rename from src/V2/Parsing/ErrorItem.php
rename to src/V2/Parsing/Error/ErrorItem.php
index 13e0fe52..2c85757d 100644
--- a/src/V2/Parsing/ErrorItem.php
+++ b/src/V2/Parsing/Error/ErrorItem.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Mindee\V2\Parsing;
+namespace Mindee\V2\Parsing\Error;
/**
* Explicit details on a problem.
diff --git a/src/V2/Parsing/ErrorResponse.php b/src/V2/Parsing/Error/ErrorResponse.php
similarity index 97%
rename from src/V2/Parsing/ErrorResponse.php
rename to src/V2/Parsing/Error/ErrorResponse.php
index fd1236f1..9279eb70 100644
--- a/src/V2/Parsing/ErrorResponse.php
+++ b/src/V2/Parsing/Error/ErrorResponse.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Mindee\V2\Parsing;
+namespace Mindee\V2\Parsing\Error;
use function is_array;
diff --git a/src/V2/Parsing/BaseInference.php b/src/V2/Parsing/Inference/BaseInference.php
similarity index 88%
rename from src/V2/Parsing/BaseInference.php
rename to src/V2/Parsing/Inference/BaseInference.php
index 5d39473a..38844531 100644
--- a/src/V2/Parsing/BaseInference.php
+++ b/src/V2/Parsing/Inference/BaseInference.php
@@ -2,12 +2,9 @@
declare(strict_types=1);
-namespace Mindee\V2\Parsing;
+namespace Mindee\V2\Parsing\Inference;
use Mindee\Parsing\SummaryHelper;
-use Mindee\V2\Parsing\Inference\InferenceFile;
-use Mindee\V2\Parsing\Inference\InferenceJob;
-use Mindee\V2\Parsing\Inference\InferenceModel;
use Stringable;
/**
diff --git a/src/V2/Parsing/Job.php b/src/V2/Parsing/Job/Job.php
similarity index 97%
rename from src/V2/Parsing/Job.php
rename to src/V2/Parsing/Job/Job.php
index 3957e17f..982853c4 100644
--- a/src/V2/Parsing/Job.php
+++ b/src/V2/Parsing/Job/Job.php
@@ -2,10 +2,11 @@
declare(strict_types=1);
-namespace Mindee\V2\Parsing;
+namespace Mindee\V2\Parsing\Job;
use DateTime;
use Exception;
+use Mindee\V2\Parsing\Error\ErrorResponse;
use function array_key_exists;
diff --git a/src/V2/Parsing/JobResponse.php b/src/V2/Parsing/Job/JobResponse.php
similarity index 94%
rename from src/V2/Parsing/JobResponse.php
rename to src/V2/Parsing/Job/JobResponse.php
index 21a8fc0d..babc7259 100644
--- a/src/V2/Parsing/JobResponse.php
+++ b/src/V2/Parsing/Job/JobResponse.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Mindee\V2\Parsing;
+namespace Mindee\V2\Parsing\Job;
use Mindee\V2\Parsing\Inference\BaseResponse;
diff --git a/src/V2/Parsing/JobWebhook.php b/src/V2/Parsing/Job/JobWebhook.php
similarity index 94%
rename from src/V2/Parsing/JobWebhook.php
rename to src/V2/Parsing/Job/JobWebhook.php
index 3205c2ce..e12d5ccf 100644
--- a/src/V2/Parsing/JobWebhook.php
+++ b/src/V2/Parsing/Job/JobWebhook.php
@@ -2,10 +2,11 @@
declare(strict_types=1);
-namespace Mindee\V2\Parsing;
+namespace Mindee\V2\Parsing\Job;
use DateTime;
use Exception;
+use Mindee\V2\Parsing\Error\ErrorResponse;
/**
* JobWebhook information.
diff --git a/src/V2/Product/Classification/ClassificationInference.php b/src/V2/Product/Classification/ClassificationInference.php
index 3d34cf36..58fefb3a 100644
--- a/src/V2/Product/Classification/ClassificationInference.php
+++ b/src/V2/Product/Classification/ClassificationInference.php
@@ -5,7 +5,7 @@
namespace Mindee\V2\Product\Classification;
use Mindee\Parsing\SummaryHelper;
-use Mindee\V2\Parsing\BaseInference;
+use Mindee\V2\Parsing\Inference\BaseInference;
/**
* Classification inference result.
diff --git a/src/V2/Product/Crop/CropInference.php b/src/V2/Product/Crop/CropInference.php
index b0472c24..d83717be 100644
--- a/src/V2/Product/Crop/CropInference.php
+++ b/src/V2/Product/Crop/CropInference.php
@@ -4,7 +4,7 @@
namespace Mindee\V2\Product\Crop;
-use Mindee\V2\Parsing\BaseInference;
+use Mindee\V2\Parsing\Inference\BaseInference;
/**
* The inference result for a crop utility request.
diff --git a/src/V2/Product/Extraction/ExtractionInference.php b/src/V2/Product/Extraction/ExtractionInference.php
index 2ef76ce2..bf4b5fb7 100644
--- a/src/V2/Product/Extraction/ExtractionInference.php
+++ b/src/V2/Product/Extraction/ExtractionInference.php
@@ -5,7 +5,7 @@
namespace Mindee\V2\Product\Extraction;
use Mindee\Parsing\SummaryHelper;
-use Mindee\V2\Parsing\BaseInference;
+use Mindee\V2\Parsing\Inference\BaseInference;
use Mindee\V2\Parsing\Inference\InferenceActiveOptions;
/**
diff --git a/src/V2/Product/Ocr/OcrInference.php b/src/V2/Product/Ocr/OcrInference.php
index cfe2fc9d..d5dbaa44 100644
--- a/src/V2/Product/Ocr/OcrInference.php
+++ b/src/V2/Product/Ocr/OcrInference.php
@@ -4,7 +4,7 @@
namespace Mindee\V2\Product\Ocr;
-use Mindee\V2\Parsing\BaseInference;
+use Mindee\V2\Parsing\Inference\BaseInference;
/**
* Response for an Ocr utility inference.
diff --git a/src/V2/Product/Split/SplitInference.php b/src/V2/Product/Split/SplitInference.php
index bf72acc4..3acdab73 100644
--- a/src/V2/Product/Split/SplitInference.php
+++ b/src/V2/Product/Split/SplitInference.php
@@ -4,7 +4,7 @@
namespace Mindee\V2\Product\Split;
-use Mindee\V2\Parsing\BaseInference;
+use Mindee\V2\Parsing\Inference\BaseInference;
/**
* The inference result for a split utility request.
diff --git a/tests/ClientTest.php b/tests/ClientTest.php
index f85c1176..262dd542 100644
--- a/tests/ClientTest.php
+++ b/tests/ClientTest.php
@@ -4,10 +4,12 @@
use Mindee\ClientOptions\PollingOptions;
use Mindee\Error\MindeeApiException;
-use Mindee\Error\MindeeHttpClientException;
-use Mindee\Error\MindeeHttpException;
+use Mindee\Error\MindeeMimeTypeException;
+use Mindee\Error\V1\MindeeV1HttpException;
use Mindee\Input\LocalResponse;
use Mindee\Input\PageOptions;
+use Mindee\Input\PathInput;
+use Mindee\Input\UrlInputSource;
use Mindee\V1\Client;
use Mindee\V1\ClientOptions\PredictMethodOptions;
use Mindee\V1\Product\Generated\GeneratedV1;
@@ -16,7 +18,6 @@
use Mindee\V1\Product\MultiReceiptsDetector\MultiReceiptsDetectorV1;
use Mindee\V1\Product\Receipt\ReceiptV5;
use PHPUnit\Framework\TestCase;
-use Mindee\Error\MindeeMimeTypeException;
class ClientTest extends TestCase
{
@@ -52,17 +53,17 @@ protected function tearDown(): void
public function testParsePathWithoutToken(): void
{
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
- $inputDoc = $this->emptyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
+ $inputDoc = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
$this->emptyClient->parse(InvoiceV4::class, $inputDoc);
}
public function testParsePathWithEnvToken(): void
{
- $this->expectException(MindeeHttpException::class);
+ $this->expectException(MindeeV1HttpException::class);
- $inputDoc = $this->envClient->sourceFromPath(TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
+ $inputDoc = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
$this->envClient->parse(InvoiceV4::class, $inputDoc);
}
@@ -70,25 +71,25 @@ public function testParsePathWithWrongFileType(): void
{
$this->expectException(MindeeMimeTypeException::class);
- $inputDoc = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . "/receipt.txt");
+ new PathInput(TestingUtilities::getFileTypesDir() . "/receipt.txt");
}
public function testParsePathWithWrongToken(): void
{
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
- $inputDoc = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
+ $inputDoc = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
$this->dummyClient->parse(InvoiceV4::class, $inputDoc);
}
public function testInterfaceVersion(): void
{
$dummyEndpoint = $this->dummyClient->createEndpoint("dummy", "dummy", "1.1");
- $inputDoc = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
+ $inputDoc = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
$predictOptions = new PredictMethodOptions();
self::assertSame("1.1", $dummyEndpoint->settings->version);
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
$this->dummyClient->parse(
GeneratedV1::class,
$inputDoc,
@@ -98,8 +99,8 @@ public function testInterfaceVersion(): void
public function testCutOptions(): void
{
- $inputDoc = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf");
- $this->expectException(MindeeHttpClientException::class);
+ $inputDoc = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf");
+ $this->expectException(MindeeV1HttpException::class);
$pageOptions = new PageOptions(range(0, 4));
$this->dummyClient->parse(ReceiptV5::class, $inputDoc, null, $pageOptions);
self::assertSame(5, $inputDoc->getPageCount());
@@ -125,7 +126,7 @@ public function testPredictOptionsWrongInputType(): void
self::assertFalse($pageOptions->isEmpty());
$predictOptions = new PredictMethodOptions();
$predictOptions->setPageOptions($pageOptions);
- $urlInputSource = $this->dummyClient->sourceFromUrl("https://dummy");
+ $urlInputSource = new UrlInputSource("https://dummy");
$this->expectException(MindeeApiException::class);
$this->dummyClient->parse(InvoiceV4::class, $urlInputSource, $predictOptions);
$this->expectException(MindeeApiException::class);
@@ -136,10 +137,10 @@ public function testPredictOptionsValidInputType(): void
{
$predictOptions = new PredictMethodOptions();
self::assertTrue($predictOptions->pageOptions->isEmpty());
- $inputDoc = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
- $this->expectException(MindeeHttpClientException::class);
+ $inputDoc = new PathInput(TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf");
+ $this->expectException(MindeeV1HttpException::class);
$this->dummyClient->parse(InvoiceV4::class, $inputDoc, $predictOptions);
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
$this->dummyClient->enqueue(InvoiceSplitterV1::class, $inputDoc, $predictOptions);
}
diff --git a/tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php b/tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php
index 89873d95..09431aae 100644
--- a/tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php
+++ b/tests/Dependencies/DependencyCheckerNoExtendedTestPdf.php
@@ -4,16 +4,15 @@
namespace Dependencies;
+use Imagick;
use Mindee\Error\MindeeUnhandledException;
-use Mindee\Extraction\ExtractedImage;
-use Mindee\Extraction\ExtractedPdf;
-use Mindee\V1\Image\ImageExtractor;
-use Mindee\Extraction\PdfExtractor;
+use Mindee\Image\ExtractedImage;
use Mindee\Input\PathInput;
+use Mindee\Pdf\ExtractedPdf;
+use Mindee\Pdf\PdfExtractor;
+use Mindee\V1\Image\ImageExtractor;
use PHPUnit\Framework\TestCase;
use TestingUtilities;
-use Imagick;
-use stdClass;
require_once(__DIR__ . "/../TestingUtilities.php");
diff --git a/tests/Input/LocalInputSourceTest.php b/tests/Input/LocalInputSourceTest.php
index 51637a4a..4ab994f4 100644
--- a/tests/Input/LocalInputSourceTest.php
+++ b/tests/Input/LocalInputSourceTest.php
@@ -217,29 +217,29 @@ public function testShouldNotRaiseMimeErrorForBrokenFixablePdf(): void
{
$this->expectNotToPerformAssertions();
- $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . '/pdf/broken_fixable.pdf', true);
+ new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_fixable.pdf', true);
}
public function testShouldRaiseErrorForBrokenUnfixablePdf(): void
{
$this->expectException(MindeeSourceException::class);
- $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . '/pdf/broken_unfixable.pdf', true);
+ new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_unfixable.pdf', true);
}
public function testShouldSendCorrectResultsForBrokenFixableInvoicePdf(): void
{
- $sourceDocOriginal = $this->dummyClient->sourceFromPath(
+ $sourceDocOriginal = new PathInput(
TestingUtilities::getV1DataDir() . '/products/invoices/invoice.pdf'
);
- $sourceDocFixed = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . '/pdf/broken_invoice.pdf', true);
+ $sourceDocFixed = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_invoice.pdf', true);
self::assertSame($sourceDocFixed->readContents()[1], $sourceDocOriginal->readContents()[1]);
}
public function testImageQualityCompressionFromInputSource(): void
{
- $receiptInput = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . '/receipt.jpg');
+ $receiptInput = new PathInput(TestingUtilities::getFileTypesDir() . '/receipt.jpg');
$receiptInput->compress(80);
file_put_contents(
TestingUtilities::getRootDataDir() . "/output/compress_indirect.jpg",
@@ -252,7 +252,7 @@ public function testImageQualityCompressionFromInputSource(): void
public function testDirectImageQualityCompression(): void
{
- $receiptInput = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . '/receipt.jpg');
+ $receiptInput = new PathInput(TestingUtilities::getFileTypesDir() . '/receipt.jpg');
$sizeOriginal = filesize(TestingUtilities::getFileTypesDir() . '/receipt.jpg');
$compresses = [
100 => ImageCompressor::compress($receiptInput->fileObject, 100),
@@ -287,9 +287,9 @@ public function testDirectImageQualityCompression(): void
public function testPdfSourceText(): void
{
- $imageInput = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . '/receipt.jpg');
- $pdfEmptyInput = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf');
- $pdfSourceText = $this->dummyClient->sourceFromPath(TestingUtilities::getFileTypesDir() . '/pdf/multipage.pdf');
+ $imageInput = new PathInput(TestingUtilities::getFileTypesDir() . '/receipt.jpg');
+ $pdfEmptyInput = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf');
+ $pdfSourceText = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage.pdf');
self::assertTrue($pdfSourceText->hasSourceText(), "Source text should be properly detected.");
self::assertFalse($pdfEmptyInput->hasSourceText(), "Empty PDFs should not have source text detected.");
self::assertFalse($imageInput->hasSourceText(), "An image should not have any text.");
@@ -297,7 +297,7 @@ public function testPdfSourceText(): void
public function testCompressPdfFromInputSource(): void
{
- $pdfInput = $this->dummyClient->sourceFromPath(
+ $pdfInput = new PathInput(
TestingUtilities::getFileTypesDir() . "/pdf/not_blank_image_only.pdf"
);
self::assertFalse($pdfInput->hasSourceText());
@@ -321,7 +321,7 @@ public function testCompressPdfFromInputSource(): void
public function testCompressPdfFromCompressor(): void
{
- $pdfInput = $this->dummyClient->sourceFromPath(
+ $pdfInput = new PathInput(
TestingUtilities::getV1DataDir() . '/products/invoice_splitter/default_sample.pdf'
);
$sizeOriginal = filesize(TestingUtilities::getV1DataDir() . '/products/invoice_splitter/default_sample.pdf');
@@ -357,7 +357,7 @@ public function testCompressPdfFromCompressor(): void
public function testSourceTextPdfCompression(): void
{
- $pdfInput = $this->dummyClient->sourceFromPath(
+ $pdfInput = new PathInput(
TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"
);
diff --git a/tests/Input/UrlInputSourceTest.php b/tests/Input/UrlInputSourceTest.php
index 272a9611..c8ce60b5 100644
--- a/tests/Input/UrlInputSourceTest.php
+++ b/tests/Input/UrlInputSourceTest.php
@@ -29,7 +29,7 @@ protected function tearDown(): void
public function testInputFromHttpShouldNotThrow(): void
{
- $inputDoc = $this->dummyClient->sourceFromUrl("https://example.com/invoice.pdf");
+ $inputDoc = new UrlInputSource("https://example.com/invoice.pdf");
self::assertInstanceOf(UrlInputSource::class, $inputDoc);
}
@@ -42,7 +42,7 @@ public function testInputFromHttpShouldThrow(): void
public function testDownloadFileFails(): void
{
$dummyAddress = "addressthatdoesntworkforcipurposes";
- $urlSource = $this->dummyClient->sourceFromUrl("https://$dummyAddress");
+ $urlSource = new UrlInputSource("https://$dummyAddress");
$this->expectException(MindeeSourceException::class);
$this->expectExceptionMessage("Failed to download file: Could not resolve host: $dummyAddress");
$urlSource->asLocalInputSource("test.pdf");
@@ -50,7 +50,7 @@ public function testDownloadFileFails(): void
public function testInvalidFileName(): void
{
- $urlSource = $this->dummyClient->sourceFromUrl("https://addressthatdoesntworkforcipurposes");
+ $urlSource = new UrlInputSource("https://addressthatdoesntworkforcipurposes");
$this->expectException(MindeeSourceException::class);
$this->expectExceptionMessage("Filename must end with an extension.");
$urlSource->asLocalInputSource("toto");
diff --git a/tests/V1/CLI/MindeeCLICommandTestFunctional.php b/tests/V1/CLI/MindeeCLICommandTestFunctional.php
index ec066319..f5169c14 100644
--- a/tests/V1/CLI/MindeeCLICommandTestFunctional.php
+++ b/tests/V1/CLI/MindeeCLICommandTestFunctional.php
@@ -9,7 +9,7 @@
require_once(__DIR__ . "/../../TestingUtilities.php");
require_once(__DIR__ . "/MindeeCLITestingUtilities.php");
-use Mindee\CLI\MindeeCLIDocuments;
+use Mindee\Cli\MindeeCLIDocuments;
use PHPUnit\Framework\TestCase;
use TestingUtilities;
diff --git a/tests/V1/Error/MindeeHttpExceptionTest.php b/tests/V1/Error/MindeeHttpExceptionTest.php
index 16cd1eb7..e5db2bc3 100644
--- a/tests/V1/Error/MindeeHttpExceptionTest.php
+++ b/tests/V1/Error/MindeeHttpExceptionTest.php
@@ -4,8 +4,7 @@
namespace V1\Error;
-use Mindee\Error\MindeeHttpClientException;
-use Mindee\Error\MindeeHttpException;
+use Mindee\Error\V1\MindeeV1HttpException;
use Mindee\Input\PathInput;
use Mindee\V1\Client;
use Mindee\V1\Product\Invoice\InvoiceV4;
@@ -22,32 +21,32 @@ protected function setUp(): void
{
$this->errorDir = TestingUtilities::getV1DataDir() . "/errors/";
$this->dummyClient = new Client("dummy-key");
- $this->dummyFile = $this->dummyClient->sourceFromPath(
+ $this->dummyFile = new PathInput(
TestingUtilities::getFileTypesDir() . "/pdf/blank.pdf"
);
}
public function testHttpClientErrorShouldRaise(): void
{
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
$this->dummyClient->parse(InvoiceV4::class, $this->dummyFile);
}
public function testHttpEnqueueClientException(): void
{
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
$this->dummyClient->enqueue(InvoiceV4::class, $this->dummyFile);
}
public function testHttpParseClientException(): void
{
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
$this->dummyClient->enqueue(InvoiceV4::class, $this->dummyFile);
}
public function testHttpEnqueueAndParseClientException(): void
{
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
$this->dummyClient->enqueueAndParse(InvoiceV4::class, $this->dummyFile);
}
@@ -55,12 +54,12 @@ public function testHttp400Exception(): void
{
$json = file_get_contents($this->errorDir . "error_400_no_details.json");
$errorObj = ["data" => json_decode($json, true), "code" => 400];
- $error400 = MindeeHttpException::handleError("dummy-url", $errorObj);
+ $error400 = MindeeV1HttpException::handleError("dummy-url", $errorObj);
self::assertSame(400, $error400->statusCode);
self::assertSame("SomeCode", $error400->apiCode);
self::assertSame("Some scary message here", $error400->apiMessage);
self::assertNull($error400->apiDetails);
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
throw $error400;
}
@@ -68,12 +67,12 @@ public function testHttp401Exception(): void
{
$json = file_get_contents($this->errorDir . "error_401_invalid_token.json");
$errorObj = ["data" => json_decode($json, true), "code" => 401];
- $error401 = MindeeHttpException::handleError("dummy-url", $errorObj);
+ $error401 = MindeeV1HttpException::handleError("dummy-url", $errorObj);
self::assertSame(401, $error401->statusCode);
self::assertSame("Unauthorized", $error401->apiCode);
self::assertSame("Authorization required", $error401->apiMessage);
self::assertSame("Invalid token provided", $error401->apiDetails);
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
throw $error401;
}
@@ -81,12 +80,12 @@ public function testHttp429Exception(): void
{
$json = file_get_contents($this->errorDir . "error_429_too_many_requests.json");
$errorObj = ["data" => json_decode($json, true), "code" => 429];
- $error429 = MindeeHttpException::handleError("dummy-url", $errorObj);
+ $error429 = MindeeV1HttpException::handleError("dummy-url", $errorObj);
self::assertSame(429, $error429->statusCode);
self::assertSame("TooManyRequests", $error429->apiCode);
self::assertSame("Too many requests", $error429->apiMessage);
self::assertSame("Too Many Requests.", $error429->apiDetails);
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
throw $error429;
}
@@ -94,24 +93,24 @@ public function testHttp500Exception(): void
{
$json = file_get_contents($this->errorDir . "error_500_inference_fail.json");
$errorObj = ["data" => json_decode($json, true), "code" => 500];
- $error500 = MindeeHttpException::handleError("dummy-url", $errorObj);
+ $error500 = MindeeV1HttpException::handleError("dummy-url", $errorObj);
self::assertSame(500, $error500->statusCode);
self::assertSame("failure", $error500->apiCode);
self::assertSame("Inference failed", $error500->apiMessage);
self::assertSame("Can not run prediction: ", $error500->apiDetails);
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
throw $error500;
}
public function testHttp500HTMLError(): void
{
$errorRefContents = file_get_contents($this->errorDir . "error_50x.html");
- $error500 = MindeeHttpException::handleError("dummy-url", ["data" => $errorRefContents, "code" => 500]);
+ $error500 = MindeeV1HttpException::handleError("dummy-url", ["data" => $errorRefContents, "code" => 500]);
self::assertSame(500, $error500->statusCode);
self::assertSame("UnknownError", $error500->apiCode);
self::assertSame("Server sent back an unexpected reply.", $error500->apiMessage);
self::assertSame($errorRefContents, $error500->apiDetails);
- $this->expectException(MindeeHttpClientException::class);
+ $this->expectException(MindeeV1HttpException::class);
throw $error500;
}
}
diff --git a/tests/V1/Extraction/ImageExtractorTest.php b/tests/V1/Image/ImageExtractorTest.php
similarity index 99%
rename from tests/V1/Extraction/ImageExtractorTest.php
rename to tests/V1/Image/ImageExtractorTest.php
index a2a1e3fc..bdba2ce1 100644
--- a/tests/V1/Extraction/ImageExtractorTest.php
+++ b/tests/V1/Image/ImageExtractorTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace V1\Extraction;
+namespace V1\Image;
use Mindee\Input\LocalResponse;
use Mindee\Input\PathInput;
diff --git a/tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php b/tests/V1/Image/InvoiceSplitterAutoExtractionTestFunctional.php
similarity index 97%
rename from tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php
rename to tests/V1/Image/InvoiceSplitterAutoExtractionTestFunctional.php
index 5ee29e77..6d52da49 100644
--- a/tests/V1/Extraction/InvoiceSplitterAutoExtractionTestFunctional.php
+++ b/tests/V1/Image/InvoiceSplitterAutoExtractionTestFunctional.php
@@ -2,10 +2,10 @@
declare(strict_types=1);
-namespace V1\Extraction;
+namespace V1\Image;
-use Mindee\Extraction\PdfExtractor;
use Mindee\Input\PathInput;
+use Mindee\Pdf\PdfExtractor;
use Mindee\V1\Client;
use Mindee\V1\Parsing\Common\Document;
use Mindee\V1\Product\Invoice\InvoiceV4;
diff --git a/tests/V1/Input/UrlInputSourceTestFunctional.php b/tests/V1/Input/UrlInputSourceTestFunctional.php
index d95ec9c9..4e66433b 100644
--- a/tests/V1/Input/UrlInputSourceTestFunctional.php
+++ b/tests/V1/Input/UrlInputSourceTestFunctional.php
@@ -30,7 +30,7 @@ public static function tearDownAfterClass(): void
public function testLoadLocalFile(): void
{
- $urlSource = $this->client->sourceFromUrl($this->referenceFilePath);
+ $urlSource = new UrlInputSource($this->referenceFilePath);
$localSource = $urlSource->asLocalInputSource();
$result = $this->client->parse(InvoiceV4::class, $localSource);
self::assertSame(1, $result->document->nPages);
@@ -39,7 +39,7 @@ public function testLoadLocalFile(): void
public function testCustomFileName(): void
{
- $urlSource = $this->client->sourceFromUrl($this->referenceFilePath);
+ $urlSource = new UrlInputSource($this->referenceFilePath);
$localSource = $urlSource->asLocalInputSource("customName.pdf");
$result = $this->client->parse(InvoiceV4::class, $localSource);
self::assertSame(1, $result->document->nPages);
@@ -48,14 +48,14 @@ public function testCustomFileName(): void
public function testSaveFile(): void
{
- $urlSource = $this->client->sourceFromUrl($this->referenceFilePath);
+ $urlSource = new UrlInputSource($this->referenceFilePath);
$urlSource->saveToFile($this->outputFilePath);
self::assertFileExists($this->outputFilePath . "blank_1.pdf");
}
public function testSaveFileWithFilename(): void
{
- $urlSource = $this->client->sourceFromUrl($this->referenceFilePath);
+ $urlSource = new UrlInputSource($this->referenceFilePath);
$urlSource->saveToFile($this->outputFilePath, "customFileName.pdf");
self::assertFileExists($this->outputFilePath . "customFileName.pdf");
}
diff --git a/tests/V1/Parsing/Common/Extras/ExtrasIntegrationFunctional.php b/tests/V1/Parsing/Common/Extras/ExtrasIntegrationFunctional.php
index 60654471..9e6e7301 100644
--- a/tests/V1/Parsing/Common/Extras/ExtrasIntegrationFunctional.php
+++ b/tests/V1/Parsing/Common/Extras/ExtrasIntegrationFunctional.php
@@ -4,6 +4,7 @@
namespace V1\Parsing\Common\Extras;
+use Mindee\Input\PathInput;
use Mindee\V1\Client;
use Mindee\V1\ClientOptions\PredictMethodOptions;
use Mindee\V1\ClientOptions\PredictOptions;
@@ -26,7 +27,7 @@ protected function setUp(): void
public function testShouldSendCropperExtra(): void
{
- $sample = $this->client->sourceFromPath(
+ $sample = new PathInput(
TestingUtilities::getV1DataDir() . "/products/invoices/default_sample.jpg"
);
$predictOptions = new PredictOptions();
@@ -42,7 +43,7 @@ public function testShouldSendCropperExtra(): void
public function testShouldSendFullTextOcrExtra(): void
{
- $sample = $this->client->sourceFromPath(
+ $sample = new PathInput(
TestingUtilities::getV1DataDir() . "/products/international_id/default_sample.jpg"
);
$predictOptions = new PredictOptions();
diff --git a/tests/V1/Extraction/PdfExtractorTest.php b/tests/V1/Pdf/PdfExtractorTest.php
similarity index 98%
rename from tests/V1/Extraction/PdfExtractorTest.php
rename to tests/V1/Pdf/PdfExtractorTest.php
index 9c2d6ef2..f9858b16 100644
--- a/tests/V1/Extraction/PdfExtractorTest.php
+++ b/tests/V1/Pdf/PdfExtractorTest.php
@@ -2,11 +2,11 @@
declare(strict_types=1);
-namespace V1\Extraction;
+namespace V1\Pdf;
-use Mindee\Extraction\PdfExtractor;
use Mindee\Input\LocalResponse;
use Mindee\Input\PathInput;
+use Mindee\Pdf\PdfExtractor;
use Mindee\V1\Client;
use Mindee\V1\Product\InvoiceSplitter\InvoiceSplitterV1;
use PHPUnit\Framework\TestCase;
diff --git a/tests/V1/Workflow/WorkflowTestFunctional.php b/tests/V1/Workflow/WorkflowTestFunctional.php
index df4ad42d..089b360f 100644
--- a/tests/V1/Workflow/WorkflowTestFunctional.php
+++ b/tests/V1/Workflow/WorkflowTestFunctional.php
@@ -4,6 +4,7 @@
namespace V1\Workflow;
+use Mindee\Input\PathInput;
use Mindee\V1\Client;
use Mindee\V1\ClientOptions\PredictMethodOptions;
use Mindee\V1\ClientOptions\WorkflowOptions;
@@ -25,7 +26,7 @@ protected function setUp(): void
$this->mindeeClient = new Client();
$this->workflowId = getenv('WORKFLOW_ID') ?: '';
$this->predictionType = FinancialDocumentV1::class;
- $this->inputSource = $this->mindeeClient->sourceFromPath(
+ $this->inputSource = new PathInput(
TestingUtilities::getV1DataDir() . "/products/financial_document/default_sample.jpg"
);
}
diff --git a/tests/V2/ClientV2Test.php b/tests/V2/ClientV2Test.php
index 83993d69..907333bc 100644
--- a/tests/V2/ClientV2Test.php
+++ b/tests/V2/ClientV2Test.php
@@ -10,7 +10,7 @@
use Mindee\Input\PathInput;
use Mindee\V2\Client;
use Mindee\V2\Http\MindeeApiV2;
-use Mindee\V2\Parsing\JobResponse;
+use Mindee\V2\Parsing\Job\JobResponse;
use Mindee\V2\Product\Extraction\ExtractionResponse;
use Mindee\V2\Product\Extraction\Params\ExtractionParameters;
use PHPUnit\Framework\MockObject\MockObject;
@@ -46,10 +46,10 @@ public function testEnqueuePostAsync(): void
$input = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf');
$params = new ExtractionParameters('dummy-model-id', textContext: 'dummy text context');
- $response = $mindeeClient->enqueueInference($input, $params);
+ $response = $mindeeClient->enqueue($input, $params);
self::assertNotNull($response, 'enqueue() must return a response');
- self::assertInstanceOf(JobResponse::class, $response);
+ self::assertEmpty($response->job->error);
}
public function testDocumentGetJobAsync(): void
diff --git a/tests/V2/ClientV2TestFunctional.php b/tests/V2/ClientV2TestFunctional.php
index 6c26449e..578ea599 100644
--- a/tests/V2/ClientV2TestFunctional.php
+++ b/tests/V2/ClientV2TestFunctional.php
@@ -4,7 +4,7 @@
namespace V2;
-use Mindee\Error\MindeeV2HttpException;
+use Mindee\Error\V2\MindeeV2HttpException;
use Mindee\Input\PathInput;
use Mindee\Input\UrlInputSource;
use Mindee\V2\Client;
@@ -103,7 +103,7 @@ public function testInvalidUUIDMustThrowError(): void
$inferenceParams = new ExtractionParameters('INVALID MODEL ID');
try {
- $this->mindeeClient->enqueueInference($source, $inferenceParams);
+ $this->mindeeClient->enqueue($source, $inferenceParams);
} catch (MindeeV2HttpException $e) {
self::assertStringStartsWith('422-', $e->errorCode);
self::assertNotEmpty($e->title);
@@ -118,7 +118,7 @@ public function testUnknownModelMustThrowError(): void
$inferenceParams = new ExtractionParameters('fc405e37-4ba4-4d03-aeba-533a8d1f0f21', textContext: 'this is invalid');
try {
- $this->mindeeClient->enqueueInference($source, $inferenceParams);
+ $this->mindeeClient->enqueue($source, $inferenceParams);
} catch (MindeeV2HttpException $e) {
self::assertStringStartsWith('404-', $e->errorCode);
self::assertNotEmpty($e->title);
@@ -154,7 +154,7 @@ public function testInvalidWebhookIDsMustThrowError(): void
);
try {
- $this->mindeeClient->enqueueInference($source, $inferenceParams);
+ $this->mindeeClient->enqueue($source, $inferenceParams);
} catch (MindeeV2HttpException $e) {
self::assertStringStartsWith('422-', $e->errorCode);
self::assertNotEmpty($e->title);
diff --git a/tests/V2/Parsing/ExtractionResponseTest.php b/tests/V2/Parsing/ExtractionResponseTest.php
index b06d6522..3c21fad8 100644
--- a/tests/V2/Parsing/ExtractionResponseTest.php
+++ b/tests/V2/Parsing/ExtractionResponseTest.php
@@ -6,13 +6,13 @@
use Mindee\Geometry\Point;
use Mindee\Input\LocalResponse;
-use Mindee\V2\Parsing\ErrorItem;
-use Mindee\V2\Parsing\ErrorResponse;
+use Mindee\V2\Parsing\Error\ErrorItem;
+use Mindee\V2\Parsing\Error\ErrorResponse;
use Mindee\V2\Parsing\Inference\Field\FieldConfidence;
use Mindee\V2\Parsing\Inference\Field\ListField;
use Mindee\V2\Parsing\Inference\Field\ObjectField;
use Mindee\V2\Parsing\Inference\Field\SimpleField;
-use Mindee\V2\Parsing\JobResponse;
+use Mindee\V2\Parsing\Job\JobResponse;
use Mindee\V2\Product\Extraction\ExtractionResponse;
use PHPUnit\Framework\TestCase;
use TestingUtilities;
diff --git a/tests/V2/Parsing/JobResponseTest.php b/tests/V2/Parsing/JobResponseTest.php
index 1bd8e662..9cba008f 100644
--- a/tests/V2/Parsing/JobResponseTest.php
+++ b/tests/V2/Parsing/JobResponseTest.php
@@ -5,9 +5,9 @@
namespace V2\Parsing;
use DateTime;
-use Mindee\V2\Parsing\ErrorItem;
-use Mindee\V2\Parsing\ErrorResponse;
-use Mindee\V2\Parsing\JobResponse;
+use Mindee\V2\Parsing\Error\ErrorItem;
+use Mindee\V2\Parsing\Error\ErrorResponse;
+use Mindee\V2\Parsing\Job\JobResponse;
use PHPUnit\Framework\TestCase;
use TestingUtilities;
diff --git a/tests/resources b/tests/resources
index 315efcc3..13093f3a 160000
--- a/tests/resources
+++ b/tests/resources
@@ -1 +1 @@
-Subproject commit 315efcc302efacfb75a6b101788058658e8c37e4
+Subproject commit 13093f3a48de212ef26889df71199c1a2a9d1478
From dbe9da38aab653ced8d352a4da833dbbabea8a7c Mon Sep 17 00:00:00 2001
From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com>
Date: Wed, 27 May 2026 15:14:51 +0200
Subject: [PATCH 2/4] fixes
---
src/Input/Base64Input.php | 5 ++---
src/Input/BytesInput.php | 5 ++---
src/Input/FileInput.php | 7 ++-----
src/Input/LocalInputSource.php | 6 +-----
src/Input/PathInput.php | 5 ++---
tests/Input/LocalInputSourceTest.php | 9 ++++++---
tests/V1/Input/UrlInputSourceTestFunctional.php | 1 +
7 files changed, 16 insertions(+), 22 deletions(-)
diff --git a/src/Input/Base64Input.php b/src/Input/Base64Input.php
index 72c62860..cadbcbe3 100644
--- a/src/Input/Base64Input.php
+++ b/src/Input/Base64Input.php
@@ -19,9 +19,8 @@ class Base64Input extends LocalInputSource
/**
* @param string $strBase64 Raw data as a base64-encoded string.
* @param string $fileName File name of the input.
- * @param boolean $fixPdf Whether to try to fix a broken PDF.
*/
- public function __construct(string $strBase64, string $fileName, bool $fixPdf = false)
+ public function __construct(string $strBase64, string $fileName)
{
$this->tempFile = tempnam(sys_get_temp_dir(), 'b64_');
$this->fileName = $fileName;
@@ -30,7 +29,7 @@ public function __construct(string $strBase64, string $fileName, bool $fixPdf =
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$this->fileMimetype = finfo_buffer($finfo, base64_decode($strBase64, true));
$this->fileObject = new CURLFile($this->tempFile, $this->fileMimetype, $this->fileName);
- parent::__construct($fixPdf);
+ parent::__construct();
}
diff --git a/src/Input/BytesInput.php b/src/Input/BytesInput.php
index c427f995..bc5ad5b4 100644
--- a/src/Input/BytesInput.php
+++ b/src/Input/BytesInput.php
@@ -19,9 +19,8 @@ class BytesInput extends LocalInputSource
/**
* @param string $fileBytes Raw data as bytes.
* @param string $fileName File name of the input.
- * @param boolean $fixPdf Whether to try to fix a broken PDF.
*/
- public function __construct(string $fileBytes, string $fileName, bool $fixPdf = false)
+ public function __construct(string $fileBytes, string $fileName)
{
$this->tempFile = tempnam(sys_get_temp_dir(), 'b64_');
$this->fileName = $fileName;
@@ -30,7 +29,7 @@ public function __construct(string $fileBytes, string $fileName, bool $fixPdf =
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$this->fileMimetype = finfo_buffer($finfo, $fileBytes);
$this->fileObject = new CURLFile($this->tempFile, $this->fileMimetype, $this->fileName);
- parent::__construct($fixPdf);
+ parent::__construct();
}
diff --git a/src/Input/FileInput.php b/src/Input/FileInput.php
index 5f725b4b..5ea83d4c 100644
--- a/src/Input/FileInput.php
+++ b/src/Input/FileInput.php
@@ -4,8 +4,6 @@
namespace Mindee\Input;
-use Mindee\Error\ErrorCode;
-use Mindee\Error\MindeeSourceException;
use CURLFile;
/**
@@ -20,16 +18,15 @@ class FileInput extends LocalInputSource
/**
* @param resource &$file File reference.
- * @param boolean $fixPdf Whether to try to fix a broken PDF.
*/
- public function __construct(&$file, bool $fixPdf = false)
+ public function __construct(&$file)
{
$this->file = &$file;
$this->filePath = stream_get_meta_data($this->file)['uri'];
$this->fileName = basename($this->filePath);
$this->fileMimetype = mime_content_type($this->filePath);
$this->fileObject = new CURLFile($this->filePath, $this->fileName, $this->fileMimetype);
- parent::__construct($fixPdf);
+ parent::__construct();
}
/**
diff --git a/src/Input/LocalInputSource.php b/src/Input/LocalInputSource.php
index d53b6b72..9963f2b0 100644
--- a/src/Input/LocalInputSource.php
+++ b/src/Input/LocalInputSource.php
@@ -97,13 +97,9 @@ private function checkMimeType(): void
/**
* Base constructor, mostly used for Mime type checking.
- * @param boolean $fixPdf Whether to attempt to fix the PDF.
*/
- public function __construct(bool $fixPdf = false)
+ public function __construct()
{
- if ($fixPdf) {
- $this->fixPdf();
- }
$this->checkMimeType();
}
diff --git a/src/Input/PathInput.php b/src/Input/PathInput.php
index 648bedca..c41a4f93 100644
--- a/src/Input/PathInput.php
+++ b/src/Input/PathInput.php
@@ -13,9 +13,8 @@ class PathInput extends LocalInputSource
{
/**
* @param string $filePath Path to open.
- * @param boolean $fixPdf Whether to try to fix a broken PDF.
*/
- public function __construct(string $filePath, bool $fixPdf = false)
+ public function __construct(string $filePath)
{
$this->filePath = $filePath;
$this->fileName = basename($filePath);
@@ -25,6 +24,6 @@ public function __construct(string $filePath, bool $fixPdf = false)
$this->fileMimetype = $mimeType;
$this->fileObject = new CURLFile($this->filePath, $mimeType, $this->fileName);
finfo_close($file);
- parent::__construct($fixPdf);
+ parent::__construct();
}
}
diff --git a/tests/Input/LocalInputSourceTest.php b/tests/Input/LocalInputSourceTest.php
index 4ab994f4..3a8daa95 100644
--- a/tests/Input/LocalInputSourceTest.php
+++ b/tests/Input/LocalInputSourceTest.php
@@ -217,14 +217,16 @@ public function testShouldNotRaiseMimeErrorForBrokenFixablePdf(): void
{
$this->expectNotToPerformAssertions();
- new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_fixable.pdf', true);
+ $pathInput = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_fixable.pdf');
+ $pathInput->fixPdf();
}
public function testShouldRaiseErrorForBrokenUnfixablePdf(): void
{
$this->expectException(MindeeSourceException::class);
- new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_unfixable.pdf', true);
+ $pathInput = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_unfixable.pdf');
+ $pathInput->fixPdf();
}
public function testShouldSendCorrectResultsForBrokenFixableInvoicePdf(): void
@@ -233,7 +235,8 @@ public function testShouldSendCorrectResultsForBrokenFixableInvoicePdf(): void
TestingUtilities::getV1DataDir() . '/products/invoices/invoice.pdf'
);
- $sourceDocFixed = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_invoice.pdf', true);
+ $sourceDocFixed = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/broken_invoice.pdf');
+ $sourceDocFixed->fixPdf();
self::assertSame($sourceDocFixed->readContents()[1], $sourceDocOriginal->readContents()[1]);
}
diff --git a/tests/V1/Input/UrlInputSourceTestFunctional.php b/tests/V1/Input/UrlInputSourceTestFunctional.php
index 4e66433b..fae63720 100644
--- a/tests/V1/Input/UrlInputSourceTestFunctional.php
+++ b/tests/V1/Input/UrlInputSourceTestFunctional.php
@@ -4,6 +4,7 @@
namespace V1\Input;
+use Mindee\Input\UrlInputSource;
use Mindee\V1\Client;
use Mindee\V1\Product\Invoice\InvoiceV4;
use PHPUnit\Framework\TestCase;
From 99a4f1a426de2f69a50cdff430e1291757e7629f Mon Sep 17 00:00:00 2001
From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com>
Date: Wed, 27 May 2026 15:28:35 +0200
Subject: [PATCH 3/4] add typed accessors
---
.../Parsing/Inference/Field/SimpleField.php | 33 +++++++++++++++++
tests/V2/ClientV2Test.php | 2 +-
tests/V2/Parsing/ExtractionResponseTest.php | 37 +++++++++++--------
3 files changed, 56 insertions(+), 16 deletions(-)
diff --git a/src/V2/Parsing/Inference/Field/SimpleField.php b/src/V2/Parsing/Inference/Field/SimpleField.php
index 1ba0d69d..6412848f 100644
--- a/src/V2/Parsing/Inference/Field/SimpleField.php
+++ b/src/V2/Parsing/Inference/Field/SimpleField.php
@@ -32,6 +32,7 @@ public function __construct(array $rawResponse, int $indentLevel = 0)
}
/**
+ * @return string String representation.
*/
public function __toString(): string
{
@@ -43,4 +44,36 @@ public function __toString(): string
}
return $this->value !== null ? (string) $this->value : '';
}
+
+ /**
+ * @return string|null String representation of the field value.
+ */
+ public function getStringValue(): ?string
+ {
+ return null !== $this->value ? (string) $this->value : null;
+ }
+
+ /**
+ * @return float|null Float representation of the field value.
+ */
+ public function getFloatValue(): ?float
+ {
+ return null !== $this->value ? (float) $this->value : null;
+ }
+
+ /**
+ * @return integer|null Integer representation of the field value.
+ */
+ public function getIntValue(): ?int
+ {
+ return null !== $this->value ? (int) $this->value : null;
+ }
+
+ /**
+ * @return boolean|null Boolean representation of the field value.
+ */
+ public function getBoolValue(): ?bool
+ {
+ return null !== $this->value ? (bool) $this->value : null;
+ }
}
diff --git a/tests/V2/ClientV2Test.php b/tests/V2/ClientV2Test.php
index 907333bc..ec3cc973 100644
--- a/tests/V2/ClientV2Test.php
+++ b/tests/V2/ClientV2Test.php
@@ -132,7 +132,7 @@ public function testInferenceLoadsLocally(): void
'Model Id mismatch'
);
- $supplierName = $loaded->inference->result->fields['supplier_name']->value ?? null;
+ $supplierName = $loaded->inference->result->fields['supplier_name']->getStringValue();
self::assertSame(
'John Smith',
$supplierName,
diff --git a/tests/V2/Parsing/ExtractionResponseTest.php b/tests/V2/Parsing/ExtractionResponseTest.php
index 3c21fad8..67bb3967 100644
--- a/tests/V2/Parsing/ExtractionResponseTest.php
+++ b/tests/V2/Parsing/ExtractionResponseTest.php
@@ -57,6 +57,7 @@ public function testAsyncPredictWhenEmptyMustHaveValidProperties(): void
);
$totalAmount = $fields->getSimpleField('total_amount');
self::assertEmpty($totalAmount->value);
+ self::assertNull($totalAmount->getFloatValue());
self::assertInstanceOf(
ListField::class,
@@ -119,7 +120,7 @@ public function testAsyncPredictWhenCompleteMustExposeAllProperties(): void
$date = $fields->get('date');
self::assertInstanceOf(SimpleField::class, $date);
- self::assertSame('2019-11-02', $date->value, "'date' value mismatch");
+ self::assertSame('2019-11-02', $date->getStringValue(), "'date' value mismatch");
$taxes = $fields->getListField('taxes');
self::assertNotNull($taxes, "'taxes' field must exist");
@@ -132,7 +133,7 @@ public function testAsyncPredictWhenCompleteMustExposeAllProperties(): void
$baseTax = $taxItemObj->fields->get('base');
self::assertInstanceOf(SimpleField::class, $baseTax);
- self::assertSame(31.5, $baseTax->value, "'taxes.base' value mismatch");
+ self::assertSame(31.5, $baseTax->getFloatValue(), "'taxes.base' value mismatch");
self::assertNotNull((string) $taxes, "'taxes'.__toString() must not be null");
$supplierAddress = $fields->getObjectField('supplier_address');
@@ -142,7 +143,7 @@ public function testAsyncPredictWhenCompleteMustExposeAllProperties(): void
$country = $supplierAddress->fields->get('country');
self::assertNotNull($country, "'supplier_address.country' must exist");
self::assertInstanceOf(SimpleField::class, $country);
- self::assertSame('USA', $country->value, 'Country mismatch');
+ self::assertSame('USA', $country->getStringValue(), 'Country mismatch');
self::assertSame('USA', (string) $country, "'country'.__toString() mismatch");
self::assertNotNull((string) $supplierAddress, "'supplier_address'.__toString() must not be null");
@@ -150,7 +151,7 @@ public function testAsyncPredictWhenCompleteMustExposeAllProperties(): void
self::assertInstanceOf(ObjectField::class, $customerAddr);
$city = $customerAddr->fields->get('city');
self::assertInstanceOf(SimpleField::class, $city);
- self::assertSame('New York', $city->value, 'City mismatch');
+ self::assertSame('New York', $city->getStringValue(), 'City mismatch');
self::assertNull($inference->result->options ?? null, 'Options must be null');
}
@@ -196,7 +197,7 @@ public function testDeepNestedFieldsMustExposeCorrectTypes(): void
self::assertInstanceOf(ObjectField::class, $firstItem);
$deepSimple = $firstItem->fields->get('sub_object_object_sub_object_list_simple');
self::assertInstanceOf(SimpleField::class, $deepSimple);
- self::assertSame('value_9', $deepSimple->value);
+ self::assertSame('value_9', $deepSimple->getStringValue());
}
/**
@@ -212,27 +213,33 @@ public function testStandardFieldTypesMustExposeCorrectTypes(): void
$fieldSimpleString = $fields->get('field_simple_string');
self::assertInstanceOf(SimpleField::class, $fieldSimpleString);
- self::assertIsString($fieldSimpleString->value);
+ self::assertIsString($fieldSimpleString->getStringValue());
$fieldSimpleFloat = $fields->get('field_simple_float');
self::assertInstanceOf(SimpleField::class, $fieldSimpleFloat);
- self::assertIsFloat($fieldSimpleFloat->value);
+ self::assertIsFloat($fieldSimpleFloat->getFloatValue());
$fieldSimpleInt = $fields->get('field_simple_int');
self::assertInstanceOf(SimpleField::class, $fieldSimpleInt);
- self::assertIsFloat($fieldSimpleInt->value);
+ self::assertIsFloat($fieldSimpleInt->getFloatValue());
+ self::assertIsInt($fieldSimpleInt->getIntValue());
$fieldSimpleZero = $fields->get('field_simple_zero');
self::assertInstanceOf(SimpleField::class, $fieldSimpleZero);
- self::assertIsFloat($fieldSimpleZero->value);
+ self::assertIsFloat($fieldSimpleZero->getFloatValue());
+ self::assertIsInt($fieldSimpleZero->getIntValue());
$fieldSimpleBool = $fields->get('field_simple_bool');
self::assertInstanceOf(SimpleField::class, $fieldSimpleBool);
- self::assertIsBool($fieldSimpleBool->value);
+ self::assertIsBool($fieldSimpleBool->getBoolValue());
$fieldSimpleNull = $fields->get('field_simple_null');
self::assertInstanceOf(SimpleField::class, $fieldSimpleNull);
self::assertNull($fieldSimpleNull->value);
+ self::assertNull($fieldSimpleNull->getStringValue());
+ self::assertNull($fieldSimpleNull->getIntValue());
+ self::assertNull($fieldSimpleNull->getFloatValue());
+ self::assertNull($fieldSimpleNull->getBoolValue());
$fieldSimpleList = $fields->get('field_simple_list');
self::assertInstanceOf(ListField::class, $fieldSimpleList);
@@ -241,11 +248,11 @@ public function testStandardFieldTypesMustExposeCorrectTypes(): void
$firstSimpleItem = $simpleItems[0];
self::assertInstanceOf(SimpleField::class, $firstSimpleItem);
- self::assertIsString($firstSimpleItem->value);
+ self::assertIsString($firstSimpleItem->getStringValue());
foreach ($fieldSimpleList->items as $item) {
self::assertInstanceOf(SimpleField::class, $item);
- self::assertIsString($item->value);
+ self::assertIsString($item->getStringValue());
}
$fieldObject = $fields->get('field_object');
@@ -258,7 +265,7 @@ public function testStandardFieldTypesMustExposeCorrectTypes(): void
$subfield1 = $fieldObjectFields->getSimpleField('subfield_1');
self::assertInstanceOf(SimpleField::class, $subfield1);
- self::assertIsString($subfield1->value);
+ self::assertIsString($subfield1->getStringValue());
$fieldObjectList = $fields->get('field_object_list');
self::assertInstanceOf(ListField::class, $fieldObjectList);
@@ -270,13 +277,13 @@ public function testStandardFieldTypesMustExposeCorrectTypes(): void
$firstObjectSubfield = $firstObjectItem->fields->get('subfield_1');
self::assertInstanceOf(SimpleField::class, $firstObjectSubfield);
- self::assertIsString($firstObjectSubfield->value);
+ self::assertIsString($firstObjectSubfield->getStringValue());
foreach ($fieldObjectList->items as $item) {
self::assertInstanceOf(ObjectField::class, $item);
$subfield = $item->fields->get('subfield_1');
self::assertInstanceOf(SimpleField::class, $subfield);
- self::assertIsString($subfield->value);
+ self::assertIsString($subfield->getStringValue());
}
}
From 7cd286753178abcfa71d8f46fd44895ead8db865 Mon Sep 17 00:00:00 2001
From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com>
Date: Wed, 27 May 2026 15:43:24 +0200
Subject: [PATCH 4/4] remove useless accessor
---
src/V2/Parsing/Inference/Field/SimpleField.php | 8 --------
tests/V2/Parsing/ExtractionResponseTest.php | 3 ---
2 files changed, 11 deletions(-)
diff --git a/src/V2/Parsing/Inference/Field/SimpleField.php b/src/V2/Parsing/Inference/Field/SimpleField.php
index 6412848f..a63fe087 100644
--- a/src/V2/Parsing/Inference/Field/SimpleField.php
+++ b/src/V2/Parsing/Inference/Field/SimpleField.php
@@ -61,14 +61,6 @@ public function getFloatValue(): ?float
return null !== $this->value ? (float) $this->value : null;
}
- /**
- * @return integer|null Integer representation of the field value.
- */
- public function getIntValue(): ?int
- {
- return null !== $this->value ? (int) $this->value : null;
- }
-
/**
* @return boolean|null Boolean representation of the field value.
*/
diff --git a/tests/V2/Parsing/ExtractionResponseTest.php b/tests/V2/Parsing/ExtractionResponseTest.php
index 67bb3967..ad6e85b8 100644
--- a/tests/V2/Parsing/ExtractionResponseTest.php
+++ b/tests/V2/Parsing/ExtractionResponseTest.php
@@ -222,12 +222,10 @@ public function testStandardFieldTypesMustExposeCorrectTypes(): void
$fieldSimpleInt = $fields->get('field_simple_int');
self::assertInstanceOf(SimpleField::class, $fieldSimpleInt);
self::assertIsFloat($fieldSimpleInt->getFloatValue());
- self::assertIsInt($fieldSimpleInt->getIntValue());
$fieldSimpleZero = $fields->get('field_simple_zero');
self::assertInstanceOf(SimpleField::class, $fieldSimpleZero);
self::assertIsFloat($fieldSimpleZero->getFloatValue());
- self::assertIsInt($fieldSimpleZero->getIntValue());
$fieldSimpleBool = $fields->get('field_simple_bool');
self::assertInstanceOf(SimpleField::class, $fieldSimpleBool);
@@ -237,7 +235,6 @@ public function testStandardFieldTypesMustExposeCorrectTypes(): void
self::assertInstanceOf(SimpleField::class, $fieldSimpleNull);
self::assertNull($fieldSimpleNull->value);
self::assertNull($fieldSimpleNull->getStringValue());
- self::assertNull($fieldSimpleNull->getIntValue());
self::assertNull($fieldSimpleNull->getFloatValue());
self::assertNull($fieldSimpleNull->getBoolValue());