سؤال

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