php - How to use composer just to load the minimum files needed to resolve dependency

I am totaly new to composer !

Example; When using composer like composer require smarty/smarty I get all kinds of directorys installed like

  • vendor\smarty\smarty\lexer

But I only need smarty\libs and this smarty/libs should show up in an existing project direcory at webroot/project/smarty/libs.

In essence , can i specify this so composer just gets me what I need and puts it where I need it?

Answer

Solution:

In essence , can i specify this so composer just gets me what I need and puts it where I need it?

Yes, but it requires additional configuration. What you already have (and what Composer is for):

  1. You identified a Composer package containing a directory of files you have interest in.
  2. You already processed that package with the Composer utility within your project and you have updated your project configuration accordingly.

Now in the default setup, Composer installs in the vendor directory. This directory is not part of your project commonly, therefore the name "vendor", and often excluded.

Now you want to import a directory of files into your project from the (in your project already configured) vendor folder.

This is basically a file-copying operation, consult your systems programming manual for the commands to recursively copy a directory of files (or consult the PHP manual for this).

Then adopt your project install instructions to (re-)create the target directory and copy over the files after the command to (re-)create the vendor folder (perhaps you're using composer install for that).

If you want to do this with Composer - which is possible - add a post-install event script to your project configuration (pre-autoload-dump can also be useful if you not only want to incorporate files but also you want to use the Composer autoloader for directories in your project, like the newly created folder by copying over vendor files).

Execute your setup instructions.

You then add your changes, review them and commit them to the project history.


Alternatively, you can also not ignore the whole vendor folder, just the part you are not interested in and then create a reference so that the project targets directory is in fact a relative symbolic link to the descendant directory of interest in vendor. This requires your system as well as your software configuration management software to support symbolic links (for example Git does). Composer itself can deal with both ways fine.


And here the take-away: You need the Smarty Composer dependency only at development time, therefore you add it to require-dev - not require.

If that does not give you enough isolation, you create another Composer project configuration and pass its name with the . You specify as well a non-standard Composer vendor directory name with that configuration and then do the operations there (this is perhaps the best to try it out in an existing project).

Source