Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How To: Get DOMPDFModule working with ZF3 #56

Open
dkern opened this issue Jun 29, 2017 · 3 comments
Open

How To: Get DOMPDFModule working with ZF3 #56

dkern opened this issue Jun 29, 2017 · 3 comments

Comments

@dkern
Copy link

dkern commented Jun 29, 2017

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 ...


  1. Delete modules/DOMPDFModule/Module.php

  2. Move files from modules/DOMPDFModule/src/DOMPDFModule/
    to modules/DOMPDFModule/src/ (one directory up)

  3. Change the path in getConfig() function
    in modules/DOMPDFModule/src/Module.php
    to __DIR__ . '/../config/module.config.php

  4. Remove getAutoloaderConfig function
    from modules/DOMPDFModule/src/Module.php

  5. 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
  1. 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
  1. 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
  1. Instead of $serviceLocator->get
    use $container->get(ServiceManager::class)->get
    in factories

  2. 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

  3. Change require_once __DIR__ . '/../../../config/module.compat.php';
    to require_once __DIR__ . '/../../config/module.compat.php';
    in modules/DOMPDFModule/src/Service/DOMPDFFactory.php

  4. Change $viewManager->getResolver()
    to $serviceLocator->get("ViewResolver")
    in modules/DOMPDFModule/src/Mvc/Service/ViewPdfRendererFactory.php

  5. Change $viewManager->getRenderer()
    to $serviceLocator->get("ViewRenderer")
    in modules/DOMPDFModule/src/Mvc/Service/ViewPdfRendererFactory.php

  6. Add autoloader configuration to composer.json:

"autoload": {
  "psr-4": {
    "DOMPDFModule\\": "module/DOMPDFModule/src/"
  }
}
  1. Run composer command dump-autoload to rebuild autoloading:
$ composer dump-autoload

This tutorial assumes that dompdf is installed in version 0.6.2 by composer in vendor directory.

@andytechcastro
Copy link

Still not working!!! Well not for me

@juizmill
Copy link

juizmill commented Aug 3, 2017

I made a migration version for ZF3 if you can view and test #57

@raykolbe
Copy link
Owner

In addition to @juizmill's work in #57, I took an initial stab at a ZF3 upgrade path in #73. Take note that the minimum Dompdf version supported here is ^0.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants