2021-11-01 11:00:59 -03:00
|
|
|
<?php
|
|
|
|
namespace Contabilidad\Common\Service;
|
|
|
|
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
|
|
|
|
class PdfHandler {
|
|
|
|
protected Client $client;
|
|
|
|
protected string $folder;
|
|
|
|
protected string $url;
|
|
|
|
public function __construct(Client $client, string $pdf_folder, string $url) {
|
|
|
|
$this->client = $client;
|
|
|
|
$this->folder = $pdf_folder;
|
|
|
|
$this->url = $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function load(): ?array {
|
|
|
|
$folder = $this->folder;
|
|
|
|
$files = new \DirectoryIterator($folder);
|
|
|
|
$output = [];
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file->isDir() or $file->getExtension() != 'pdf') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$output []= ['filename' => $file->getBasename()];
|
|
|
|
}
|
|
|
|
$response = $this->client->post($this->url, ['json' => ['files' => $output]]);
|
2021-11-02 15:37:36 -03:00
|
|
|
$output = json_decode($response->getBody());
|
2021-11-01 11:00:59 -03:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|