ZF2 and DOMPDF autoloading issue

1.3k Views Asked by At

I am using Zend Loader from here in my project and I am unable to configure Zend autoloader for the DOMPDF, working parallel to dompdf autoloader. Is there any way to set zend autoload to configure such that it fallback to dompdf auotloader.

I see some example e.g using pushAutoLoader, but that seems its using Zend older version (v < 2 probably )

    require_once('dompdf/dompdf_config.inc.php' );
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->pushAutoloader('DOMPDF_autoload', '');

What is the alternative to pushAutoloader() , in ZF2 Loader ? I do not see any such method right now.

One more thing I cannot use 'fallback_autoloader' => true, option as I am using php 5.3.1 which gives me error :

  `Call to undefined function Zend\Loader\stream_resolve_include_path()`

As it seems stream_resolve_include_path() is added in php 5.3.2

1

There are 1 best solutions below

1
On

This seems to be a minor glitch , just found that the DOMPDF config file is using an obsolete way to register its autoloader e.g

if ( !function_exists("__autoload") ) {
  /**
   * Default __autoload() function
   *
   * @param string $class
   */
  function __autoload($class) {
    DOMPDF_autoload($class);
  }
}

and a fix would be just use the spl_autoload_register bcz php spl_autoload_register vs __autoload? and replace the above code with just one line, with minor update to autoload function

function DOMPDF_autoload($class) { 
  //don't check for namespaced files/classes   
  if(strpos($class, "\\") > 0) return;

  if($class=='UFPDF') return ;

  $filename = mb_strtolower($class) . ".cls.php";

  require(DOMPDF_INC_DIR . "/$filename");
}

spl_autoload_register('DOMPDF_autoload');

cheers :)