Composer игнорировать версию php

hannesvdvreken / ignore-platform-requirements.md

Since version 1.0.0-alpha9 composer has a new flag for the install and update commands. I’m talking about the —ignore-platform-reqs flag. From the changelog:

Added --ignore-platform-reqs to install/update commands to install even if you are missing a php extension or have an invalid php version. 
--ignore-platform-reqs: ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these. 

Normally when you run composer install, update or require (which will invoke update), composer will compare your installed PHP version with the PHP version limitations from your composer.json’s require field and the PHP version requirements of your other dependencies. The same goes for HHVM. It will also check if some optional PHP extensions are loaded and match the required version, as well as the PHP extension requirements of the required dependencies. When the versions don’t match up, composer will not install your required packagist packages.

But if you add the —ignore-platform-reqs option when you run composer update , it will gracefully ignore these restrictions.

Читайте также:  Create css using javascript

Now, when this feature was being added, people were +1’d for the following reason: they could run composer commands from a different environment than the environment in which the application would run. This is people running composer install on their host machine while their application runs on their vagrant box. I don’t think this solves their problem in all cases because of possible composer after scripts.

Though this is not the reason why I am excited about the new flag. Mainly because I don’t even have PHP installed on my host machine. I’m a vagrant purist.

In my opinion this is a useful addition because you can now install dependencies on automated systems. Test boxes, if you will. Automated systems like tavis-ci and scrutinizer-ci use test boxes without any, or with only a few PHP extensions installed on it. In order to get composer to install your development dependencies, one needs to run bash commands as before scripts to install pear/pecl packages and maybe even modify php.ini files to load these extensions. When for example you have Mockery defined as a dev-dependency for testing and «ext-mongo»: «~1.5» as production use, you can now use the —ignore-platform-reqs flag to install Mockery anayway. Like so, one can inject mocked MongoDB Client objects into classes without the need to load the mongo extension. Unless you’re doing acceptance/integration testing with the extension and an actual MongoDB database server installed on the test box, this new flag might be useful to you. Your .travis.yml file before_script section will be able to be reduced to:

- before_script: - travis_retry composer self-update - travis_retry composer install --prefer-source --no-interaction --dev --ignore-platform-reqs 

One other case when this flag might help you is when one of your dependencies requires a higher PHP version than your package. Let’s say you want to run tests for PHP version 5.3 and you have some helper package as a dependency, but not for testing, which requires PHP 5.4. In that case you may also use the —ignore-platform-reqs flag. Be careful not to misabuse this flag, though. Minimum PHP versions are defined as they are for a reason!

Читайте также:  Php get all subdomains

Well, this was why I think this flag is very useful for package developers. Scrutinizer-ci will use this flag in the near future when they updated their boxes with the newest composer. If you happen to know other cases where this flag comes in handy, leave a comment or hit me up on twitter (@hannesvdvreken).

By the way, I added this small addendum for the people who wonder how composer is able to check your PHP environment. Here’s how: you’re able to retrieve your PHP version using the phpversion function. This function return the value that is stored in the PHP_VERSION global constant. To check if an extension is loaded one can use the extension_loaded function and to retrieve the extension version phpversion($extensionName); . Version comparisons for both PHP version and extension versions can be done using the version_compare function, although the tilde and caret operators will need some more string manipulations and conditionals.

  • Composer changelog: https://github.com/composer/composer/releases/tag/1.0.0-alpha9
  • ignore-platform-reqs GitHub issue: composer/composer#1426
  • ignore-platform-reqs documentation: https://getcomposer.org/doc/03-cli.md#require
  • Travis: https://travis-ci.org/
  • Scrutinizer: https://scrutinizer-ci.com/
  • travis_retry http://docs.travis-ci.com/user/build-timeouts/

Источник

How to install Composer packages ignoring PHP version requirements

A new feature in Composer v2 allows you to selectively ignore platform requirements.

composer install --ignore-platform-req=php

Compared to —ignore-platform-reqs

Composer already has a —ignore-platform-reqs option (notice the s in reqs ), but it ignores all platform requirements, including PHP version, extensions ( ext-* ), and composer-plugin-api .

The new —ignore-platform-req option can be used to set specific requirements that Composer can ignore.

Ignore multiple platform requirements

You can specify one or more platform requirements to ignore by simply using the option multiple times.

For example, to ignore the PHP version and ext-zip , but enforce all other platform requirements, you can use the command like this:

composer install --ignore-platform-req=php --ignore-platform-req=ext-zip

Install Composer packages on unreleased PHP versions

A common use-case of ignore-platform-req option would be to test PHP packages in unreleased PHP versions, or dev builds of PHP.

Libraries such as PHPUnit come with rather strict PHP version constraint in their composer.json file, which prevents them the libraries from being installed in dev versions of PHP.

Instead of using ignore-platform-reqs , which would ignore all platform requirements such as extensions (which might be required for the package to function), you can use ignore-platform-req option to selectively specify platform requirements you intentionally ignore.

Recent Articles on PHP.Watch

How to extend lifetime of legacy PHP applications

How to extend lifetime of legacy PHP applications

As PHP continue to evolve with new breaking changes, and while that is great for most PHP applications, there are legacy applications that can’t justify the human and financial cost of keeping up. Here is a guide on how to extend the lifetime of legacy PHP applications with security updates and maintenance.

PHP 8.2 Highlights: What

PHP 8.2 Highlights: What’s New and Changed

How to install/upgrade PHP 8.2 on Debian and Ubuntu systems

How to install/upgrade PHP 8.2 on Debian and Ubuntu systems

You will receive an email on last Wednesday of every month and on major PHP releases with new articles related to PHP, upcoming changes, new features and what’s changing in the language. No marketing emails, no selling of your contacts, no click-tracking, and one-click instant unsubscribe from any email you receive.

© 2018-2023 PHP.Watch, with ❤ from Ayesh • About PHP.Watch

Источник

Как убрать зависимость от версии в composer?

Если я всё правильно понимаю, это у меня, глобально установлена зависимость, которую по всей видимости как то надо изменить(например на >=7.1)?

Простой 3 комментария

delphinpro

Compolomus

composer install —ignore-platform-reqs
Помогает если скрипт на 7, запускать на 8. Наоборот может ваш скрипт не поехать

Зависимость, скорее всего, вряд ли прописана глобально. Но расположение глобального конфига, откуда это требование можно убрать/настроить, можно посмотреть командой:

$ composer -n config --global home /home//.composer

Если же нужно все равно накатить проект, игнорируя подобные требования, composer install или composer update можно запускать с флагом —ignore-platform-reqs , чтобы проигнорировать вообще все platform-requirements. Либо можно указать игнорирование отдельных требований (возможность появилась в Composer V2). В данном случае, если задача проигнорировать только версию PHP, это будет —ignore-platform-req=php (разница с предыдущей — req , а не reqs ).

gzhegow

Композер это тоже исполняемый скрипт. И исполняется он через алиас привязанный куда то. Под капотом сие запускает пыху и кормит ей пхп файл композера. В итоге в проекте написано юзать пыху такойто версии а у тебя композер другой версией выполняется. Хз я себе создал пять ярлыков композера в разные пыхи. Четыре в пыхи и один который постоянно захожу подменяю. И могу либо написать composer8 require, либо поменять глобальный алиас чтоб 8 не писать постоянно

Войдите, чтобы написать ответ

PHP — как отправить письмо с одного EMail на другой, с помощью SMTP+php?

Источник

Restrict PHP Version for Composer Packages

A conductor with hands raised above the head with one hand holding a baton

It’s quite common in having the web development environment with one version of PHP and then using another version in the production environment. This can cause quite a hassle and make it difficult to manage. Therefore, a developer needs to be able to set restrictions to not just for the dependencies, but also the platform itself, PHP. Luckily there is a solution for those using Composer to manage PHP dependency packages.

PHP Platform

By setting the PHP platform version in the “composer.json” file, this will restrict Composer packages and extensions being installed to only install versions that are compatible to the fake PHP platform version, not the actually PHP version. So next time an installation or update is done with Composer the PHP platform version will be used instead of the actual PHP version installed. This will ensure both development and production environment remain compatible. Though do keep in mind that you may need to require certain package versions to also work within both environments.

The platform setting can be achieved manually by using a text editor or just be simply running a command within your project directory.

$ composer config platform.php 8.0.0 
 "config":  "platform":  "php": "8.0.0" > > > 

For global system setting add the option, “-g” as shown below.

$ composer config -g platform.php 8.0.0 
 "config":  "platform":  "php": "8.0.0" > > > 

Ignoring Platform Requirement

If for some reason you need to ignore the PHP platform setting, you can run the following command to override. Just replace the package name “symfony/mailer” in the example below to any package you desired.

$ composer update symfony/mailer --ignore-platform-reqs 
$ composer install --ignore-platform-reqs 

Check Platform Requirements

It is recommended to verify platform requirements by running the following command as a part of the deployment process.

$ composer check-platform-reqs 
Checking platform requirements for packages in the vendor dir ext-gd 8.1.13 success ext-mbstring * success provided by symfony/polyfill-mbstring ext-pcre 8.1.13 success php 8.1.13 success 

Find PHP Version

PHP 8.1.13 (cli) (built: Nov 23 2022 16:30:12) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.13, Copyright (c) Zend Technologies 
PHP 7.4.33 (cli) (built: Nov 7 2022 21:50:25) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies 

This is post 45 of 100, and is round 2 of the 100 Days To Offload challenge.

References
Changelog

Источник

Оцените статью