Search code examples
composer-phpphpspreadsheet

Installing Composer and Packagers - first time


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


Solution

  • 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.