From 0d973128a753ab12e80e0452ee23f7c102825615 Mon Sep 17 00:00:00 2001 From: Denys Moskovchenko Date: Wed, 27 Jul 2022 17:20:08 +0300 Subject: [PATCH] Add support of infilter --- src/Converter.php | 3 ++- src/LowrapperParameters.php | 28 +++++++++++++++++++++++++++- tests/ConverterTest.php | 11 ++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/Converter.php b/src/Converter.php index 5774877..d9274ee 100644 --- a/src/Converter.php +++ b/src/Converter.php @@ -113,10 +113,11 @@ public function convert(LowrapperParameters $parameters) $options = array_merge($this->defaultOptions, [ $documentType ? '--' . $documentType : '', + $parameters->getInputFilter() ? sprintf('--infilter=%s', $parameters->getInputFilter()) : null, '--convert-to "' . $parameters->getOutputFormat() . $outputFilters . '"', '"' . $inputFile . '"', ]); - $command = $this->binaryPath . ' ' . implode(' ', $options); + $command = $this->binaryPath . ' ' . implode(' ', array_filter($options)); $process = $this->createProcess($command); diff --git a/src/LowrapperParameters.php b/src/LowrapperParameters.php index 003f15b..a76acc5 100644 --- a/src/LowrapperParameters.php +++ b/src/LowrapperParameters.php @@ -55,6 +55,14 @@ class LowrapperParameters */ protected $outputFilters = []; + /** + * Input filters, eg. + * - Text (encoded) + * - UTF8 + * @var ?string + */ + protected $inputFilter = null; + public function __construct( /*string*/ $outputFormat = null, /*string*/ $outputFile = null, @@ -163,6 +171,24 @@ public function getOutputFilters()//: array return $this->outputFilters; } + /** + * @param string $outputFilter + * @return LowrapperParameters + */ + public function setInputFilter(/*string*/ $inputFilter) + { + $this->inputFilter = $inputFilter; + return $this; + } + + /** + * @return ?string + */ + public function getInputFilter()//: ?string + { + return $this->inputFilter; + } + /** * @return mixed */ @@ -183,4 +209,4 @@ public function setInputData($inputData) -} \ No newline at end of file +} diff --git a/tests/ConverterTest.php b/tests/ConverterTest.php index ea1b379..16763b1 100644 --- a/tests/ConverterTest.php +++ b/tests/ConverterTest.php @@ -96,6 +96,15 @@ public function converterProvider() $command .'--web --convert-to "text:some filter" "some_temp_file"', null, ], + 'Input filter' => [ + (new LowrapperParameters()) + ->setInputFile('test.html') + ->setOutputFormat(Format::TEXT_TEXT) + ->setOutputFile('test.text') + ->setInputFilter('some'), + $command .'--web --infilter=some --convert-to "text:Text (encoded):UTF8" "some_temp_file"', + null, + ], 'Default text filter' => [ (new LowrapperParameters()) ->setInputFile('test.html') @@ -124,4 +133,4 @@ public function converterProvider() ]; } -} \ No newline at end of file +}