Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions src/Http/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions src/Http/MindeeApiV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 0 additions & 21 deletions src/Input/FileInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
8 changes: 0 additions & 8 deletions src/Input/InferenceParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -62,7 +57,6 @@ class InferenceParameters
* @param string|null $alias Optional file alias.
* @param array<string>|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,
Expand All @@ -73,7 +67,6 @@ public function __construct(
?string $alias = null,
?array $webhooksIds = null,
?PollingOptions $pollingOptions = null,
?bool $closeFile = null
) {
$this->modelId = $modelId;
if (!$pollingOptions) {
Expand All @@ -85,7 +78,6 @@ public function __construct(
$this->polygon = $polygon;
$this->confidence = $confidence;

$this->closeFile = (bool) $closeFile;
if (isset($alias)) {
$this->alias = $alias;
}
Expand Down
35 changes: 0 additions & 35 deletions src/Input/LocalInputSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -100,7 +95,6 @@ private function checkMimeType()
public function __construct()
{
$this->checkMimeType();
$this->throwsOnClose = false;
}

/**
Expand Down Expand Up @@ -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).
Expand Down
6 changes: 0 additions & 6 deletions src/Input/PredictMethodOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*/
Expand All @@ -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;
}
Expand Down
31 changes: 0 additions & 31 deletions tests/Input/LocalInputSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading