How to automatically include a file, which is not a class, in Composer?

Asked

Viewed 83 times

3

In Composer, usually when we configure autoload for files that contain classes, I usually do so:

"autoload" : { 
   "psr-4" : { "WallaceMaxters\\Timer\\" : 'src/timer'}
}

Composer will automatically load the file that has the same class name once it is instantiated.

But now I have a file called functions.php that has some functions that I want to include in this same library.

How do I automatically include a file?

1 answer

1


You can also include arquivos in Composer:

{
    "autoload": {
        "files": ["src/minhaBiblioteca/functions.php"]
    }
}

This way, Composer will ensure that files defined as files under the directive of autoload will be automatically loaded.

Reference

  • Do you need to update Composer or just add the file path? I created a class but you can’t find the class.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.