简体   繁体   English

ZF2和DOMPDF自动加载问题

[英]ZF2 and DOMPDF autoloading issue

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. 我从这里在我的项目中使用Zend Loader,但无法为DOMPDF配置Zend自动加载器,与dompdf自动加载器并行工作。 Is there any way to set zend autoload to configure such that it fallback to dompdf auotloader. 有什么方法可以设置zend autoload进行配置,以使其回退到dompdf auotloader。

I see some example eg using pushAutoLoader, but that seems its using Zend older version (v < 2 probably ) 我看到了一些示例,例如使用pushAutoLoader,但这似乎是使用Zend的旧版本(v <2可能)

    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 ? ZF2 Loader中pushAutoloader()的替代方法是什么? 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 : 我不能再使用'fallback_autoloader' => true,是我正在使用php 5.3.1的选项,这给了我错误:

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

As it seems stream_resolve_include_path() is added in php 5.3.2 似乎在PHP 5.3.2中添加了stream_resolve_include_path()

This seems to be a minor glitch , just found that the DOMPDF config file is using an obsolete way to register its autoloader eg 这似乎是一个小故障,只是发现DOMPDF配置文件正在使用一种过时的方式来注册其自动加载器,例如

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? 和修复将只是使用spl_autoload_register bcz php spl_autoload_register与__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 :) 欢呼:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM