0

I have never used Composer, but I want to use PHPSpreadsheet package, and it is recommended that Composer is used.

I am on a MAC using XAMPP and Netbeans.

I have installed Composer, and I have run the following command to get and install the PHPSpreadsheet package.

php ../../Composer/composer.phar require phpoffice/phpspreadsheet

I am running this in my project folder, (hence the ../../ to where Composer.phar is located.

This downloads the files into a vendor folder in my project folder.

What should I do then? Do I need to keep it in the Vendor folder, or can I move into a folder of my choice?

Netbeans has Composer options in the menus, but as far as I can see, this is for creating dependencies rather than installing packages.

I know I am totally missing the point of Composer somewhere, but have spent hours just trying to get this work.

Many thanks

StripyTiger
  • 877
  • 1
  • 14
  • 31

1 Answers1

0

You should really start with the docs -> https://getcomposer.org/doc/01-basic-usage.md

You have to keep the vendor directory - this is where all dependencies are kept. If you require more packages - then they will be installed in that directory.

After requring the package you have to load it so the PHP will know all the classes. Composer comes with great autolader. It is located by default in vendor/autoload.php. So what you have to do now is to require this file in your project. After that all classes from composer packages will be loaded automaticaly each time you use them in the code :)

I hope this will help you with this great tool. Cheers.

Damian Dziaduch
  • 2,107
  • 1
  • 15
  • 16
  • Thank you very much. So if I add another packager using Composer, it will add this to the same autoload.php. Won't everything load whether you need it or not then? For example, on 1 php page I might want to use PHPSpreadsheet, on a different page I may want to use Google Sheets. Whichever page I am on, if I load vendor`autoload.php it will load both packages. – StripyTiger Nov 14 '18 at 17:09
  • 1
    @pbs it loads classes on demand. If you require `vendor/autoload.php` in your code but you do not use any class from composer packages, it will not load any class. So in your case on page 1 it will load `PHPSpreadsheet` but on the second one it will not. It uses PHP feature called autoloader -> http://php.net/manual/en/function.spl-autoload-register.php – Damian Dziaduch Nov 14 '18 at 20:13