php – How to automatically include a file, which is not a class, in composer?

Question:

In composer, usually when we're going to configure the autoload for files that contain classes, I usually do it like this:

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

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

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

How do I make composer include a file automatically?

Answer:

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 autoload policy will be loaded automatically.

Reference

Scroll to Top
AllEscort