Skip to content

Commit d1bd314

Browse files
committed
💥 remove closeFile parameter
1 parent adf2e79 commit d1bd314

7 files changed

Lines changed: 0 additions & 107 deletions

File tree

src/Http/Endpoint.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ private function initCurlSessionPost(
119119
$postFields = ['document' => $inputSource->url];
120120
} elseif ($inputSource instanceof LocalInputSource) {
121121
$inputSource->checkNeedsFix();
122-
if ($options->closeFile) {
123-
$inputSource->close();
124-
}
125122
$postFields = ['document' => $inputSource->fileObject];
126123
}
127124
if ($options->predictOptions->includeWords) {

src/Http/MindeeApiV2.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ private function documentEnqueuePost(
306306
$postFields['url'] = $inputSource->url;
307307
} elseif ($inputSource instanceof LocalInputSource) {
308308
$inputSource->checkNeedsFix();
309-
if ($params->closeFile) {
310-
$inputSource->close();
311-
}
312309
$postFields['file'] = $inputSource->fileObject;
313310
}
314311

src/Input/FileInput.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,6 @@ public function readContents(): array
3939
return [$this->fileName, $fileContents];
4040
}
4141

42-
/**
43-
* Closes the file.
44-
*
45-
* @return void
46-
* @throws MindeeSourceException Throws when strict mode is enabled.
47-
*/
48-
public function close(): void
49-
{
50-
if (!is_resource($this->file)) {
51-
if ($this->throwsOnClose) {
52-
throw new MindeeSourceException(
53-
"File is already closed.",
54-
ErrorCode::USER_OPERATION_ERROR
55-
);
56-
}
57-
error_log("File is already closed.");
58-
} else {
59-
fclose($this->file);
60-
}
61-
}
62-
6342
/**
6443
* Returns the reference to the file object. Only used for testing purposes.
6544
*

src/Input/InferenceParameters.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ class InferenceParameters
4848
*/
4949
public PollingOptions $pollingOptions;
5050

51-
/**
52-
* @var boolean Whether to close the file after enqueuing.
53-
*/
54-
public bool $closeFile;
55-
5651
/**
5752
* @param string $modelId ID of the model.
5853
* @param boolean|null $rag Whether to enable Retrieval-Augmented Generation.
@@ -62,7 +57,6 @@ class InferenceParameters
6257
* @param string|null $alias Optional file alias.
6358
* @param array<string>|null $webhooksIds List of webhook IDs.
6459
* @param PollingOptions|null $pollingOptions Polling options.
65-
* @param boolean|null $closeFile Whether to close the file after enqueuing.
6660
*/
6761
public function __construct(
6862
string $modelId,
@@ -73,7 +67,6 @@ public function __construct(
7367
?string $alias = null,
7468
?array $webhooksIds = null,
7569
?PollingOptions $pollingOptions = null,
76-
?bool $closeFile = null
7770
) {
7871
$this->modelId = $modelId;
7972
if (!$pollingOptions) {
@@ -85,7 +78,6 @@ public function __construct(
8578
$this->polygon = $polygon;
8679
$this->confidence = $confidence;
8780

88-
$this->closeFile = (bool) $closeFile;
8981
if (isset($alias)) {
9082
$this->alias = $alias;
9183
}

src/Input/LocalInputSource.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ abstract class LocalInputSource extends InputSource
5555
*/
5656
public ?string $filePath;
5757

58-
/**
59-
* @var boolean Sets the input mode to debug. Only used in unit tests.
60-
*/
61-
protected bool $throwsOnClose;
62-
6358
/**
6459
* Checks if the file needs fixing.
6560
* @return void
@@ -100,7 +95,6 @@ private function checkMimeType()
10095
public function __construct()
10196
{
10297
$this->checkMimeType();
103-
$this->throwsOnClose = false;
10498
}
10599

106100
/**
@@ -259,35 +253,6 @@ public function fixPDF(): void
259253
);
260254
}
261255

262-
/**
263-
* Closes the handle/stream, if the input type supports it.
264-
*
265-
* @return void
266-
* @throws MindeeSourceException Throws when strict mode is enabled.
267-
*/
268-
public function close(): void
269-
{
270-
if ($this->throwsOnClose) {
271-
throw new MindeeSourceException(
272-
"Closing is not implemented on this type of local input source.",
273-
ErrorCode::USER_OPERATION_ERROR
274-
);
275-
} else {
276-
error_log("Closing is not implemented on this type of local input source.");
277-
}
278-
}
279-
280-
/**
281-
* Enables strict mode.
282-
* Currently only used to throw on misuse of close().
283-
*
284-
* @return void
285-
*/
286-
public function enableStrictMode()
287-
{
288-
$this->throwsOnClose = true;
289-
}
290-
291256
/**
292257
* @param integer $quality Quality of the output file.
293258
* @param integer|null $maxWidth Maximum width (Ignored for PDFs).

src/Input/PredictMethodOptions.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ class PredictMethodOptions
2828
*/
2929
public $endpoint;
3030

31-
/**
32-
* @var boolean Whether to close the file after parsing it.
33-
*/
34-
public bool $closeFile;
35-
3631
/**
3732
* @var boolean If set, will enable Retrieval-Augmented Generation (only works if a valid WorkflowId is set).
3833
*/
@@ -51,7 +46,6 @@ public function __construct()
5146
$this->predictOptions = new PredictOptions();
5247
$this->pageOptions = new PageOptions();
5348
$this->endpoint = null;
54-
$this->closeFile = false;
5549
$this->rag = false;
5650
$this->workflowId = null;
5751
}

tests/Input/LocalInputSourceTest.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -222,37 +222,6 @@ public function testInputFromRawb64String()
222222
$this->assertEquals(str_replace("\n", "", $pdfBytes), str_replace("\n", "", base64_encode($contents[1])));
223223
}
224224

225-
226-
public function testFileCloseValid()
227-
{
228-
$fileRef = fopen($this->fileTypesDir . "/pdf/multipage.pdf", "r");
229-
$inputDoc = $this->dummyClient->sourceFromFile($fileRef);
230-
$this->assertTrue(is_resource($inputDoc->getFilePtr()));
231-
$inputDoc->close();
232-
$this->assertFalse(is_resource($inputDoc->getFilePtr()));
233-
}
234-
235-
public function testFileCloseInvalid()
236-
{
237-
$fileRef = fopen($this->fileTypesDir . "/pdf/multipage.pdf", "r");
238-
$inputDoc = $this->dummyClient->sourceFromFile($fileRef);
239-
$inputDoc->enableStrictMode();
240-
fclose($fileRef);
241-
$this->expectException(MindeeSourceException::class);
242-
$this->expectExceptionMessage("File is already closed.");
243-
$inputDoc->close();
244-
}
245-
246-
public function testFileCloseNotImplemented()
247-
{
248-
$pdfBytes = file_get_contents($this->fileTypesDir . "/receipt.txt");
249-
$inputDoc = $this->dummyClient->sourceFromb64String($pdfBytes, "dummy.pdf");
250-
$inputDoc->enableStrictMode();
251-
$this->expectException(MindeeSourceException::class);
252-
$this->expectExceptionMessage("Closing is not implemented on this type of local input source.");
253-
$inputDoc->close();
254-
}
255-
256225
public function testShouldNotRaiseMimeErrorForBrokenFixablePdf()
257226
{
258227
$this->expectNotToPerformAssertions();

0 commit comments

Comments
 (0)