I know this is sloppy and unconventional, but I need to test some changes to a package by manually adjusting a composer.json file within a package in the vendor folder. But I can't figure out how to get the new dependencies and "autoloader->file" changes to take hold. I've tried composer install, composer dumpautoload -o, and installing directly from that folder (which merely created a new and useless "vendor" folder within the package directory).
Is this even possible, or just too sloppy for Composer to offer a way to go about it?
Related
I am using https://github.com/tonix-tuft/grunt-hub-automator (a repo I have created on GitHub) which lets me set up a daemon which runs the following command whenever I change my composer.json or composer.lock file:
composer self-update && composer install --no-dev && composer update --lock
This way I can move across different branches and the daemon keeps the dependencies in vendor synchronized with composer.json.
However, if after adding new dependencies on new_branch I checkout old_branch which doesn't have those dependencies defined in composer.json because I have added them only on new_branch, the daemon fires the command and removes the dependencies on the old branch to keep everything in sync.
The problem of this approach is that if at that point I checkout again new_branch before the composer command has finished its work on old_branch (it's running in the background thanks to the daemon), I end up with an unsynced vendor folder because Composer is removing the dependencies as it thinks I am still on old_branch.
Is there a way to tell Composer not to remove already installed dependencies from vendor when they are not defined in composer.json?
Basically, I would like Composer to install missing dependencies or update those which are defined in composer.json every time composer.json changes without removing eventual dependencies which were already installed in vendor but now are not defined in composer.json anymore.
Is it possible?
I hope I was clear.
Thank you for your attention.
When I try to composer require something/something in my vendor folder
it starts installing a lot of stuff I didn't ask for.
Like I just did composer require ramsey/uuid, and Composer created a subfolder called vendor then started downloading a lot of libraries e.g Laravel, Symfony, and Twig (these are just the ones I know).
This first happened when I tried to require Twig. I just deleted the irrelevant libraries and kept Twig.
Does anyone have an idea to whats causing this?
If composer is downloading and installing stuff you didn't ask for, then that stuff probably was asked for by one of the following:
some require statement defined in the composer.json file
a dependency required by something you are installing. I'm not familiar with twig, but it might require laravel, symfony et. al. If you plan to use one of these frameworks, I suggest you install that first before requiring twig.
some cached thing somewhere, like the composer.lock file mentioned above
Composer creates the folder called vendor as the home for all of the libraries/packages that it fetches and installs.
You can always check, why Composer installed something, by runnung
$ composer why webmozart/assert
The command will show you, which of the root requirements depends on the package (webmozart/assert in this case).
The best way is to delete everything and start from scratch, given that you haven't really done much yet (as you say, your composer.json file is empty):
$ rm -rf vendor/
$ rm composer.json
$ rm composer.lock
Then, start composer and install the dependency again:
$ composer init
$ composer require ramsey/uuid
You should now have it all working.
My assumption is that you were running composer install based on an older composer.lock file, which will re-download the dependencies.
I was working with a laravel project and, accidentally, removed vendor folder.
What should I do? Create a new project and copy it or download it anywhere else?
I had no additional composer dependencies installed.
Just run composer install after cding into the Laravel project's directory.
The Vendor folder is created by running composer install. It contains only the packages which you have asked composer to track in the composer.json file. If you have a composer.phar file in the root of your application run php composer.phar install.
https://getcomposer.org/doc/00-intro.md is probably your best source for additional information.
This is how I use composer and svn together:
In my development version, I run composer to download required packages to the vendor directory. I then commit the vendor directory to svn together with the rest of the development folder. The production build makes a copy of the vendor folder.
I know, it is recommended not to commit the vendor directory in svn (see SVN Repo in vendor with Composer), but I want to be safe for the case when a composer update may break my application. It allows me to rollback everything in that case to the last stable state.
The problem with how composer works is that the checked out svn repo breaks, if composer deletes whole directories.
I would switch to the recommended practice and only check in composer.lock and composer.json into svn, if I knew how to rollback an eventual breaking composer update. Can somebody explain this to me, please.
When you have composer.lock and run composer install (not update) you are sure that you'll get dependencies which are "locked" by you.
Running composer update ignores entries in composer.lock and tries to download latest dependencies allowed by composer.json.
I already know how to install by going through composer.json to add laravel/cashier, then composer update, and then add some line in app provider. But where does this folder go? What other things does it add in my app to make it fully functional? What is the work flow of composer update in Laravel 4?
Composer is a dependency management tool for PHP. It is not a typical package manager as it does not install libraries globally, but on a per project basis. It uses the file "composer.json" to install, update and remove libraries specified, including the version requested.
Composer creates an "autoload.php" file that, if included in your project, autoloads all libraries and classes and makes them available for use.
Typically, in a regular PHP project, you'd include the following line to bootstrap your project:
require 'vendor/autoload.php';
Now, when you execute composer install (for first time) or composer update (every time after), Composer adds/removes packages according to configuration made in "composer.json" file. All packages go in the directory "vendor" found in root of your project directory.
Laravel, by default, is a Composer project. You know when you execute composer create-project laravel/laravel my-app --prefer-dist to install Laravel, you are telling Composer to build a "composer.json" file with Laravel project and its dependencies, and run composer install. That's all!
Last but not least, Laravel, since it is a Composer project, includes "autoload.php" file and autoloads all packages within that project by default. You will notice "vendor" directory in the root directory. In Laravel 5 project, if you navigate to "bootstrap/autoload.php" file, you will see Laravel includes "autoload.php" file: require __DIR__.'/../vendor/autoload.php';
To answer your question about manually installing Laravel Cashier, Laravel Cashier is a package made specifically for Laravel, and as such, is not meant to be used on regular PHP project, unless you use specific classes and do some tweaking. To manually install Laravel Cashier, if you go to the following link, you will find link to "laravel/cashier" GitHub repository, from where you can manually download Zip file or clone the repository using git:
https://packagist.org/packages/laravel/cashier
I hope this adequately answers your questions - I kept it as simple as I could. Let me know if you have any other questions.