From 4bc8368e4e591d9bab4c65449456aca3e41fd03b Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 1 Feb 2020 01:16:07 +0100 Subject: [PATCH 01/24] - Switching to Laminas - Updating to dompdf 0.8.x --- composer.json | 4 ++-- src/Factory/dompdfFactory.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index b132b04..6ae55d1 100644 --- a/composer.json +++ b/composer.json @@ -6,8 +6,8 @@ "homepage": "https://www.phpcontext.com", "require": { "php": "^5.5 || ^7.0", - "dompdf/dompdf": "^0.7.0", - "zendframework/zend-servicemanager": "^2.0 || ^3.0" + "dompdf/dompdf": "^0.8.0", + "laminas/laminas-servicemanager": "^2.0 || ^3.0" }, "autoload": { "psr-4": { diff --git a/src/Factory/dompdfFactory.php b/src/Factory/dompdfFactory.php index 0a3d1fa..43f0ef9 100644 --- a/src/Factory/dompdfFactory.php +++ b/src/Factory/dompdfFactory.php @@ -4,8 +4,8 @@ use Dompdf\Dompdf; use Dompdf\Options; use Interop\Container\ContainerInterface; -use Zend\ServiceManager\FactoryInterface; -use Zend\ServiceManager\ServiceLocatorInterface; +use Laminas\ServiceManager\FactoryInterface; +use Laminas\ServiceManager\ServiceLocatorInterface; class dompdfFactory implements FactoryInterface { From de3c1122270088fb20a30a314ece567687a967f4 Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 6 Jun 2020 14:08:49 +0200 Subject: [PATCH 02/24] Finalising switch to Laminas. --- .travis.yml | 14 ++--- README.md | 69 ++++++++++++++++++++----- composer.json | 16 +++--- src/Factory/dompdfFactory.php | 17 +++--- src/Module.php | 1 + src/Tests/Factory/dompdfFactoryTest.php | 1 + src/Tests/ModuleTest.php | 1 + 7 files changed, 80 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index 79314dd..e2befb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,10 @@ language: php php: - - 5.5 - - 5.6 - - 7.0 - - nightly - - hhvm - -matrix: - allow_failures: - - php: nightly - - php: hhvm + - 7.1 + - 7.2 + - 7.3 + - 7.4 before_script: - travis_retry composer self-update diff --git a/README.md b/README.md index 4fd161f..822435b 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ dompdfmodule ============ -DOMPDF library wrapper as lightweight ZF2/ZF3 module. +DOMPDF library wrapper as lightweight Laminas module. -[![Build Status](https://travis-ci.org/mikemix/dompdfmodule.svg?branch=master)](https://travis-ci.org/mikemix/dompdfmodule) +[![Build Status](https://travis-ci.org/rarog/dompdfmodule.svg?branch=master)](https://travis-ci.org/rarog/dompdfmodule) ## Requirements - - [Zend Framework 2 or 3](https://framework.zend.com/) + - [Laminas](https://getlaminas.org/) ## Installation Installation of DOMPDFModule uses PHP Composer. For more information about @@ -20,14 +20,14 @@ PHP Composer, please visit the official [PHP Composer site](http://getcomposer.o ```json { "require": { - "mikemix/dompdfmodule": "^3.0" + "rarog/dompdfmodule": "^4.0" } } ``` 3. install PHP Composer via `curl -s http://getcomposer.org/installer | php` (on windows, download http://getcomposer.org/installer and execute it with PHP) 4. run `php composer.phar install` - 5. open `my/project/directory/config/application.config.php` and add the following key to your `modules`: + 5. open `my/project/directory/config/application.config.php` and add the following key to your `modules`: ```php 'dompdfmodule', @@ -40,20 +40,65 @@ Full list of possible settings is available at the official [DOMPDF library](htt #### Example usage -> Side note: use of `getServiceLocator()` in the controller is deprecated since in ZF3. Make sure you create your controller via a factory and inject the Dompdf object in the constructor. +Controller factory ```php get('dompdf') + ); + } +} +``` + +Controller + +```php +dompdf = $dompdf; + } public function indexAction() { - /** @var \Dompdf\Dompdf $dompdf */ - $dompdf = $this->getServiceLocator()->get('dompdf'); - $dompdf->load_html('Ehlo World'); - $dompdf->render(); + $this->dompdf->load_html('Hello World'); + $this->dompdf->render(); - file_put_contents(__DIR__ . '/document.pdf', $dompdf->output()); + file_put_contents(__DIR__ . '/document.pdf', $this->dompdf->output()); } +} ``` diff --git a/composer.json b/composer.json index 6ae55d1..321207d 100644 --- a/composer.json +++ b/composer.json @@ -1,20 +1,16 @@ { - "name": "mikemix/dompdfmodule", + "name": "rarog/dompdfmodule", "type": "library", - "description": "DOMPDF Zend Framework lightweight module", - "keywords": ["pdf","dompdf", "zf2", "zf3"], - "homepage": "https://www.phpcontext.com", + "description": "DOMPDF Laminas lightweight module", + "keywords": ["pdf","dompdf", "laminas"], "require": { - "php": "^5.5 || ^7.0", - "dompdf/dompdf": "^0.8.0", - "laminas/laminas-servicemanager": "^2.0 || ^3.0" + "php": "^7.1", + "dompdf/dompdf": "^0.8.4", + "laminas/laminas-servicemanager": "^3.0" }, "autoload": { "psr-4": { "dompdfmodule\\": "src/" } - }, - "suggest": { - "mikemix/mxdi-module": "Configure dependency injection with annotations" } } diff --git a/src/Factory/dompdfFactory.php b/src/Factory/dompdfFactory.php index 43f0ef9..c5be8c0 100644 --- a/src/Factory/dompdfFactory.php +++ b/src/Factory/dompdfFactory.php @@ -1,24 +1,27 @@ createFromConfig($container->get('config')); } - public function createService(ServiceLocatorInterface $serviceLocator) - { - return $this->createFromConfig($serviceLocator->get('config')); - } - + /** + * @param array $config Configuration + * @return Dompdf Dompdf instance + */ protected function createFromConfig(array $config) { $userConfig = isset($config['dompdf']) ? $config['dompdf'] : []; diff --git a/src/Module.php b/src/Module.php index 158c337..b132d77 100644 --- a/src/Module.php +++ b/src/Module.php @@ -1,4 +1,5 @@ Date: Sat, 6 Jun 2020 14:10:23 +0200 Subject: [PATCH 03/24] Fixing example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 822435b..216039f 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Controller ```php Date: Sat, 6 Jun 2020 14:13:17 +0200 Subject: [PATCH 04/24] Requiring fitting PHPUnit versions. --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 321207d..54e244f 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,9 @@ "dompdf/dompdf": "^0.8.4", "laminas/laminas-servicemanager": "^3.0" }, + "require-dev": { + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", + }, "autoload": { "psr-4": { "dompdfmodule\\": "src/" From b6754973c7effccb19d38617448819e0127d3052 Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 6 Jun 2020 14:14:26 +0200 Subject: [PATCH 05/24] Fixing composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 54e244f..be6b69b 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "laminas/laminas-servicemanager": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "autoload": { "psr-4": { From d55273a730ea6e337bd62ecec2b5ba3d47576593 Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 6 Jun 2020 14:19:10 +0200 Subject: [PATCH 06/24] Call the local PHPUnit version. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e2befb0..a5a35b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ before_script: - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source script: - - phpunit + - ./vendor/bin/phpunit From 39d3a2544288335dc9b2cb9880669ee5c9164a4c Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 6 Jun 2020 14:26:12 +0200 Subject: [PATCH 07/24] Fixing for new PHPUnit version. --- src/Tests/Factory/dompdfFactoryTest.php | 2 +- src/Tests/ModuleTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tests/Factory/dompdfFactoryTest.php b/src/Tests/Factory/dompdfFactoryTest.php index 34e78e8..7e27362 100644 --- a/src/Tests/Factory/dompdfFactoryTest.php +++ b/src/Tests/Factory/dompdfFactoryTest.php @@ -4,7 +4,7 @@ use dompdfmodule\Factory\dompdfFactory; -class dompdfFactoryTest extends \PHPUnit_Framework_TestCase +class dompdfFactoryTest extends \PHPUnit\Framework\TestCase { private $factory; diff --git a/src/Tests/ModuleTest.php b/src/Tests/ModuleTest.php index 7297284..894f07b 100644 --- a/src/Tests/ModuleTest.php +++ b/src/Tests/ModuleTest.php @@ -4,7 +4,7 @@ use dompdfmodule\Module; -class ModuleTest extends \PHPUnit_Framework_TestCase +class ModuleTest extends \PHPUnit\Framework\TestCase { public function test_it_returns_config() { From cf229b281b31ba6b261ed5ffd2b8b0273b12ba31 Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 6 Jun 2020 14:32:52 +0200 Subject: [PATCH 08/24] Adjusting PHPUnit config. --- phpunit.xml | 27 +++++++++++++++++++++++++++ phpunit.xml.dist | 22 ---------------------- 2 files changed, 27 insertions(+), 22 deletions(-) create mode 100644 phpunit.xml delete mode 100644 phpunit.xml.dist diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..422a2d1 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,27 @@ + + + + ./src/Tests + + + + ./src + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 7da1eef..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,22 +0,0 @@ - - - - ./src/Tests - - - - ./src - - - From 56f0e987d657ee115629702d4c253d6f0e57ee19 Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 6 Jun 2020 14:38:37 +0200 Subject: [PATCH 09/24] Adding phpcs. --- .travis.yml | 1 + composer.json | 3 ++- phpcs.xml | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 phpcs.xml diff --git a/.travis.yml b/.travis.yml index a5a35b6..f29e1d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,3 +12,4 @@ before_script: script: - ./vendor/bin/phpunit + - ./vendor/bin/phpcs diff --git a/composer.json b/composer.json index be6b69b..f5e7b46 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "laminas/laminas-servicemanager": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", + "squizlabs/php_codesniffer": "^3.0" }, "autoload": { "psr-4": { diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..213b766 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,29 @@ + + + Laminas Coding Standard + + + + + + + + + + + + + + + + + + + + + + + + config + src + From 896bf64e891a9374e11c703b4f2fb7e651a15648 Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 6 Jun 2020 14:41:19 +0200 Subject: [PATCH 10/24] Updating test. --- src/Tests/Factory/dompdfFactoryTest.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Tests/Factory/dompdfFactoryTest.php b/src/Tests/Factory/dompdfFactoryTest.php index 7e27362..9fcefea 100644 --- a/src/Tests/Factory/dompdfFactoryTest.php +++ b/src/Tests/Factory/dompdfFactoryTest.php @@ -8,11 +8,24 @@ class dompdfFactoryTest extends \PHPUnit\Framework\TestCase { private $factory; - public function setUp() + /** + * {@inheritDoc} + * @see \PHPUnit\Framework\TestCase::setUp() + */ + protected function setUp(): void { $this->factory = new dompdfFactory(); } + /** + * {@inheritDoc} + * @see \PHPUnit\Framework\TestCase::tearDown() + */ + protected function tearDown(): void + { + unset($this->factory); + } + public function test_it_is_initializable() { self::assertInstanceOf('dompdfmodule\Factory\dompdfFactory', $this->factory); From 472ab336efe5404ac9a9cda4ab9f556ec37fce3b Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 6 Jun 2020 14:49:59 +0200 Subject: [PATCH 11/24] Changes to code style. --- src/Factory/{dompdfFactory.php => DompdfFactory.php} | 6 +++--- src/Module.php | 4 +++- .../{dompdfFactoryTest.php => DompdfFactoryTest.php} | 8 ++++---- src/Tests/ModuleTest.php | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) rename src/Factory/{dompdfFactory.php => DompdfFactory.php} (96%) rename src/Tests/Factory/{dompdfFactoryTest.php => DompdfFactoryTest.php} (65%) diff --git a/src/Factory/dompdfFactory.php b/src/Factory/DompdfFactory.php similarity index 96% rename from src/Factory/dompdfFactory.php rename to src/Factory/DompdfFactory.php index c5be8c0..7db4892 100644 --- a/src/Factory/dompdfFactory.php +++ b/src/Factory/DompdfFactory.php @@ -7,7 +7,7 @@ use Interop\Container\ContainerInterface; use Laminas\ServiceManager\Factory\FactoryInterface; -class dompdfFactory implements FactoryInterface +class DompdfFactory implements FactoryInterface { /** * {@inheritDoc} @@ -54,7 +54,7 @@ protected function createFromConfig(array $config) */ protected function createDefaultSettings($dompdfDir) { - return array( + return [ 'logOutputFile' => false, 'defaultMediaType' => 'screen', 'defaultPaperSize' => 'A4', @@ -76,6 +76,6 @@ protected function createDefaultSettings($dompdfDir) 'debugLayoutBlocks' => false, 'debugLayoutInline' => false, 'debugLayoutPaddingBox' => false, - ); + ]; } } diff --git a/src/Module.php b/src/Module.php index b132d77..6551c28 100644 --- a/src/Module.php +++ b/src/Module.php @@ -2,6 +2,8 @@ namespace dompdfmodule; +use dompdfmodule\Factory\DompdfFactory; + class Module { public function getConfig() @@ -12,7 +14,7 @@ public function getConfig() 'dompdf' => false, ], 'factories' => [ - 'dompdf' => 'dompdfmodule\Factory\dompdfFactory', + 'dompdf' => DompdfFactory::class, ], ], ]; diff --git a/src/Tests/Factory/dompdfFactoryTest.php b/src/Tests/Factory/DompdfFactoryTest.php similarity index 65% rename from src/Tests/Factory/dompdfFactoryTest.php rename to src/Tests/Factory/DompdfFactoryTest.php index 9fcefea..cc030b2 100644 --- a/src/Tests/Factory/dompdfFactoryTest.php +++ b/src/Tests/Factory/DompdfFactoryTest.php @@ -2,9 +2,9 @@ namespace dompdfmodule\Tests\Factory; -use dompdfmodule\Factory\dompdfFactory; +use dompdfmodule\Factory\DompdfFactory; -class dompdfFactoryTest extends \PHPUnit\Framework\TestCase +class DompdfFactoryTest extends \PHPUnit\Framework\TestCase { private $factory; @@ -26,8 +26,8 @@ protected function tearDown(): void unset($this->factory); } - public function test_it_is_initializable() + public function testInitWentThrough() { - self::assertInstanceOf('dompdfmodule\Factory\dompdfFactory', $this->factory); + self::assertInstanceOf(DompdfFactory::class, $this->factory); } } diff --git a/src/Tests/ModuleTest.php b/src/Tests/ModuleTest.php index 894f07b..9c7baaf 100644 --- a/src/Tests/ModuleTest.php +++ b/src/Tests/ModuleTest.php @@ -6,10 +6,10 @@ class ModuleTest extends \PHPUnit\Framework\TestCase { - public function test_it_returns_config() + public function testConfigIsReturned() { $module = new Module(); - self::assertInternalType('array', $module->getConfig()); + self::assertIsArray($module->getConfig()); } } From f93dbae94ea938717824eac96525110b3fdca940 Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 6 Jun 2020 14:54:43 +0200 Subject: [PATCH 12/24] Fixing xml. --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 422a2d1..256873b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,4 +1,4 @@ - + Date: Sat, 6 Jun 2020 15:01:09 +0200 Subject: [PATCH 13/24] Adding coveralls. --- README.md | 1 + composer.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 216039f..6896812 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ dompdfmodule DOMPDF library wrapper as lightweight Laminas module. [![Build Status](https://travis-ci.org/rarog/dompdfmodule.svg?branch=master)](https://travis-ci.org/rarog/dompdfmodule) +[![Coverage Status](https://coveralls.io/repos/github/rarog/dompdfmodule/badge.svg?branch=master)](https://coveralls.io/github/rarog/dompdfmodule?branch=master ## Requirements - [Laminas](https://getlaminas.org/) diff --git a/composer.json b/composer.json index f5e7b46..72d1be9 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ }, "require-dev": { "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", - "squizlabs/php_codesniffer": "^3.0" + "squizlabs/php_codesniffer": "^3.0", + "php-coveralls/php-coveralls": "^2.0" }, "autoload": { "psr-4": { From 02e5eceb65c40b3957855fb230ba4e4be4e3f827 Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 6 Jun 2020 15:03:59 +0200 Subject: [PATCH 14/24] Fixing README. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6896812..5836609 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ dompdfmodule DOMPDF library wrapper as lightweight Laminas module. [![Build Status](https://travis-ci.org/rarog/dompdfmodule.svg?branch=master)](https://travis-ci.org/rarog/dompdfmodule) -[![Coverage Status](https://coveralls.io/repos/github/rarog/dompdfmodule/badge.svg?branch=master)](https://coveralls.io/github/rarog/dompdfmodule?branch=master +[![Coverage Status](https://coveralls.io/repos/github/rarog/dompdfmodule/badge.svg?branch=master)](https://coveralls.io/github/rarog/dompdfmodule?branch=master) ## Requirements - [Laminas](https://getlaminas.org/) From 6c9d4a6d4a1e5017c92a602ee12bc55af02e3e1c Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 6 Jun 2020 15:11:56 +0200 Subject: [PATCH 15/24] Travis should upload to Coveralls. --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index f29e1d7..1d5f21b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,3 +13,8 @@ before_script: script: - ./vendor/bin/phpunit - ./vendor/bin/phpcs + +after_script: + - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml + - php vendor/bin/php-coveralls + \ No newline at end of file From 62bc9f1ab9cc1ddd0572dc24c59bd7ea3a885dd2 Mon Sep 17 00:00:00 2001 From: Andrej Sinicyn Date: Sat, 6 Jun 2020 15:31:46 +0200 Subject: [PATCH 16/24] Dompdf directory isn't used since 2.0 --- src/Factory/DompdfFactory.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Factory/DompdfFactory.php b/src/Factory/DompdfFactory.php index 7db4892..318aa19 100644 --- a/src/Factory/DompdfFactory.php +++ b/src/Factory/DompdfFactory.php @@ -26,15 +26,10 @@ protected function createFromConfig(array $config) { $userConfig = isset($config['dompdf']) ? $config['dompdf'] : []; - // evaluate library directory - $dompdfDir = isset($userConfig['DOMPDF_DIR']) ? - $userConfig['DOMPDF_DIR'] : - realpath('vendor/dompdf/dompdf'); - // merge default config with user config if necessary $dompdfConfig = count($userConfig) ? - array_merge($this->createDefaultSettings($dompdfDir), $userConfig) : - $this->createDefaultSettings($dompdfDir); + array_merge($this->createDefaultSettings(), $userConfig) : + $this->createDefaultSettings(); // set options $options = new Options(); @@ -49,10 +44,9 @@ protected function createFromConfig(array $config) /** * Some settings can be evaluated by default. - * @param string $dompdfDir DOMPDF library directory * @return array Default settings */ - protected function createDefaultSettings($dompdfDir) + protected function createDefaultSettings(): array { return [ 'logOutputFile' => false, From 3e531fae2f16326ef62689fafe2174503e98d6f6 Mon Sep 17 00:00:00 2001 From: rarog Date: Sat, 6 Jun 2020 16:23:49 +0200 Subject: [PATCH 17/24] Reorganising --- .gitignore | 5 +- README.md | 18 +++--- composer.json | 55 ++++++++++++------- config/dompdf.config.php.dist | 44 +++++++-------- phpcs.xml | 1 + phpunit.xml | 2 +- src/Factory/DompdfFactory.php | 2 +- src/Module.php | 11 +++- src/Tests/ModuleTest.php | 15 ----- .../Factory/DompdfFactoryTest.php | 14 +++-- test/ModuleTest.php | 19 +++++++ 11 files changed, 107 insertions(+), 79 deletions(-) delete mode 100644 src/Tests/ModuleTest.php rename {src/Tests => test}/Factory/DompdfFactoryTest.php (53%) create mode 100644 test/ModuleTest.php diff --git a/.gitignore b/.gitignore index 486d2a6..d6a14f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -/vendor -phpunit.xml +build/ +vendor/ composer.lock - diff --git a/README.md b/README.md index 5836609..5277125 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ -dompdfmodule +DompdfHelper ============ -DOMPDF library wrapper as lightweight Laminas module. +DompdfHelper - a lightweight library wrapper Laminas module -[![Build Status](https://travis-ci.org/rarog/dompdfmodule.svg?branch=master)](https://travis-ci.org/rarog/dompdfmodule) -[![Coverage Status](https://coveralls.io/repos/github/rarog/dompdfmodule/badge.svg?branch=master)](https://coveralls.io/github/rarog/dompdfmodule?branch=master) +[![Build Status](https://travis-ci.org/rarog/dompdf-helper.svg?branch=master)](https://travis-ci.org/rarog/dompdf-helper) +[![Coverage Status](https://coveralls.io/repos/github/rarog/dompdf-helper/badge.svg?branch=master)](https://coveralls.io/github/rarog/dompdf-helper?branch=master) ## Requirements - [Laminas](https://getlaminas.org/) ## Installation -Installation of DOMPDFModule uses PHP Composer. For more information about +Installation of DompdfHelper uses PHP Composer. For more information about PHP Composer, please visit the official [PHP Composer site](http://getcomposer.org/). #### Installation steps @@ -21,7 +21,7 @@ PHP Composer, please visit the official [PHP Composer site](http://getcomposer.o ```json { "require": { - "rarog/dompdfmodule": "^4.0" + "rarog/dompdf-helper": "^4.0" } } ``` @@ -31,13 +31,13 @@ PHP Composer, please visit the official [PHP Composer site](http://getcomposer.o 5. open `my/project/directory/config/application.config.php` and add the following key to your `modules`: ```php - 'dompdfmodule', + 'DompdfHelper', ``` #### Configuration options -You can override default options via the `dompdf` key in your local or global config files. See the [dompdfmoule\Service\dompdfFactory.php](https://github.com/mikemix/dompdfmodule/blob/master/src/dompdfmodule/Service/dompdfFactory.php#L39) file for the list of default settings. +You can override default options via the `dompdf` key in your local or global config files. See the [config/dompdf.config.php.dist](https://github.com/rarog/dompdf-helper/blob/master/config/dompdf.config.php.dist) file for the list of default settings. -Full list of possible settings is available at the official [DOMPDF library](https://github.com/dompdf/dompdf) site. +Full list of possible settings is available at the official [Dompdf library](https://github.com/dompdf/dompdf) site. #### Example usage diff --git a/composer.json b/composer.json index 72d1be9..2f81250 100644 --- a/composer.json +++ b/composer.json @@ -1,21 +1,36 @@ { - "name": "rarog/dompdfmodule", - "type": "library", - "description": "DOMPDF Laminas lightweight module", - "keywords": ["pdf","dompdf", "laminas"], - "require": { - "php": "^7.1", - "dompdf/dompdf": "^0.8.4", - "laminas/laminas-servicemanager": "^3.0" - }, - "require-dev": { - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", - "squizlabs/php_codesniffer": "^3.0", - "php-coveralls/php-coveralls": "^2.0" - }, - "autoload": { - "psr-4": { - "dompdfmodule\\": "src/" - } - } -} + "name" : "rarog/dompdf-helper", + "type" : "library", + "description" : "DompdfHelper - a lightweight library wrapper Laminas module", + "keywords" : [ + "pdf", + "dompdf", + "laminas" + ], + "require" : { + "php" : "^7.1", + "dompdf/dompdf" : "^0.8.4", + "laminas/laminas-servicemanager" : "^3.0", + "laminas/laminas-modulemanager" : "^2.8" + }, + "require-dev" : { + "phpunit/phpunit" : "^7.0 || ^8.0 || ^9.0", + "squizlabs/php_codesniffer" : "^3.0", + "php-coveralls/php-coveralls" : "^2.0" + }, + "autoload" : { + "psr-4" : { + "DompdfHelper\\" : "src/" + } + }, + "scripts" : { + "cs-check" : "phpcs", + "cs-fix" : "phpcbf", + "test" : "phpunit" + }, + "authors" : [{ + "name" : "mikemix", + "role" : "Original developer" + } + ] +} \ No newline at end of file diff --git a/config/dompdf.config.php.dist b/config/dompdf.config.php.dist index 11f056e..dc1cfc6 100644 --- a/config/dompdf.config.php.dist +++ b/config/dompdf.config.php.dist @@ -1,26 +1,26 @@ false, - 'defaultMediaType' => 'screen', - 'defaultPaperSize' => 'A4', - 'defaultFont' => 'serif', - 'dpi' => 96, - 'pdfBackend' => 'CPDF', - 'fontHeightRatio' => 1.1, - 'isPhpEnabled' => false, - 'isRemoteEnabled' => false, - 'isJavascriptEnabled' => false, - 'isHtml5ParserEnabled' => true, - 'isFontSubsettingEnabled' => false, - 'debugPng' => false, - 'debugKeepTemp' => false, - 'debugCss' => false, - 'debugLayout' => false, - 'debugLayoutLines' => false, - 'debugLayoutBlocks' => false, - 'debugLayoutInline' => false, - 'debugLayoutPaddingBox' => false, + 'dompdf' => [ + 'logOutputFile' => false, + 'defaultMediaType' => 'screen', + 'defaultPaperSize' => 'A4', + 'defaultFont' => 'serif', + 'dpi' => 96, + 'pdfBackend' => 'CPDF', + 'fontHeightRatio' => 1.1, + 'isPhpEnabled' => false, + 'isRemoteEnabled' => false, + 'isJavascriptEnabled' => false, + 'isHtml5ParserEnabled' => true, + 'isFontSubsettingEnabled' => false, + 'debugPng' => false, + 'debugKeepTemp' => false, + 'debugCss' => false, + 'debugLayout' => false, + 'debugLayoutLines' => false, + 'debugLayoutBlocks' => false, + 'debugLayoutInline' => false, + 'debugLayoutPaddingBox' => false, + ], ]; diff --git a/phpcs.xml b/phpcs.xml index 213b766..1294840 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -26,4 +26,5 @@ config src + test diff --git a/phpunit.xml b/phpunit.xml index 256873b..c0805c1 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -12,7 +12,7 @@ processIsolation="false" backupGlobals="false"> - ./src/Tests + ./test diff --git a/src/Factory/DompdfFactory.php b/src/Factory/DompdfFactory.php index 318aa19..5a92569 100644 --- a/src/Factory/DompdfFactory.php +++ b/src/Factory/DompdfFactory.php @@ -1,6 +1,6 @@ getConfig()); - } -} diff --git a/src/Tests/Factory/DompdfFactoryTest.php b/test/Factory/DompdfFactoryTest.php similarity index 53% rename from src/Tests/Factory/DompdfFactoryTest.php rename to test/Factory/DompdfFactoryTest.php index cc030b2..c10b9ea 100644 --- a/src/Tests/Factory/DompdfFactoryTest.php +++ b/test/Factory/DompdfFactoryTest.php @@ -1,10 +1,11 @@ factory); } - public function testInitWentThrough() + /** + * @covers DompdfHelper\Factory\DompdfFactory::__invoke + */ + public function testInitWentThrough(): void { - self::assertInstanceOf(DompdfFactory::class, $this->factory); + $this->assertInstanceOf(DompdfFactory::class, $this->factory); } } diff --git a/test/ModuleTest.php b/test/ModuleTest.php new file mode 100644 index 0000000..4f2b252 --- /dev/null +++ b/test/ModuleTest.php @@ -0,0 +1,19 @@ +assertIsArray($module->getConfig()); + } +} From 19f8a5444f89108403fc28d9aa652ba28b542c49 Mon Sep 17 00:00:00 2001 From: rarog Date: Sat, 6 Jun 2020 17:15:10 +0200 Subject: [PATCH 18/24] More testing. --- test/Factory/DompdfFactoryTest.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/test/Factory/DompdfFactoryTest.php b/test/Factory/DompdfFactoryTest.php index c10b9ea..d6be625 100644 --- a/test/Factory/DompdfFactoryTest.php +++ b/test/Factory/DompdfFactoryTest.php @@ -2,11 +2,16 @@ namespace DompdfModuleTest\Factory; +use Dompdf\Dompdf; use DompdfHelper\Factory\DompdfFactory; +use Laminas\ServiceManager\ServiceManager; use PHPUnit\Framework\TestCase; class DompdfFactoryTest extends TestCase { + /** + * @var DompdfFactory + */ private $factory; /** @@ -15,7 +20,7 @@ class DompdfFactoryTest extends TestCase */ protected function setUp(): void { - $this->factory = new dompdfFactory(); + $this->factory = new DompdfFactory(); } /** @@ -29,9 +34,23 @@ protected function tearDown(): void /** * @covers DompdfHelper\Factory\DompdfFactory::__invoke + * @covers DompdfHelper\Factory\DompdfFactory::createFromConfig + * @covers DompdfHelper\Factory\DompdfFactory::createDefaultSettings */ public function testInitWentThrough(): void { - $this->assertInstanceOf(DompdfFactory::class, $this->factory); + $factory = $this->factory; + + $config = [ + 'dompdf' => [ + 'defaultPaperSize' => 'A5', + ], + ]; + + $serviceManager = new ServiceManager(); + $serviceManager->setService('config', $config); + + $domPdf = $factory($serviceManager, null); + $this->assertInstanceOf(Dompdf::class, $domPdf); } } From f84a1cf325b5f3312f2297ff57898f0cbaf70836 Mon Sep 17 00:00:00 2001 From: rarog Date: Sat, 6 Jun 2020 17:17:14 +0200 Subject: [PATCH 19/24] Simplifying code. --- src/Factory/DompdfFactory.php | 6 ++---- test/Factory/DompdfFactoryTest.php | 8 +------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Factory/DompdfFactory.php b/src/Factory/DompdfFactory.php index 5a92569..100902e 100644 --- a/src/Factory/DompdfFactory.php +++ b/src/Factory/DompdfFactory.php @@ -26,10 +26,8 @@ protected function createFromConfig(array $config) { $userConfig = isset($config['dompdf']) ? $config['dompdf'] : []; - // merge default config with user config if necessary - $dompdfConfig = count($userConfig) ? - array_merge($this->createDefaultSettings(), $userConfig) : - $this->createDefaultSettings(); + // merge default config with user config + $dompdfConfig = array_merge($this->createDefaultSettings(), $userConfig); // set options $options = new Options(); diff --git a/test/Factory/DompdfFactoryTest.php b/test/Factory/DompdfFactoryTest.php index d6be625..912dcd6 100644 --- a/test/Factory/DompdfFactoryTest.php +++ b/test/Factory/DompdfFactoryTest.php @@ -41,14 +41,8 @@ public function testInitWentThrough(): void { $factory = $this->factory; - $config = [ - 'dompdf' => [ - 'defaultPaperSize' => 'A5', - ], - ]; - $serviceManager = new ServiceManager(); - $serviceManager->setService('config', $config); + $serviceManager->setService('config', []); $domPdf = $factory($serviceManager, null); $this->assertInstanceOf(Dompdf::class, $domPdf); From c3e8cfd20bc48a4ef7fc38ee3a91671bcba25bce Mon Sep 17 00:00:00 2001 From: rarog Date: Sat, 6 Jun 2020 17:26:17 +0200 Subject: [PATCH 20/24] Adding license file --- LICENSE | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f24f486 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2020, rarog +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file From 42cb8aa429f8eb79c31deb4669173f76670ba5c6 Mon Sep 17 00:00:00 2001 From: rarog Date: Sat, 6 Jun 2020 17:27:24 +0200 Subject: [PATCH 21/24] Adding license information to composer.json --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2f81250..625d3ab 100644 --- a/composer.json +++ b/composer.json @@ -32,5 +32,6 @@ "name" : "mikemix", "role" : "Original developer" } - ] + ], + "license" : "BSD 3-Clause License" } \ No newline at end of file From e26ec4246c146be59318a26b5823ee2ca6a86bf9 Mon Sep 17 00:00:00 2001 From: rarog Date: Mon, 5 Jul 2021 20:05:32 +0200 Subject: [PATCH 22/24] Updating dependencies. --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 625d3ab..9d68625 100644 --- a/composer.json +++ b/composer.json @@ -9,9 +9,9 @@ ], "require" : { "php" : "^7.1", - "dompdf/dompdf" : "^0.8.4", + "dompdf/dompdf" : "^1.0", "laminas/laminas-servicemanager" : "^3.0", - "laminas/laminas-modulemanager" : "^2.8" + "laminas/laminas-modulemanager" : "^2.10" }, "require-dev" : { "phpunit/phpunit" : "^7.0 || ^8.0 || ^9.0", @@ -34,4 +34,4 @@ } ], "license" : "BSD 3-Clause License" -} \ No newline at end of file +} From 8592a320f49a6d287d9e6a2212ab50f8f99d1b40 Mon Sep 17 00:00:00 2001 From: rarog Date: Tue, 6 Jul 2021 12:36:11 +0200 Subject: [PATCH 23/24] Fixing license in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9d68625..27cab14 100644 --- a/composer.json +++ b/composer.json @@ -33,5 +33,5 @@ "role" : "Original developer" } ], - "license" : "BSD 3-Clause License" + "license" : "BSD-3-Clause" } From 03c182c1974e3e401501322bb4e1b631d59836cc Mon Sep 17 00:00:00 2001 From: rarog Date: Tue, 25 Oct 2022 12:47:45 +0200 Subject: [PATCH 24/24] Adding support for PHP 8.0 and DomPdf 2 --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 27cab14..803ddad 100644 --- a/composer.json +++ b/composer.json @@ -8,14 +8,14 @@ "laminas" ], "require" : { - "php" : "^7.1", - "dompdf/dompdf" : "^1.0", - "laminas/laminas-servicemanager" : "^3.0", + "php" : "^8.0", + "dompdf/dompdf" : "^2.0", + "laminas/laminas-servicemanager" : "^3.6", "laminas/laminas-modulemanager" : "^2.10" }, "require-dev" : { - "phpunit/phpunit" : "^7.0 || ^8.0 || ^9.0", - "squizlabs/php_codesniffer" : "^3.0", + "phpunit/phpunit" : "^9.0", + "squizlabs/php_codesniffer" : "^3.6", "php-coveralls/php-coveralls" : "^2.0" }, "autoload" : {