Download the PHP package italystrap/platform-requirements-check without Composer
On this page you can find all versions of the php package italystrap/platform-requirements-check. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download italystrap/platform-requirements-check
More information about italystrap/platform-requirements-check
Files in italystrap/platform-requirements-check
Package platform-requirements-check
Short Description Check the minimum and or maximum requirements for your application
License MIT
Informations about the package platform-requirements-check
Platform Requirements Check
Platform Requirements Check is a PHP library that allows you to check system requirements for your PHP project or plugin. The library provides a simple interface that can be used to define and check system requirements like minimum and maximum PHP versions, PHP extensions, and any other specific project requirements.
This library support PHP 7.4 or higher. If you need to support PHP <7.4 you can use the original Minimum Requirement library where this is forked from.
Table Of Contents
- Installation
- Basic Usage
- Advanced Usage
- Contributing
- License
Installation
The best way to use this package is through Composer:
This package adheres to the SemVer specification and will be fully backward compatible between minor versions.
Basic Usage
The first important thing to do is to require the autoloader file included in this package before the Composer autoloader:
This file will register a PSR-4 autoloader for the ItalyStrap\PlatformRequirementsCheck
namespace.
You need to require it before everything else because this library can't rely on the Composer autoloader since the Composer autoloader itself is loaded to late in the application bootstrap process, so you need to perform PlatformRequirementsCheck before all and if all requirements are met then you can load the Composer autoloader.
The library provides a RequirementInterface
interface which you can use to define your system requirements. Implement this interface to define a new requirement.
I don't know your project so I don't know all the cases you need to add your own requirement, in any case maybe using an anonymous class could be a good idea if you need only a single requirement.
The library also provides two traits, WithNameTrait
and WithConstraintTrait
, which can be used to simplify the creation of new requirement classes.
Additionally, there's a Requirements
class that can be used to group together and check a set of requirements.
RangeVersionRequirement
is a concrete class that implements RequirementInterface
. This class checks if the current version of a certain component (e.g., PHP, Theme or plugin) is within a version range. Use RangeVersionRequirement
to define a version range-based requirement.
Because the min and max versions are optional, if you omit one of them the one you omitted will be replaced with the current version of the component you are checking.
Let's see an example:
You get the point.
Now, one last thing, if you need for example to check for maximum PHP version to be less than 8.1 but greater than 8.0 because right now the operator used for checking the maximum version is '<='
you can do by appending PHP_INT_MAX
to the max version like '8.0.' . PHP_INT_MAX
, so any version less than 8.1 but max than 8.0 will be valid, yes I know, it's a little bit hacky but if you do not like this just create your own requirement class, and you're done.
If $requirement->check()
is false then you can get the error message with $requirement->errorMessage()
and print it if you need to.
For the basic usage, that's all you need to know, I think.
Advanced Usage
If you want to use this library in your WordPress plugin, you can use it like this:
You could check in the main file or like me create a bootstrap.php
file to do all the rest of the stuff.
If the requirements are not met, you can choose to deactivate the plugin or theme, or you can choose to show an error message to the user and let them decide what to do, you have the power.
Right now I decided to not include the check for required plugins like the original package does, if I have some time in the future I could do it.
Contributing
All feedback / bug reports / pull requests are welcome.
License
Copyright (c) 2019 Enea Overclokk, ItalyStrap
This code is licensed under the MIT.