I've made the module working on ZF3. But actually only with dompdf version 0.6.2. You should totally upgrade to newer version of it!
But so far, just to give you an hint what to do to make this module working on ZF3, I made an change list while updateing it. It works pretty well then. Maybe helpful for others too, so I will let this here.
It really easy to do, just follow this easy steps ...
-
Delete modules/DOMPDFModule/Module.php
-
Move files from modules/DOMPDFModule/src/DOMPDFModule/
to modules/DOMPDFModule/src/ (one directory up)
-
Change the path in getConfig() function
in modules/DOMPDFModule/src/Module.php
to __DIR__ . '/../config/module.config.php
-
Remove getAutoloaderConfig function
from modules/DOMPDFModule/src/Module.php
-
Change from use Zend\ServiceManager\FactoryInterface;
to use Zend\ServiceManager\Factory\FactoryInterface; in:
modules/DOMPDFModule/src/MVC/Service/ViewPdfRendererFactory.php
modules/DOMPDFModule/src/MVC/Service/ViewPdfStrategyFactory.php
modules/DOMPDFModule/src/Service/DOMPDFFactory.php
- Change function
public function createService(ServiceLocatorInterface $serviceLocator)
to public function __invoke(ContainerInterface $container, $requestedName, array $options = null) in:
modules/DOMPDFModule/src/MVC/Service/ViewPdfRendererFactory.php
modules/DOMPDFModule/src/MVC/Service/ViewPdfStrategyFactory.php
modules/DOMPDFModule/src/Service/DOMPDFFactory.php
- Add new imports:
use Interop\Container\ContainerInterface;
use Interop\Container\Exception\ContainerException;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\ServiceManager;
to the following file headers:
modules/DOMPDFModule/src/MVC/Service/ViewPdfRendererFactory.php
modules/DOMPDFModule/src/MVC/Service/ViewPdfStrategyFactory.php
modules/DOMPDFModule/src/Service/DOMPDFFactory.php
-
Instead of $serviceLocator->get
use $container->get(ServiceManager::class)->get
in factories
-
Change defined('DOMPDF_DIR') || define("DOMPDF_DIR", __DIR__ . '/../../../../../dompdf/dompdf');
to defined('DOMPDF_DIR') || define("DOMPDF_DIR", __DIR__ . '/../../../../vendor/dompdf/dompdf');
in modules/DOMPDFModule/src/Service/DOMPDFFactory.php
-
Change require_once __DIR__ . '/../../../config/module.compat.php';
to require_once __DIR__ . '/../../config/module.compat.php';
in modules/DOMPDFModule/src/Service/DOMPDFFactory.php
-
Change $viewManager->getResolver()
to $serviceLocator->get("ViewResolver")
in modules/DOMPDFModule/src/Mvc/Service/ViewPdfRendererFactory.php
-
Change $viewManager->getRenderer()
to $serviceLocator->get("ViewRenderer")
in modules/DOMPDFModule/src/Mvc/Service/ViewPdfRendererFactory.php
-
Add autoloader configuration to composer.json:
"autoload": {
"psr-4": {
"DOMPDFModule\\": "module/DOMPDFModule/src/"
}
}
- Run
composer command dump-autoload to rebuild autoloading:
This tutorial assumes that dompdf is installed in version 0.6.2 by composer in vendor directory.
I've made the module working on ZF3. But actually only with
dompdfversion0.6.2. You should totally upgrade to newer version of it!But so far, just to give you an hint what to do to make this module working on ZF3, I made an change list while updateing it. It works pretty well then. Maybe helpful for others too, so I will let this here.
It really easy to do, just follow this easy steps ...
Delete
modules/DOMPDFModule/Module.phpMove files from
modules/DOMPDFModule/src/DOMPDFModule/to
modules/DOMPDFModule/src/(one directory up)Change the path in
getConfig()functionin
modules/DOMPDFModule/src/Module.phpto
__DIR__ . '/../config/module.config.phpRemove
getAutoloaderConfigfunctionfrom
modules/DOMPDFModule/src/Module.phpChange from
use Zend\ServiceManager\FactoryInterface;to
use Zend\ServiceManager\Factory\FactoryInterface;in:modules/DOMPDFModule/src/MVC/Service/ViewPdfRendererFactory.phpmodules/DOMPDFModule/src/MVC/Service/ViewPdfStrategyFactory.phpmodules/DOMPDFModule/src/Service/DOMPDFFactory.phppublic function createService(ServiceLocatorInterface $serviceLocator)to
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)in:modules/DOMPDFModule/src/MVC/Service/ViewPdfRendererFactory.phpmodules/DOMPDFModule/src/MVC/Service/ViewPdfStrategyFactory.phpmodules/DOMPDFModule/src/Service/DOMPDFFactory.phpuse Interop\Container\ContainerInterface;use Interop\Container\Exception\ContainerException;use Zend\ServiceManager\Exception\ServiceNotCreatedException;use Zend\ServiceManager\Exception\ServiceNotFoundException;use Zend\ServiceManager\ServiceManager;to the following file headers:
modules/DOMPDFModule/src/MVC/Service/ViewPdfRendererFactory.phpmodules/DOMPDFModule/src/MVC/Service/ViewPdfStrategyFactory.phpmodules/DOMPDFModule/src/Service/DOMPDFFactory.phpInstead of
$serviceLocator->getuse
$container->get(ServiceManager::class)->getin factories
Change
defined('DOMPDF_DIR') || define("DOMPDF_DIR", __DIR__ . '/../../../../../dompdf/dompdf');to
defined('DOMPDF_DIR') || define("DOMPDF_DIR", __DIR__ . '/../../../../vendor/dompdf/dompdf');in
modules/DOMPDFModule/src/Service/DOMPDFFactory.phpChange
require_once __DIR__ . '/../../../config/module.compat.php';to
require_once __DIR__ . '/../../config/module.compat.php';in
modules/DOMPDFModule/src/Service/DOMPDFFactory.phpChange
$viewManager->getResolver()to
$serviceLocator->get("ViewResolver")in
modules/DOMPDFModule/src/Mvc/Service/ViewPdfRendererFactory.phpChange
$viewManager->getRenderer()to
$serviceLocator->get("ViewRenderer")in
modules/DOMPDFModule/src/Mvc/Service/ViewPdfRendererFactory.phpAdd autoloader configuration to
composer.json:composercommanddump-autoloadto rebuild autoloading:This tutorial assumes that
dompdfis installed in version0.6.2bycomposerinvendordirectory.