Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including PHP Defines() using Composer

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.

like image 384
Ryan Brodie Avatar asked Jul 01 '13 12:07

Ryan Brodie


1 Answers

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

{
    "autoload": {
        "files": [ "../constants.php" ]
    }
}
like image 110
tarnfeld Avatar answered Oct 08 '22 00:10

tarnfeld