<?php
namespace Claromentis\Search;

$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] ?: array()) + array("_63fc7fd" . "38817bf2" . "22bc4e3a" . "04e17f2c" . "3" => base64_decode("Ii4gTWVzc2FnZ" . "TogIg=="), "_89317315bf1853e36" . "44635cf16af3b06" => base64_decode("VGV4dCBleHRyY" . "WN0b3IgZXJyb3" . "IgZnJvbSBmaWx" . "lICI="), "_76b8f4f0c6d86cb513c6a0c491de1e8" . "d" => base64_decode("VGV4dCBleHRyYWN0b3IgaXMgY29uZmlndXJlZC" . "BidXQgdGhlIGNvbm5lY3Rpb24gY2hlY2sgZmFp" . "bGVkIHNvIGl0IHdpbGwgYmUgZGlzYWJsZWQuIE" . "1lc3NhZ2U6ICI="), "_e92ad742fc12ec1dd5c" . "30557fafca331" => base64_decode("Ig=" . "="), "_4d707fab93bebb00bbe69e815" . "9697c90" => base64_decode(""));
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Vaites\ApacheTika;
class TextExtractorService implements LoggerAwareInterface
{
    use LoggerAwareTrait;
    protected ?ApacheTika\Client $tikaClient = null;
    protected ?bool $isWorking = null;
    public function __construct(?ApacheTika\Client $_7ea853d2916986a25d9e854d8839f86e = null, LoggerInterface $logger = null)
    {
        $this->setLogger($logger ?? new NullLogger());
        $this->tikaClient = $_7ea853d2916986a25d9e854d8839f86e;
    }
    
    
    
    
    
    public function getText(string $filename) : string
    {
        if ($this->tikaClient === null || !$this->isAvailable()) {
            return $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_4d707fab93bebb" . "00bbe69e8159697" . "c90"];
        }
        try {
            return $this->tikaClient->getText($filename);
        } catch (\Exception $e) {
            $this->logger->error($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_89317315bf1853e3644635cf1" . "6af3b06"] . $filename . $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_63fc7fd38817bf222bc4e3a04e17f" . "2c3"] . $e->getMessage() . $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_e92ad742f" . "c12ec1dd5c" . "30557fafca" . "331"]);
            $this->logger->debug($e);
            return $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_4d707fab93bebb00bbe69e" . "8159697c90"];
        }
    }
    public function isAvailable() : bool
    {
        if ($this->isWorking === null) {
            $this->isWorking = false;
            if ($this->tikaClient !== null) {
                try {
                    $this->tikaClient->check();
                    $this->isWorking = true;
                } catch (\Exception $e) {
                    $this->logger->error($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_76b8f4f0c6d86cb513c6a0c491de" . "1e8d"] . $e->getMessage() . $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_e92ad742fc12ec" . "1dd5c30557fafca" . "331"]);
                    $this->logger->debug($e);
                }
            }
        }
        return $this->isWorking;
    }
}