2

I've installed and deployed magento-hackathon/magento-composer-installer in my Magento 1.9 and I am trying to add and use mpdf/mpdf (composer packagist) in a controller.

This package contains a classmapped file

"autoload": {
    "classmap": [
      "filters/",
      "fpdi.php",
      "fpdf_tpl.php",
      "fpdi_pdf_parser.php",
      "pdf_context.php"
    ]
  },

Which is called in another component.

$this->parsers[$fn] = new fpdi_pdf_parser($fn);

And then Magento gives me the error

Warning: include(Fpdi/Pdf/Parser.php): failed to open stream: No such file or directory in /../mymagento/lib/Varien/Autoload.php on line 94

The Mage.php seems to be patched properly, and I also tried to do composer dumpautoload.

Some facts and findings:

  • If I create a /newfile.php (on the root folder, with not triggering Magento), include autoload.php, and call the method, it works.
  • If I disable developer mode it works (and the warning is logged).
  • If I change the Varien/Autoload.php and add an if(stream_resolve_include_path($classFile)) (as suggested here) before returning the include, it works (but I would override a core file).
  • It seems that when composer autoload resolves fpdi_pdf_parser it makes a require_once to 'pdf_parser.php' and at this stage Mage autoload is triggered instead of Composer's autoload.

Am I missing something? Any help is appreciated.

  • In which folder that FPDI install? – kunj Aug 22 '18 at 8:44
  • its under vendor/setasign/fpdi/fpdi_pdf_parser.php and the file that calls it, is vendor/mpdf/mpdf/src/Mpdf.php – Ricardo Martins Aug 22 '18 at 10:55
  • you want to use that as web, not for cron, right? – kunj Aug 24 '18 at 11:11
  • Yes, for web and maybe cron – Ricardo Martins Aug 25 '18 at 7:13
3
+50

Are you certain that the vendor directory is being autoloaded? That's what that error sounds like - I had a similar issue and used this module (instead of modifying the Mage.php file, which could cause conflicts in future patches):

https://github.com/romantomchak/magento-composer-autoload

  • I tried to make changes in the Autoloader as well, but it was still breaking. Your changes works fine. The only change I would suggest in your autoload is at line 195... Magento uses include_once, instead of include. ;) Thanks for helping. – Ricardo Martins Aug 30 '18 at 7:26
  • In fact I was precipitated, hehe. The problem continues even with your autoloader. I can't instantiate a new \Mpdf\Mpdf, which raises the same error (Warning: include(Fpdi/Pdf/Parser.php): failed to open stream: No such file or directory in /Users/martins/www/magenteiro/app/code/local/Varien/Autoload.php on line 181). I tried to create a model that extends this, but unloads Magento autoload (spl_autoload_unregister([Varien_Autoload::instance(), 'autoload']);). The problem is that anything that requires something from magento, after my Model is instantiated doesnt work. – Ricardo Martins Aug 30 '18 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.