Override PHP Base Dependency in Composer

Override PHP base dependency in composer

The error message indicates a requirement from the main composer.json. The version requirement can be just adapted:

"require": {
"php": ">=5.5",

After changing the version like this I get:

  Problem 1
- Installation request for classpreloader/classpreloader 2.0.0 -> satisfiable by classpreloader/classpreloader[2.0.0].
- classpreloader/classpreloader 2.0.0 requires php >=5.5.9 -> your PHP version (5.5.6) or "config.platform.php" value does not satisfy that requirement.
Problem 2
- Installation request for laravel/framework v5.1.17 -> satisfiable by laravel/framework[v5.1.17].
- laravel/framework v5.1.17 requires php >=5.5.9 -> your PHP version (5.5.6) or "config.platform.php" value does not satisfy that requirement.
Problem 3
- Installation request for laravelcollective/html v5.1.6 -> satisfiable by laravelcollective/html[v5.1.6].
- laravelcollective/html v5.1.6 requires php >=5.5.9 -> your PHP version (5.5.6) or "config.platform.php" value does not satisfy that requirement.
Problem 4
- laravel/framework v5.1.17 requires php >=5.5.9 -> your PHP version (5.5.6) or "config.platform.php" value does not satisfy that requirement.
- jenssegers/agent v2.1.7 requires illuminate/support ~4.0|~5.0 -> satisfiable by laravel/framework[v5.1.17].
- Installation request for jenssegers/agent v2.1.7 -> satisfiable by jenssegers/agent[v2.1.7].

Using the following snippet in composer.json, a php version can be simulated

[...]
"config": {
"preferred-install": "dist",
"platform": {
"php": "5.5.9"
}
}

Doc: https://getcomposer.org/doc/06-config.md#platform

platform

Lets you fake platform packages (PHP and extensions) so that you can emulate a production env or define your target platform in the config. Example: {"php": "5.4", "ext-something": "4.0"}.

Don't forget to run a composer.phar update after this

Composer: How to override a requirement globally for composer.json?

I believe the docs have a good example for this scenario.

Basically you need to define an alias in your composer.json as following:

"require": {
"asm89/twig-cache-extension": "dev-master as 1.3",
"emanueleminotto/twig-cache-bundle": "1.0.2",
}

Added by the questioner:

One step was still missing: "composer update asm89/twig-cache-extension"

Dependency install errors in composer

Unfortunately HHVM no longer supports vanilla PHP. You should use the vanilla (Zend) PHP runtime, and should not install HHVM as php on your system.

More information on both PHP deprecation and Composer is here: https://hhvm.com/blog/2019/02/11/hhvm-4.0.0.html

How to override others dependencies in composer.json

In your own composer.json, you can do this:

{
"require": {
"h4cc/alice-fixtures-bundle": "dev/master", //Whatever version you use
"fzaninotto/faker": "dev-master as 1.0"
}
}

Error Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement

It's because in your project in composer.json file you have:

"require": {
"php": ">=7.3",
.....
},

Try to update this requirement to:

"require": {
"php": "^7.3|^8.0",
.....
},

How to override required version defined by composer.json hosted on packagist.org?

There is a workaround by using replace property which aims to replace given package, so other packages won't download it. For example:

{
"require": {
"aeris/guzzle-http-mock": ">=1.1.5"
},
"replace": {
"guzzlehttp/guzzle": "~5.0.0"
},
"minimum-stability": "dev",
"prefer-stable": true
}

will ignore guzzlehttp/guzzle dependency and it won't be downloaded, however the right version needs to be provided separately or as part of the package.

For example, the required repository can be cloned manually by adding:

"repositories": [
{
"type": "vcs",
"url": "https://github.com/guzzle/guzzle.git"
}
]

Another idea is to use inline aliases like:

"guzzlehttp/guzzle": "dev-5.3.0 as 5.0.3"

but it doesn't work as expected anyway after testing this way, but maybe there is a way.


Related GitHub thread: How to replace the 3rd party dependency?



Related Topics



Leave a reply



Submit