dongshi949737
2017-04-21 11:09
浏览 52
已采纳

在Zend 1.12中使用Composer自动加载器(用于加载外部库)?

Basically, I'd want to use Composer auto-loader (for loading third-party libraries), but I want to continue using built-in mechanism for auto-loading in Zend 1.12

I added the following piece of code:

<?php // File path: index.php 

// ...

$composerAutoloaderPaths = array(
    '../vendor/autoload.php',
    '../../common/vendor/autoload.php' // store common libraries used by multiple projects, currently that's working by adding the directory in set_include_path()
);

foreach($composerAutoloaderPaths as $composerAutoloaderPath)
{
    if(file_exists($composerAutoloaderPath))
    {
        require_once $composerAutoloaderPath;
    }
    else 
    {
        // handle the error gracefully
    }
}

// ...

Also, I'm using Zend_Loader_Autoloader like this:

<?php // File path: Bootstrap.php 

// ...

$autoloader = Zend_Loader_Autoloader::getInstance();

$autoloader->registerNamespace('Plugin_');
$autoloader->registerNamespace('Helper_');
// etc.

// ...

Is there something to worry about using Composer and Zend autoloaders like this?

图片转代码服务由CSDN问答提供 功能建议

基本上,我想使用Composer自动加载器(用于加载第三方库),但我想要 继续在Zend 1.12中使用内置机制进行自动加载

我添加了以下代码:

 &lt;?  php //文件路径:index.php 
 
 // ... 
 
 $ composerAutoloaderPaths = array(
'../vendor/autoload.php',
'../../common  /vendor/autoload.php'//存储多个项目使用的公共库,目前通过在set_include_path()
)中添加目录来工作; 
 
foreach($ composerAutoloaderPaths as $ composerAutoloaderPath)
 {
 if(  file_exists($ composerAutoloaderPath))
 {
 require_once $ composerAutoloaderPath; 
} 
 else 
 {
 //正常处理错误
} 
} 
 
 // ... 
 <  / code>  
 
 

另外,我正在使用 Zend_Loader_Autoloader ,如下所示:

 &lt;?php /  /文件路径:Bootstrap.php 
 
 // ... 
 
 $ autoloader = Zend_Loader_Autoloader:  :getInstance(); 
 
 $ autoloader-&gt; registerNamespace('Plugin _'); 
 $ autoloader-&gt; registerNamespace('Helper _'); 
 //等等
 
 // ...  
   
 
 

使用像这样的Composer和Zend自动加载器有什么值得担心的吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题