From d1bd314716ec8b59be96c8cca79993804c74e5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Thu, 11 Sep 2025 10:49:49 +0200 Subject: [PATCH] :boom: remove closeFile parameter --- src/Http/Endpoint.php | 3 --- src/Http/MindeeApiV2.php | 3 --- src/Input/FileInput.php | 21 ----------------- src/Input/InferenceParameters.php | 8 ------- src/Input/LocalInputSource.php | 35 ---------------------------- src/Input/PredictMethodOptions.php | 6 ----- tests/Input/LocalInputSourceTest.php | 31 ------------------------ 7 files changed, 107 deletions(-) diff --git a/src/Http/Endpoint.php b/src/Http/Endpoint.php index 22d8f08f..d4a04d82 100644 --- a/src/Http/Endpoint.php +++ b/src/Http/Endpoint.php @@ -119,9 +119,6 @@ private function initCurlSessionPost( $postFields = ['document' => $inputSource->url]; } elseif ($inputSource instanceof LocalInputSource) { $inputSource->checkNeedsFix(); - if ($options->closeFile) { - $inputSource->close(); - } $postFields = ['document' => $inputSource->fileObject]; } if ($options->predictOptions->includeWords) { diff --git a/src/Http/MindeeApiV2.php b/src/Http/MindeeApiV2.php index e05e490f..95d6eeb6 100644 --- a/src/Http/MindeeApiV2.php +++ b/src/Http/MindeeApiV2.php @@ -306,9 +306,6 @@ private function documentEnqueuePost( $postFields['url'] = $inputSource->url; } elseif ($inputSource instanceof LocalInputSource) { $inputSource->checkNeedsFix(); - if ($params->closeFile) { - $inputSource->close(); - } $postFields['file'] = $inputSource->fileObject; } diff --git a/src/Input/FileInput.php b/src/Input/FileInput.php index ee1b308f..14c836d8 100644 --- a/src/Input/FileInput.php +++ b/src/Input/FileInput.php @@ -39,27 +39,6 @@ public function readContents(): array return [$this->fileName, $fileContents]; } - /** - * Closes the file. - * - * @return void - * @throws MindeeSourceException Throws when strict mode is enabled. - */ - public function close(): void - { - if (!is_resource($this->file)) { - if ($this->throwsOnClose) { - throw new MindeeSourceException( - "File is already closed.", - ErrorCode::USER_OPERATION_ERROR - ); - } - error_log("File is already closed."); - } else { - fclose($this->file); - } - } - /** * Returns the reference to the file object. Only used for testing purposes. * diff --git a/src/Input/InferenceParameters.php b/src/Input/InferenceParameters.php index 6dc55787..7e2b6b33 100644 --- a/src/Input/InferenceParameters.php +++ b/src/Input/InferenceParameters.php @@ -48,11 +48,6 @@ class InferenceParameters */ public PollingOptions $pollingOptions; - /** - * @var boolean Whether to close the file after enqueuing. - */ - public bool $closeFile; - /** * @param string $modelId ID of the model. * @param boolean|null $rag Whether to enable Retrieval-Augmented Generation. @@ -62,7 +57,6 @@ class InferenceParameters * @param string|null $alias Optional file alias. * @param array|null $webhooksIds List of webhook IDs. * @param PollingOptions|null $pollingOptions Polling options. - * @param boolean|null $closeFile Whether to close the file after enqueuing. */ public function __construct( string $modelId, @@ -73,7 +67,6 @@ public function __construct( ?string $alias = null, ?array $webhooksIds = null, ?PollingOptions $pollingOptions = null, - ?bool $closeFile = null ) { $this->modelId = $modelId; if (!$pollingOptions) { @@ -85,7 +78,6 @@ public function __construct( $this->polygon = $polygon; $this->confidence = $confidence; - $this->closeFile = (bool) $closeFile; if (isset($alias)) { $this->alias = $alias; } diff --git a/src/Input/LocalInputSource.php b/src/Input/LocalInputSource.php index 45d054c6..1f9e1e8b 100644 --- a/src/Input/LocalInputSource.php +++ b/src/Input/LocalInputSource.php @@ -55,11 +55,6 @@ abstract class LocalInputSource extends InputSource */ public ?string $filePath; - /** - * @var boolean Sets the input mode to debug. Only used in unit tests. - */ - protected bool $throwsOnClose; - /** * Checks if the file needs fixing. * @return void @@ -100,7 +95,6 @@ private function checkMimeType() public function __construct() { $this->checkMimeType(); - $this->throwsOnClose = false; } /** @@ -259,35 +253,6 @@ public function fixPDF(): void ); } - /** - * Closes the handle/stream, if the input type supports it. - * - * @return void - * @throws MindeeSourceException Throws when strict mode is enabled. - */ - public function close(): void - { - if ($this->throwsOnClose) { - throw new MindeeSourceException( - "Closing is not implemented on this type of local input source.", - ErrorCode::USER_OPERATION_ERROR - ); - } else { - error_log("Closing is not implemented on this type of local input source."); - } - } - - /** - * Enables strict mode. - * Currently only used to throw on misuse of close(). - * - * @return void - */ - public function enableStrictMode() - { - $this->throwsOnClose = true; - } - /** * @param integer $quality Quality of the output file. * @param integer|null $maxWidth Maximum width (Ignored for PDFs). diff --git a/src/Input/PredictMethodOptions.php b/src/Input/PredictMethodOptions.php index e067c92c..29623083 100644 --- a/src/Input/PredictMethodOptions.php +++ b/src/Input/PredictMethodOptions.php @@ -28,11 +28,6 @@ class PredictMethodOptions */ public $endpoint; - /** - * @var boolean Whether to close the file after parsing it. - */ - public bool $closeFile; - /** * @var boolean If set, will enable Retrieval-Augmented Generation (only works if a valid WorkflowId is set). */ @@ -51,7 +46,6 @@ public function __construct() $this->predictOptions = new PredictOptions(); $this->pageOptions = new PageOptions(); $this->endpoint = null; - $this->closeFile = false; $this->rag = false; $this->workflowId = null; } diff --git a/tests/Input/LocalInputSourceTest.php b/tests/Input/LocalInputSourceTest.php index 20aa1af4..9cf79748 100644 --- a/tests/Input/LocalInputSourceTest.php +++ b/tests/Input/LocalInputSourceTest.php @@ -222,37 +222,6 @@ public function testInputFromRawb64String() $this->assertEquals(str_replace("\n", "", $pdfBytes), str_replace("\n", "", base64_encode($contents[1]))); } - - public function testFileCloseValid() - { - $fileRef = fopen($this->fileTypesDir . "/pdf/multipage.pdf", "r"); - $inputDoc = $this->dummyClient->sourceFromFile($fileRef); - $this->assertTrue(is_resource($inputDoc->getFilePtr())); - $inputDoc->close(); - $this->assertFalse(is_resource($inputDoc->getFilePtr())); - } - - public function testFileCloseInvalid() - { - $fileRef = fopen($this->fileTypesDir . "/pdf/multipage.pdf", "r"); - $inputDoc = $this->dummyClient->sourceFromFile($fileRef); - $inputDoc->enableStrictMode(); - fclose($fileRef); - $this->expectException(MindeeSourceException::class); - $this->expectExceptionMessage("File is already closed."); - $inputDoc->close(); - } - - public function testFileCloseNotImplemented() - { - $pdfBytes = file_get_contents($this->fileTypesDir . "/receipt.txt"); - $inputDoc = $this->dummyClient->sourceFromb64String($pdfBytes, "dummy.pdf"); - $inputDoc->enableStrictMode(); - $this->expectException(MindeeSourceException::class); - $this->expectExceptionMessage("Closing is not implemented on this type of local input source."); - $inputDoc->close(); - } - public function testShouldNotRaiseMimeErrorForBrokenFixablePdf() { $this->expectNotToPerformAssertions();