Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use composer to require only 1 file?

Is it possible to require only 1 file from a composer package?

I need only 1 or few files from a package and it would be pointless to require the whole package which consist of hundred of files when i would use only a few.

Is it possible to do this via composer?

like image 446
user2707590 Avatar asked Feb 12 '16 11:02

user2707590


1 Answers

It's possible to include specific files in the current package with the files autoloading strategy:

{
    "autoload": {
        "files": [
            "path/to/my/file.php"
        ]
    }
}

If you need to require specific files from a package you installed with composer, this is not possible. Not really needed either, as the files are not loaded into memory unless you use them in your code.

More about files and other autoloading stragegies can be found in the composer docs.

like image 106
Jakub Zalas Avatar answered Nov 01 '22 03:11

Jakub Zalas