Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/vendor
phpunit.xml
build/
vendor/
composer.lock

22 changes: 11 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
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
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source

script:
- phpunit
- ./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

29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
80 changes: 63 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
dompdfmodule
DompdfHelper
============

DOMPDF library wrapper as lightweight ZF2/ZF3 module.
DompdfHelper - a lightweight library wrapper 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/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
- [Zend Framework 2 or 3](https://framework.zend.com/)
- [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
Expand All @@ -20,40 +21,85 @@ PHP Composer, please visit the official [PHP Composer site](http://getcomposer.o
```json
{
"require": {
"mikemix/dompdfmodule": "^3.0"
"rarog/dompdf-helper": "^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',
'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

> 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
<?php

// some controller
namespace My\Factory\Controller;

use Interop\Container\ContainerInterface;
use My\Controller\ExampleController;

class ExampleControllerFactory implements FactoryInterface
{
/**
* {@inheritDoc}
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return new ExampleController(
$container->get('dompdf')
);
}
}
```

Controller

```php
<?php

namespace My\Controller;

use Dompdf\Dompdf;
use Laminas\Mvc\Controller\AbstractActionController;

class ExampleController extends AbstractActionController
{
/**
* @var Dompdf
*/
private $dompdf;

/**
* Constructor
*
* @param Dompdf $dompdf
*/
public function __construct(
Dompdf $dompdf
) {
$this->dompdf = $dompdf;
}

public function indexAction()
{
/** @var \Dompdf\Dompdf $dompdf */
$dompdf = $this->getServiceLocator()->get('dompdf');
$dompdf->load_html('<strong>Ehlo World</strong>');
$dompdf->render();
$this->dompdf->load_html('<strong>Hello World</strong>');
$this->dompdf->render();

file_put_contents(__DIR__ . '/document.pdf', $dompdf->output());
file_put_contents(__DIR__ . '/document.pdf', $this->dompdf->output());
}
}
```
53 changes: 35 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
{
"name": "mikemix/dompdfmodule",
"type": "library",
"description": "DOMPDF Zend Framework lightweight module",
"keywords": ["pdf","dompdf", "zf2", "zf3"],
"homepage": "https://www.phpcontext.com",
"require": {
"php": "^5.5 || ^7.0",
"dompdf/dompdf": "^0.7.0",
"zendframework/zend-servicemanager": "^2.0 || ^3.0"
},
"autoload": {
"psr-4": {
"dompdfmodule\\": "src/"
}
},
"suggest": {
"mikemix/mxdi-module": "Configure dependency injection with annotations"
}
"name" : "rarog/dompdf-helper",
"type" : "library",
"description" : "DompdfHelper - a lightweight library wrapper Laminas module",
"keywords" : [
"pdf",
"dompdf",
"laminas"
],
"require" : {
"php" : "^8.0",
"dompdf/dompdf" : "^2.0",
"laminas/laminas-servicemanager" : "^3.6",
"laminas/laminas-modulemanager" : "^2.10"
},
"require-dev" : {
"phpunit/phpunit" : "^9.0",
"squizlabs/php_codesniffer" : "^3.6",
"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"
}
],
"license" : "BSD-3-Clause"
}
44 changes: 22 additions & 22 deletions config/dompdf.config.php.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<?php

$dompdfDir = realpath('vendor/dompdf/dompdf');

return [
'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,
'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,
],
];
30 changes: 30 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Laminas Coding Standard">
<description>Laminas Coding Standard</description>

<!-- display progress -->
<arg value="p"/>
<arg name="colors"/>
<arg name="extensions" value="php,dist"/>

<!-- inherit rules from: -->
<rule ref="PSR12"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.Formatting.SpaceAfterNot"/>
<rule ref="Squiz.WhiteSpace.OperatorSpacing">
<properties>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="false"/>
</properties>
</rule>
<rule ref="PSR1.Files.SideEffects"/>

<!-- Paths to check -->
<file>config</file>
<file>src</file>
<file>test</file>
</ruleset>
27 changes: 27 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
stopOnFailure="false"
processIsolation="false"
backupGlobals="false">
<testsuite name="dompdfmoduleTests">
<directory>./test</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-text" target="php://stdout"/>
<log type="coverage-html" target="build/logs/coverage" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
22 changes: 0 additions & 22 deletions phpunit.xml.dist

This file was deleted.

Loading