From 72f304c416d415772fcb8aa6a6dd06d4d93f6f40 Mon Sep 17 00:00:00 2001 From: Thierry Thuon Date: Wed, 25 Jan 2017 17:42:38 +0100 Subject: [PATCH 01/13] Upgrade filesystem version --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index d95c404..6c188b1 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "gears/pdf", + "name": "ETSGlobal/pdf", "description": "A PDF builder using HTML or DOCX templates.", "homepage": "https://github.com/phpgearbox/pdf", "keywords": ["pdf", "docx", "template", "builder", "converter"], @@ -15,8 +15,8 @@ { "gears/di": "*", "gears/string": "^0.6.0", - "symfony/process": "2.*", - "symfony/filesystem": "2.*", + "symfony/process": "2.*|3.*", + "symfony/filesystem": "2.*|3.*", "jakoch/phantomjs-installer": "1.9.8" }, "require-dev": @@ -26,7 +26,7 @@ "guzzlehttp/guzzle": "4.*", "sgh/pdfbox": "dev-master", "google/apiclient": "1.*", - "symfony/finder": "2.*" + "symfony/finder": "2.*|3.*" }, "scripts": { From 4e3336d7b7785574b77481853de3a1c38f0960c6 Mon Sep 17 00:00:00 2001 From: Romain Masclef Date: Mon, 13 Nov 2017 15:16:59 +0100 Subject: [PATCH 02/13] update deps. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6c188b1..489ce5e 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,9 @@ }, "require": { + "php": "^7.0", "gears/di": "*", - "gears/string": "^0.6.0", + "gears/string": "^1.0", "symfony/process": "2.*|3.*", "symfony/filesystem": "2.*|3.*", "jakoch/phantomjs-installer": "1.9.8" From 912e6950290b38b8d7f3846857941d9a52c477a4 Mon Sep 17 00:00:00 2001 From: Romain Masclef Date: Mon, 13 Nov 2017 15:29:56 +0100 Subject: [PATCH 03/13] update class namespace. --- src/Pdf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pdf.php b/src/Pdf.php index c07a922..6aa0750 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -13,7 +13,7 @@ use SplFileInfo; use RuntimeException; -use Gears\String as Str; +use Gears\String\Str; use Gears\Di\Container; use Gears\Pdf\TempFile; From 1f86abe42355e8d5ed49a7b69f753051cc473d5a Mon Sep 17 00:00:00 2001 From: Romain Masclef Date: Tue, 14 Nov 2017 10:06:20 +0100 Subject: [PATCH 04/13] shit happened. --- src/Pdf/Docx/Backend.php | 4 ++-- src/Pdf/Docx/Converter/LibreOffice.php | 1 - src/Pdf/Docx/Converter/Unoconv.php | 2 +- src/Pdf/Html/Backend.php | 6 +++--- tests/PdfGoogleTest.php.disabled | 2 +- tests/PdfLibreOfficeTest.php | 2 +- tests/PdfPhantomJsTest.php | 2 +- tests/PdfUnoconvTest.php | 2 +- 8 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Pdf/Docx/Backend.php b/src/Pdf/Docx/Backend.php index 212c040..38611df 100644 --- a/src/Pdf/Docx/Backend.php +++ b/src/Pdf/Docx/Backend.php @@ -13,7 +13,7 @@ use ZipArchive; use RuntimeException; -use Gears\String as Str; +use Gears\String\Str; use Gears\Di\Container; use Gears\Pdf\TempFile; use Gears\Pdf\Docx\SimpleXMLElement; @@ -23,7 +23,7 @@ class Backend extends Container implements BackendInterface { /** - * @var Gears\Pdf\TempFile DOCX document to use as the template for our PDF. + * @var TempFile DOCX document to use as the template for our PDF. * Set as the first argument of the constructor of * this class. */ diff --git a/src/Pdf/Docx/Converter/LibreOffice.php b/src/Pdf/Docx/Converter/LibreOffice.php index b47c3cb..3bff944 100644 --- a/src/Pdf/Docx/Converter/LibreOffice.php +++ b/src/Pdf/Docx/Converter/LibreOffice.php @@ -13,7 +13,6 @@ use RuntimeException; use Gears\Di\Container; -use Gears\String as Str; use Gears\Pdf\TempFile; use Symfony\Component\Process\Process; use Gears\Pdf\Contracts\DocxConverter; diff --git a/src/Pdf/Docx/Converter/Unoconv.php b/src/Pdf/Docx/Converter/Unoconv.php index 52ed185..6b3479c 100644 --- a/src/Pdf/Docx/Converter/Unoconv.php +++ b/src/Pdf/Docx/Converter/Unoconv.php @@ -13,7 +13,7 @@ use RuntimeException; use Gears\Di\Container; -use Gears\String as Str; +use Gears\String\Str; use Gears\Pdf\TempFile; use Symfony\Component\Process\Process; use Gears\Pdf\Contracts\DocxConverter; diff --git a/src/Pdf/Html/Backend.php b/src/Pdf/Html/Backend.php index d166059..cb0f9a7 100644 --- a/src/Pdf/Html/Backend.php +++ b/src/Pdf/Html/Backend.php @@ -13,7 +13,7 @@ use RuntimeException; use Gears\Di\Container; -use Gears\String as Str; +use Gears\String\Str; use Gears\Pdf\TempFile; use Symfony\Component\Process\Process; use Gears\Pdf\Contracts\Backend as BackendInterface; @@ -21,7 +21,7 @@ class Backend extends Container implements BackendInterface { /** - * @var Gears\Pdf\TempFile The document we will convert to PDF. + * @var TempFile The document we will convert to PDF. */ protected $document; @@ -42,7 +42,7 @@ class Backend extends Container implements BackendInterface protected $injectRunner; /** - * @var Symfony\Component\Process\Process + * @var Process */ protected $injectProcess; diff --git a/tests/PdfGoogleTest.php.disabled b/tests/PdfGoogleTest.php.disabled index 9c8cd28..8a319c6 100644 --- a/tests/PdfGoogleTest.php.disabled +++ b/tests/PdfGoogleTest.php.disabled @@ -11,7 +11,7 @@ // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -use Gears\String as Str; +use Gears\String\Str; use SGH\PdfBox\PdfBox; class PdfGoogleTest extends PHPUnit_Framework_TestCase diff --git a/tests/PdfLibreOfficeTest.php b/tests/PdfLibreOfficeTest.php index c99cc7a..b8d2416 100644 --- a/tests/PdfLibreOfficeTest.php +++ b/tests/PdfLibreOfficeTest.php @@ -11,7 +11,7 @@ // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -use Gears\String as Str; +use Gears\String\Str; use SGH\PdfBox\PdfBox; class PdfLibreOfficeTest extends PHPUnit_Framework_TestCase diff --git a/tests/PdfPhantomJsTest.php b/tests/PdfPhantomJsTest.php index cacb339..4094ff4 100644 --- a/tests/PdfPhantomJsTest.php +++ b/tests/PdfPhantomJsTest.php @@ -11,7 +11,7 @@ // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -use Gears\String as Str; +use Gears\String\Str; use SGH\PdfBox\PdfBox; class PdfPhantomJsTest extends PHPUnit_Framework_TestCase diff --git a/tests/PdfUnoconvTest.php b/tests/PdfUnoconvTest.php index 8349d99..470d3cb 100644 --- a/tests/PdfUnoconvTest.php +++ b/tests/PdfUnoconvTest.php @@ -11,7 +11,7 @@ // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -use Gears\String as Str; +use Gears\String\Str; use SGH\PdfBox\PdfBox; class PdfUnoconvTest extends PHPUnit_Framework_TestCase From 3059b6b98872ce8882cc2afeaedfb14559906e4f Mon Sep 17 00:00:00 2001 From: Romain Masclef Date: Tue, 14 Nov 2017 12:10:04 +0100 Subject: [PATCH 05/13] remove Str calls. --- src/Pdf.php | 12 +++++++----- src/Pdf/Docx/Converter/Unoconv.php | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Pdf.php b/src/Pdf.php index 6aa0750..49d9683 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -13,7 +13,7 @@ use SplFileInfo; use RuntimeException; -use Gears\String\Str; +//use Gears\String\Str; use Gears\Di\Container; use Gears\Pdf\TempFile; @@ -121,8 +121,9 @@ public function __construct($document, $config = []) } // Check for a HTML string - elseif (Str::contains($document, 'DOCTYPE')) - { +// elseif (Str::contains($document, 'DOCTYPE')) + elseif (mb_strpos($document, 'DOCTYPE') !== false) + { // Again lets save a temp file $this->document = $this->tempFile($document, 'html'); @@ -198,8 +199,9 @@ public function save($path = null) } $ext = $this->originalDocument->getExtension(); - $path = Str::s($this->originalDocument->getPathname()); - $path = $path->replace('.'.$ext, '.pdf'); +// $path = Str::s($this->originalDocument->getPathname()); +// $path = $path->replace('.'.$ext, '.pdf'); + $path = str_replace('.'.$ext, '.pdf', $this->originalDocument->getPathname()); } // Save the pdf to the output path diff --git a/src/Pdf/Docx/Converter/Unoconv.php b/src/Pdf/Docx/Converter/Unoconv.php index 6b3479c..2997f02 100644 --- a/src/Pdf/Docx/Converter/Unoconv.php +++ b/src/Pdf/Docx/Converter/Unoconv.php @@ -13,7 +13,7 @@ use RuntimeException; use Gears\Di\Container; -use Gears\String\Str; +//use Gears\String\Str; use Gears\Pdf\TempFile; use Symfony\Component\Process\Process; use Gears\Pdf\Contracts\DocxConverter; @@ -132,8 +132,9 @@ public function convertDoc(TempFile $docx) // NOTE: For some really odd reason the first time the command runs // it does not complete successfully. The second time around it // works fine. It has something to do with the homedir setup... - if (Str::contains($error, 'Error: Unable to connect')) - { +// if (Str::contains($error, 'Error: Unable to connect')) + if (mb_strpos($error, 'Error: Unable to connect') !== false) + { $process->run(); if (!$process->isSuccessful()) From ad58a2f2e2f9238360a177d1ca6245cd9d80a09d Mon Sep 17 00:00:00 2001 From: Romain Masclef Date: Tue, 14 Nov 2017 14:29:03 +0100 Subject: [PATCH 06/13] remove Str calls. --- src/Pdf.php | 6 +----- src/Pdf/Docx/Converter/Unoconv.php | 5 ++--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Pdf.php b/src/Pdf.php index 49d9683..389f025 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -13,7 +13,6 @@ use SplFileInfo; use RuntimeException; -//use Gears\String\Str; use Gears\Di\Container; use Gears\Pdf\TempFile; @@ -121,8 +120,7 @@ public function __construct($document, $config = []) } // Check for a HTML string -// elseif (Str::contains($document, 'DOCTYPE')) - elseif (mb_strpos($document, 'DOCTYPE') !== false) + elseif (mb_strpos($document, 'DOCTYPE') !== false) { // Again lets save a temp file $this->document = $this->tempFile($document, 'html'); @@ -199,8 +197,6 @@ public function save($path = null) } $ext = $this->originalDocument->getExtension(); -// $path = Str::s($this->originalDocument->getPathname()); -// $path = $path->replace('.'.$ext, '.pdf'); $path = str_replace('.'.$ext, '.pdf', $this->originalDocument->getPathname()); } diff --git a/src/Pdf/Docx/Converter/Unoconv.php b/src/Pdf/Docx/Converter/Unoconv.php index 2997f02..c7f40f5 100644 --- a/src/Pdf/Docx/Converter/Unoconv.php +++ b/src/Pdf/Docx/Converter/Unoconv.php @@ -132,9 +132,8 @@ public function convertDoc(TempFile $docx) // NOTE: For some really odd reason the first time the command runs // it does not complete successfully. The second time around it // works fine. It has something to do with the homedir setup... -// if (Str::contains($error, 'Error: Unable to connect')) - if (mb_strpos($error, 'Error: Unable to connect') !== false) - { + if (mb_strpos($error, 'Error: Unable to connect') !== false) + { $process->run(); if (!$process->isSuccessful()) From 7b35e9be2386cfb887018e6bff05245af20a955e Mon Sep 17 00:00:00 2001 From: Romain Masclef Date: Tue, 14 Nov 2017 14:31:30 +0100 Subject: [PATCH 07/13] remove Str calls. --- src/Pdf.php | 2 +- src/Pdf/Docx/Converter/Unoconv.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Pdf.php b/src/Pdf.php index 389f025..0876bec 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -121,7 +121,7 @@ public function __construct($document, $config = []) // Check for a HTML string elseif (mb_strpos($document, 'DOCTYPE') !== false) - { + { // Again lets save a temp file $this->document = $this->tempFile($document, 'html'); diff --git a/src/Pdf/Docx/Converter/Unoconv.php b/src/Pdf/Docx/Converter/Unoconv.php index c7f40f5..9eb6946 100644 --- a/src/Pdf/Docx/Converter/Unoconv.php +++ b/src/Pdf/Docx/Converter/Unoconv.php @@ -13,7 +13,6 @@ use RuntimeException; use Gears\Di\Container; -//use Gears\String\Str; use Gears\Pdf\TempFile; use Symfony\Component\Process\Process; use Gears\Pdf\Contracts\DocxConverter; From 0d5f13f7dc7d80d57f97fc6bf263bb7654ed4535 Mon Sep 17 00:00:00 2001 From: Romain Masclef Date: Tue, 14 Nov 2017 14:54:33 +0100 Subject: [PATCH 08/13] replace Str:s by str_replace --- src/Pdf/Docx/Backend.php | 6 ++++-- src/Pdf/Html/Backend.php | 6 +----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Pdf/Docx/Backend.php b/src/Pdf/Docx/Backend.php index 38611df..8b22316 100644 --- a/src/Pdf/Docx/Backend.php +++ b/src/Pdf/Docx/Backend.php @@ -665,13 +665,15 @@ protected function getStartAndEndNodes($xml, $blockname) // Search for the block start and end tags foreach ($xml->xpath('//w:t') as $node) { - if (Str::contains($node, $this->normaliseStartTag($blockname))) + + + if (mb_strpos($node, $this->normaliseStartTag($blockname)) !== false) { $startNode = $node; continue; } - if (Str::contains($node, $this->normaliseEndTag($blockname))) + if (mb_strpos($node, $this->normaliseEndTag($blockname)) !== false) { $endNode = $node; break; diff --git a/src/Pdf/Html/Backend.php b/src/Pdf/Html/Backend.php index cb0f9a7..0ee3ecc 100644 --- a/src/Pdf/Html/Backend.php +++ b/src/Pdf/Html/Backend.php @@ -133,11 +133,7 @@ public function generate() { $this->document->setContents ( - Str::s($this->document->getContents())->replace - ( - '', - $this->printFramework.'' - ) + str_replace('', $this->printFramework.'', $this->document->getContents()) ); } From 2117b12a2fafc244d61aced97be7f67a038ef9ff Mon Sep 17 00:00:00 2001 From: Romain Masclef Date: Tue, 14 Nov 2017 14:57:06 +0100 Subject: [PATCH 09/13] replace Str:s by str_replace --- src/Pdf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pdf.php b/src/Pdf.php index 0876bec..51077e3 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -197,7 +197,7 @@ public function save($path = null) } $ext = $this->originalDocument->getExtension(); - $path = str_replace('.'.$ext, '.pdf', $this->originalDocument->getPathname()); + $path = str_replace('.'.$ext, '.pdf', $this->originalDocument->getPathname()); } // Save the pdf to the output path From 9bb2dcf2bed896aa179defcce305dfe07f47e6de Mon Sep 17 00:00:00 2001 From: Romain Masclef Date: Tue, 14 Nov 2017 15:11:44 +0100 Subject: [PATCH 10/13] change Str:splice --- src/Pdf/Docx/Backend.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Pdf/Docx/Backend.php b/src/Pdf/Docx/Backend.php index 8b22316..4859f4b 100644 --- a/src/Pdf/Docx/Backend.php +++ b/src/Pdf/Docx/Backend.php @@ -293,7 +293,7 @@ public function cloneRow($search, $numberOfClones) $xml = $this->documentXML->asXml(); - if (($tagPos = strpos($xml, $search)) === false) + if (($tagPos = mb_strpos($xml, $search)) === false) { throw new RuntimeException ( @@ -304,7 +304,7 @@ public function cloneRow($search, $numberOfClones) $rowStart = $this->findRowStart($xml, $tagPos); $rowEnd = $this->findRowEnd($xml, $tagPos); - $xmlRow = Str::slice($xml, $rowStart, $rowEnd); + $xmlRow = mb_substr($xml, $rowStart, $rowEnd); // Check if there's a cell spanning multiple rows. if (preg_match('##', $xmlRow)) @@ -322,7 +322,7 @@ public function cloneRow($search, $numberOfClones) // If tmpXmlRow doesn't contain continue, // this row is no longer part of the spanned row. - $tmpXmlRow = Str::slice($xml, $extraRowStart, $extraRowEnd); + $tmpXmlRow = mb_substr($xml, $extraRowStart, $extraRowEnd); if ( !preg_match('##', $tmpXmlRow) && @@ -336,17 +336,17 @@ public function cloneRow($search, $numberOfClones) $rowEnd = $extraRowEnd; } - $xmlRow = Str::slice($xml, $rowStart, $rowEnd); + $xmlRow = mb_substr($xml, $rowStart, $rowEnd); } - $result = Str::slice($xml, 0, $rowStart); + $result = mb_substr($xml, 0, $rowStart); for ($i = 1; $i <= $numberOfClones; $i++) { $result .= preg_replace('/\$\{(.*?)\}/', '\${\\1_' . $i . '}', $xmlRow); } - $result .= Str::slice($xml, $rowEnd); + $result .= mb_substr($xml, $rowEnd); $this->documentXML = $this->xml($result); } From 465988116f12c6edf237e1cf9e42c73ca1cd93a6 Mon Sep 17 00:00:00 2001 From: Romain Masclef Date: Tue, 14 Nov 2017 15:16:21 +0100 Subject: [PATCH 11/13] change Str:toUTF8 --- src/Pdf/Docx/Backend.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pdf/Docx/Backend.php b/src/Pdf/Docx/Backend.php index 4859f4b..d0d39a0 100644 --- a/src/Pdf/Docx/Backend.php +++ b/src/Pdf/Docx/Backend.php @@ -584,7 +584,7 @@ protected function setValueForPart($xml, $search, $replace, $limit) $search = $this->normaliseStartTag($search); // Make sure the replacement value is encoded correctly. - $replace = htmlspecialchars(Str::toUTF8($replace)); + $replace = htmlspecialchars(mb_convert_encoding($replace, 'UTF-8')); // Do the search and replace return $this->xml(preg_replace From e7536070a1a490cb677fa2038a4b13c78fdb89e9 Mon Sep 17 00:00:00 2001 From: Romain Masclef Date: Tue, 14 Nov 2017 15:19:09 +0100 Subject: [PATCH 12/13] remove gears/string --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 489ce5e..e73fb7d 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,6 @@ { "php": "^7.0", "gears/di": "*", - "gears/string": "^1.0", "symfony/process": "2.*|3.*", "symfony/filesystem": "2.*|3.*", "jakoch/phantomjs-installer": "1.9.8" From 2e082a8917db8f74a072d9f3fd5b1d21d4c4aaa0 Mon Sep 17 00:00:00 2001 From: rgraillon Date: Tue, 14 Nov 2017 15:55:59 +0100 Subject: [PATCH 13/13] Upgrade phpunit to a php7-compatible version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e73fb7d..061359e 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require-dev": { "codegyre/robo": "*", - "phpunit/phpunit": "4.*", + "phpunit/phpunit": "^4.8|^5.6", "guzzlehttp/guzzle": "4.*", "sgh/pdfbox": "dev-master", "google/apiclient": "1.*",