8

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Ryan Brodie
  • 6,554
  • 8
  • 40
  • 57

1 Answers1

22

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

{
    "autoload": {
        "files": [ "../constants.php" ]
    }
}
tarnfeld
  • 25,992
  • 41
  • 111
  • 146