Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/DocumentCommandConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mindee\CLI;
namespace Mindee\Cli;

/**
* Document configuration class for CLI usage.
Expand Down
25 changes: 12 additions & 13 deletions bin/MindeeCLICommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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("<error>Page cut & page keep operations are mutually exclusive.</error>");
$output->writeln("<error>Page cut and page keep operations are mutually exclusive.</error>");
return true;
}
return false;
Expand All @@ -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("<error>Invalid path or url provided '$filePathOrUrl'.</error>");
return null;
}
}
return $client->sourceFromUrl($filePathOrUrl);
return new UrlInputSource($filePathOrUrl);
}

/**
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -524,7 +523,7 @@ private function runClientPrediction(
PredictMethodOptions $predictMethodOptions,
bool $isAsync,
bool $debug
) {
): AsyncPredictResponse|PredictResponse|string {
if ($debug) {
return "Command executed successfully.";
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion bin/MindeeCLIDocuments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bin/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mindee\CLI;
namespace Mindee\Cli;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/MindeeCLIDocuments.php';
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/bank_account_details_v1.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\Fr\BankAccountDetails\BankAccountDetailsV1;

// Init a new client
$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");

// Parse the file
$apiResponse = $mindeeClient->parse(BankAccountDetailsV1::class, $inputSource);
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/bank_account_details_v2.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\Fr\BankAccountDetails\BankAccountDetailsV2;

// Init a new client
$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");

// Parse the file
$apiResponse = $mindeeClient->parse(BankAccountDetailsV2::class, $inputSource);
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/bank_check_v1.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\Us\BankCheck\BankCheckV1;

// Init a new client
$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");

// Parse the file
$apiResponse = $mindeeClient->parse(BankCheckV1::class, $inputSource);
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/barcode_reader_v1.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\BarcodeReader\BarcodeReaderV1;

// Init a new client
$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");

// Parse the file
$apiResponse = $mindeeClient->parse(BarcodeReaderV1::class, $inputSource);
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/bill_of_lading_v1_async.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\BillOfLading\BillOfLadingV1;

// Init a new client
$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");

// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(BillOfLadingV1::class, $inputSource);
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/business_card_v1_async.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\BusinessCard\BusinessCardV1;

// Init a new client
$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");

// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(BusinessCardV1::class, $inputSource);
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/carte_grise_v1.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\Fr\CarteGrise\CarteGriseV1;

// Init a new client
$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");

// Parse the file
$apiResponse = $mindeeClient->parse(CarteGriseV1::class, $inputSource);
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/cropper_v1.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\Cropper\CropperV1;

// Init a new client
$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");

// Parse the file
$apiResponse = $mindeeClient->parse(CropperV1::class, $inputSource);
Expand Down
2 changes: 1 addition & 1 deletion docs/code_samples/custom_v1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/default.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\Generated\GeneratedV1;
use Mindee\V1\ClientOptions\PredictMethodOptions;

// Init a new client
$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(
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/default_async.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\Generated\GeneratedV1;
use Mindee\V1\ClientOptions\PredictMethodOptions;

// Init a new client
$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(
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/delivery_notes_v1_async.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\DeliveryNote\DeliveryNoteV1;

// Init a new client
$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");

// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(DeliveryNoteV1::class, $inputSource);
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/driver_license_v1_async.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\DriverLicense\DriverLicenseV1;

// Init a new client
$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");

// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(DriverLicenseV1::class, $inputSource);
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/energy_bill_fra_v1_async.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\Fr\EnergyBill\EnergyBillV1;

// Init a new client
$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");

// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(EnergyBillV1::class, $inputSource);
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/expense_receipts_v5.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\Receipt\ReceiptV5;

// Init a new client
$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");

// Parse the file
$apiResponse = $mindeeClient->parse(ReceiptV5::class, $inputSource);
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/expense_receipts_v5_async.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\Receipt\ReceiptV5;

// Init a new client
$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");

// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(ReceiptV5::class, $inputSource);
Expand Down
3 changes: 2 additions & 1 deletion docs/code_samples/financial_document_v1.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Mindee\V1\Client;
use Mindee\Input\PathInput;
use Mindee\V1\Product\FinancialDocument\FinancialDocumentV1;

// Init a new client
$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");

// Parse the file
$apiResponse = $mindeeClient->parse(FinancialDocumentV1::class, $inputSource);
Expand Down
Loading
Loading