本文介绍了使用Composer包括PHP Defines()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Composer进行模块依赖性管理(喜欢使用autoload.php而不是大量的include和require!).

I'm using Composer for module dependency management (loving using autoload.php instead of a ton of includes and requires!).

我想包括一个Composer根目录之外的PHP文件(出于安全性考虑),其凭据存储在defines()中.

I want to include a PHP file that is outside of the root Composer directory (for security) with credentials stored in defines().

这不起作用, composer.json :

{
  "autoload": {
    "classmap": ["../credentials.php"]
  }
}

credentials.php :

define('RYAN','BRODIE');

test.php :

require_once __DIR__.'/../vendor/autoload.php';
echo RYAN;

结果为Notice: Use of undefined constant RYAN.如果Composer的自动加载器仅适用于Class包含,那么我将不胜感激能够使这项工作成功的任何黑客手段.

Results in Notice: Use of undefined constant RYAN. If Composer's autoloader is only intended for Class includes then I'd be grateful for any hacks (as it were) to make this work.

推荐答案

该方法应该可以正常工作,但是例如,您需要使用files而不是classmap

That method should work fine, however you'll need to use files instead of classmap for example;

{
    "autoload": {
        "files": [ "../constants.php" ]
    }
}

这篇关于使用Composer包括PHP Defines()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 07:15