문제

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.

도움이 되었습니까?

해결책

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

{
    "autoload": {
        "files": [ "../constants.php" ]
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top