Including PHP Defines() using Composer

谁说胖子不能爱 提交于 2019-11-30 04:03:35

问题


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

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

This isn't working, composer.json:

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

credentials.php:

define('RYAN','BRODIE');

test.php:

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

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.


回答1:


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

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


来源:https://stackoverflow.com/questions/17404351/including-php-defines-using-composer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!