Installing Composer and Packagers - first time - composer-php

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

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.

Related

Autoload doesn't locate previous packages

I am learning to use composer and I am constantly stopping at one problem. I've tried to find the solution, without success...
When I install new packages into my vendor folder, where I already have packages installed, the new autoload.php + composer folder doesn't locate my previous packages anymore. However, my composer.lock still display all the packages.
Did I do something wrong? I used
composer require package/name
to add my new packages.
Thank you in advance for your help!
Problem solved:
Autoload psr-4 wouldn't work.
After manually adding the code into autoload_psr4.php and autoload_classic.php everything works.
My issue also was that one of my packages didn't exist anymore (FormGuide/PHPFormValidator), which made that I couldn't simple re-install everything.

Is npm install affecting Laravel project?

I am working on the Laravel project, and intend to use Vue.js as its client-side scripting. When I searched the internet, I found that I had to use the npm install command. My question is if I run the order, will it affect the project I'm working on?
For example, in the directory structure or variable section?
It will change only package.json and /node_modules folder (it will download vue.js last version package into this folder) in your root directory. But it won't affect your existing codebase until you don't use them via importing or accessing it. It is like installing a package with composer, but not using it. The downloaded package will stay in /vendor folder and package name in composer.json, composer.lock

Get production versions of packages on "composer install"

Since composer was created, it made our life a lot easier. However, running composer install often ends up with so many files that can be useful for development, but just bloat the production server. Shared hosting often has limited inodes, or you must upload the "vendor" folder yourself since composer isn't on the server.
When the vendor folder has 6,000 files+ this is an issue, especially if you have multiple projects with 6,000 files each. And so many of these files are "README.MD" or "TODO". Production servers don't need the dev's "TODO" file.
I tried searching on Google but I can't find any clues, so anyone knows if there is a composer command that will install a production version?
There was a feature request for that, but it was rejected (several times). Right now the best what you can get from Composer is:
composer install --no-dev --prefer-dist
It will skip installation dev packages and prefer dist archives, which usually does not contain tests and other files not necessary to run package on production.
If this is still not enough, you may try to use octolab/cleaner plugin.
composer install --no-dev
The official link:
https://getcomposer.org/doc/03-cli.md#install
If you want to exclude something very specific, you want archive.
https://getcomposer.org/doc/04-schema.md#archive
"archive": {
"exclude": ["*.md", "vendor/**/tests", "/*.test"]
}

Refactoring Composer executable file for portability

Installing Composer locally puts a file named composer in your directory. I have taken to copying this file into each of my projects that uses Composer, so that I can run php composer in each folder.
Since this results in a lot of needlessly-repeated code, I want to refactor the composer file into something minimal. The most logical solution would be to refer to a class that resides in the vendor folder. Why is there so much code in the composer file anyway? I'd prefer not to put the code into my own libraries if I don't have to.
For comparison, here's a sample of code in a typical phpunit file:
require_once 'my_bootstrap.php';
spl_autoload_register(array(MyBootstrap::class,'autoload'));
// Do some other stuff here.
\PHPUnit_TextUI_Command::main();
I want to reduce the composer file in each project to something like this.
I do not want to install Composer globally. I want each project to be an environment unto itself and not have to instruct another developer to install anything other than PHP.

fuelphp No composer autoloader found

I got error message when install fuelphp
No composer autoloader found. Please run composer to install the FuelPHP framework dependencies first!
Also i my composer is updated.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
I am using PHP7 with a Vagrant environment.
Any idea about this error ?
It is not able to find installation of fuelphp. Most common issue is that index.php("public" or "public_html" folder) does not have the fuelphp's app, core and packages path set properly.
change DIR.'../ to DIR.'/../../(goes back one folder level)
There should be three of them.

Resources