Reputation: 581
I have a file with some functions (polyfills for some extensions) without namespace that should be loaded and accessible globally.
Question is where to put this file (now it in "/src/AppBundle" dir) and how to load it in Symfony? Maybe some best practice or something.
File exmaple:
<?php
// functions.php
define('CONSTANT_NAME', 'constant_value');
function doSomething()
{
}
Updated: also some functions should be loaded (in a separated file) only in "dev" environment. Maybe add "include_once" in app_dev.php?
Upvotes: 1
Views: 2010
Reputation: 36944
I'd put it in /src
folder, maybe /src/functions.php
- you can decide according to your preferences.
To load it, you can change your composer.json
and add files
to your autoload
configuration, then run composer update
.
"autoload": {
"files": ["src/functions.php"]
}
So that functions.php
is required to every request.
Upvotes: 3