How to get composer to update version numbers to the latest ones available in composer.json? - composer-php

In my composer.json config file, I have:
"require": {
"zendframework/zend-log" : "~2.3",
},
"require-dev": {
"phpunit/phpunit": "^5.4"
}
I want:
"require": {
"zendframework/zend-log" : "^2.9",
},
"require-dev": {
"phpunit/phpunit": "^6.2"
}
Note the version number changes
How? I want it to be done automatically without me having to look up each individual latest version that's available and edit it manually.
There is this question but it does not help: How to resolve package not found error when trying to make the composer get the latest package versions?

Run
composer require zendframework/zend-log
and
composer require --dev phpunit/phpunit

Since Composer 2.4, there's a bump command that does exactly that.
Quoted from the release announcement (Jordi Boggiano for Packagist; Aug 2022):
The new bump command lets you increase your requirements to match the versions currently installed. For example, if you require package "foo/bar": "^1" – but you currently have foo/bar 1.5.3 installed – running composer bump foo/bar will update your composer.json requirement to "foo/bar": "^1.5.3".
c.f. "Bumping your version constraints more easily"

For all packages in composer.json, you can do it with the following command (--no-dev):
composer show --no-dev --direct --name-only \
| xargs composer require
And for all developer dependencies:
grep -F -v -f \
<(composer show --direct --no-dev --name-only | sort) \
<(composer show --direct --name-only | sort) \
| xargs composer require --dev
The combination of both commands is similar to what npm-check-updates (ncu) would do for NPM.

Related

Argument 1 passed to League\\Flysystem\\AwsS3v3\\AwsS3Adapter::__construct() must be an instance of Aws\\S3Client, instance of Aws\\S3\\S3Client given [duplicate]

I have installed the s3 flysystem package by running the following composer command in my Laravel 8 project
composer require --with-all-dependencies league/flysystem-aws-s3-v3 "^1.0"
and tried to store a file from the request as
$imageName = $request->file('file')->store('uploads');
I got the following error
League\Flysystem\AwsS3v3\AwsS3Adapter::__construct(): Argument #1
($client) must be of type Aws\S3Client, Aws\S3\S3Client given, called
in
D:\Projects\Rescale\vendor\laravel\framework\src\Illuminate\Filesystem\FilesystemManager.php
on line 229
So it seems ThePHPLeague Flysystem major version got updated (to v2) thus breaking a lot of stuff since latest Laravel depends on "^1.1" (see: https://github.com/laravel/framework/blob/8.x/composer.json#L27).
I've had this error, so my workaround is to use a specific version instead.
Go to composer.json and use latest v1 (see: https://github.com/thephpleague/flysystem-aws-s3-v3/tags).
- "league/flysystem-aws-s3-v3": "^1.0",
+ "league/flysystem-aws-s3-v3": "1.0.29",
Run composer update and let composer update your dependencies.
try this to upload an image on AWS
$path = Storage::disk('s3')->put('uploads', $request->file('file'));
try this
composer require --with-all-dependencies league/flysystem-aws-s3-v3 "~1.0"
I got same error in Laravel version 8
open composer.json and change inside version to "league/flysystem-aws-s3-v3": "^1.0"
run composer update

How to composer install using a package's composer.lock file?

If I have:
a fresh project
no composer.lock
composer.json like the following
{
"name": "fresh",
"type": "library",
"require": {
"consolidation/robo": "3.0.3"
}
}
Then run composer install
It will install consolidation/robo and update the consolidation/robo internal dependencies instead of using the consolidation/robo internal composer.lock to get a known working version of the library.
How do to get composer install to use https://github.com/consolidation/robo/blob/3.0.3/composer.lock when installing consolidation/robo dependencies instead of running the equivalent of composer update on consolidation/robo?
Currently, it's retrieving a broken internal dependency and I have to outline it in my root composer.json which internal dependency should be retrieved. Where as the https://github.com/consolidation/robo/blob/3.0.3/composer.lock has the working version of the library.
That's the way composer is supposed to work.
Lockfiles for dependencies are ignored, that's by design. If the package you are using has broken version constraints (e.g. it says its compatible with ^2.1 of foo/bar, but in reality was only tested with versions >= 2.1.0 && <= 2.2.2, and installing version 2.3 of foo/bar breaks), it's either becuse foo/bar broke the semver promise, or because the package you depend on was not adequately tested.
What you can do is simply add in your root composer.json:
{
"conflict":
"foo/bar": ">=2.3"
}

i have run composer and laravel on my therminal. but when i run laravel new freeCodeGram it said "The Laravel installer requires PHP 7.3.0 or greater

PS C:\Users\TOHEEB> composer
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.10.7 2020-06-03 10:03:56
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--profile Display timing and memory usage information
--no-plugins Whether to disable plugins.
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
--no-cache Prevent use of the cache
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
about Shows the short information about Composer.
archive Creates an archive of this composer package.
browse Opens the package's repository URL or homepage in your browser.
cc Clears composer's internal package cache.
check-platform-reqs Check that platform requirements are satisfied.
clear-cache Clears composer's internal package cache.
clearcache Clears composer's internal package cache.
config Sets config options.
create-project Creates new project from a package into given directory.
depends Shows which packages cause the given package to be installed.
diagnose Diagnoses the system to identify common errors.
dump-autoload Dumps the autoloader.
dumpautoload Dumps the autoloader.
exec Executes a vendored binary/script.
fund Discover how to help fund the maintenance of your dependencies.
global Allows running commands in the global composer dir ($COMPOSER_HOME).
help Displays help for a command
home Opens the package's repository URL or homepage in your browser.
i Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
info Shows information about packages.
init Creates a basic composer.json file in current directory.
install Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
licenses Shows information about licenses of dependencies.
list Lists commands
outdated Shows a list of installed packages that have updates available, including their latest version.
remove Removes a package from the require or require-dev.
run Runs the scripts defined in composer.json.
search Searches for packages.
self-update Updates composer.phar to the latest version.
selfupdate Updates composer.phar to the latest version.
show Shows information about packages.
status Shows a list of locally modified packages, for packages installed from source.
suggests Shows package suggestions.
u Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
update Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
upgrade Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
validate Validates a composer.json and composer.lock.
why Shows which packages cause the given package to be installed.
why-not Shows which packages prevent the given package from being installed.
PS C:\Users\TOHEEB> node -v
v12.18.0
PS C:\Users\TOHEEB> npm -v
6.14.4
PS C:\Users\TOHEEB> laravel
Laravel Installer 3.1.0
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help Displays help for a command
list Lists commands
new Create a new Laravel application
PS C:\Users\TOHEEB> laravel
Laravel Installer 3.1.0
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help Displays help for a command
list Lists commands
new Create a new Laravel application
PS C:\Users\TOHEEB> laravel new freeCodeGram
In NewCommand.php line 45:
The Laravel installer requires PHP 7.3.0 or greater. Please use "composer create-project laravel/laravel" instead.
new [--dev] [--auth] [-f|--force] [--] [<name>]
PS C:\Users\TOHEEB> php -v
PHP 7.2.28 (cli) (built: Feb 18 2020 12:54:18) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
I have experienced this before, what worked for me was
composer create-project laravel/laravel nameofproject
I'm not familiar with freeCodeGram, but the error is telling you to use Laravel to create a project.
composer create-project laravel/laravel
PHP 7.2 is installed? Check the Laravel documentation on required PHP version to make sure it matches your PHP version.
composer.json will show you what version of Laravel framework is being installed and the required PHP version. Make sure no dependencies require a higher version than what you have installed too.
You can create a project with a specific Laravel version like this:
composer create-project laravel/laravel="5.5.*" myApp

composer.json file property name is required

I am using composer for the first time so if I shouldn't be posting here I am very sorry.
I am following a youtube tutorial on the paypal api I have installed composer and created the json file the same as the example. composer.json is saved in the root folder for the website. the structure is below. composer diagnose composer.json: fail and property name is required.
{
"require": {
"paypal/rest-api-php": "1.5.1"
}
}
looks like your composer had much fresher version, check composer --version !
need to update composer.json with:
{
"name": "some/name",
"description": "Some description will be useful too!",
"require": {
"paypal/rest-api-php": "1.5.1"
}
}
or install some old version, by exec 3lines
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=1.0.1
php -r "unlink('composer-setup.php');"
The best way to start a project using Composer:
composer init
This will ask you some questions, some of them with sensible defaults that you can simply accept - others (like the name of your project) cannot be guessed.
The best way to install a package after that
composer require package/name
Optionally for development packages:
composer require --dev package/name
The composer command used here assumes you have downloaded "composer.phar" and renamed or symlinked it in a way that it can be called just by typing composer. Otherwise, replace that command with the one that works for you, like php composer.phar or composer.phar.

composer not downloading latest composer.json from github?

Here's my projects composer.json:
{
"require": {
"phpseclib/phpseclib": "0.3.x"
}
}
Here's phpseclib's composer.json:
https://github.com/phpseclib/phpseclib/blob/master/composer.json
Note how that file has in it this line:
"System": "phpseclib/"
When I do cat vendor/phpseclib/phpseclib/composer.json I don't see that line. Why not?
You have told Composer to download the latest tagged version of "phpseclib/phpseclib" that matches "0.3.x".
First - there is no version tagged since they added "System": "phpseclib/" so Composer isn't downloading it. You should set the required version to be dev-master if you want to get the absolutely latest version.
Second - I don't think 0.3.x isn't a valid semver version. Did you mean 0.3.* or the equivalent ~0.3 ?

Resources