@@ -22,6 +22,70 @@ You can install the package via composer:
2222composer require roadrunner-php/version-checker
2323```
2424
25+ ## Usage
26+
27+ Use the ` RoadRunner\VersionChecker\VersionChecker ` methods to check the compatibility of the installed RoadRunner
28+ version. The VersionChecker class has three public methods:
29+
30+ - ** greaterThan** - Checks if the installed version of RoadRunner is ** greater than or equal** to the specified version.
31+ If no version is specified, the minimum required version will be determined based on the minimum required version of
32+ the ` spiral/roadrunner ` package.
33+ - ** lessThan** - Checks if the installed version of RoadRunner is ** less than or equal** to the specified version.
34+ - ** equal** - Checks if the installed version of RoadRunner is ** equal** to the specified version.
35+
36+ All three methods throw an ` RoadRunner\VersionChecker\Exception\UnsupportedVersionException ` if the installed version
37+ of RoadRunner does not meet the specified requirements. If RoadRunner is not installed, a
38+ ` RoadRunner\VersionChecker\Exception\RoadrunnerNotInstalledException ` is thrown.
39+
40+ ``` php
41+ use RoadRunner\VersionChecker\VersionChecker;
42+ use RoadRunner\VersionChecker\Exception\UnsupportedVersionException;
43+
44+ $checker = new VersionChecker();
45+
46+ try {
47+ $checker->greaterThan('2023.1');
48+ } catch (UnsupportedVersionException $exception) {
49+ var_dump($exception->getMessage()); // Installed RoadRunner version `2.12.3` not supported. Requires version `2023.1` or higher.
50+ var_dump($exception->getInstalledVersion()); // 2.12.3
51+ var_dump($exception->getRequestedVersion()); // 2023.1
52+ }
53+
54+ try {
55+ $checker->lessThan('2.11');
56+ } catch (UnsupportedVersionException $exception) {
57+ var_dump($exception->getMessage()); // Installed RoadRunner version `2.12.3` not supported. Requires version `2.11` or lower.
58+ var_dump($exception->getInstalledVersion()); // 2.12.3
59+ var_dump($exception->getRequestedVersion()); // 2.11
60+ }
61+
62+ try {
63+ $checker->equal('2.11');
64+ } catch (UnsupportedVersionException $exception) {
65+ var_dump($exception->getMessage()); // Installed RoadRunner version `2.12.3` not supported. Requires version `2.11`.
66+ var_dump($exception->getInstalledVersion()); // 2.12.3
67+ var_dump($exception->getRequestedVersion()); // 2.11
68+ }
69+ ```
70+
71+ ### Path to the RoadRunner binary
72+
73+ To configure the ` VersionChecker ` to search for the RoadRunner binary in a location other than the default
74+ (application root with a rr filename), you can bind the ` RoadRunner\VersionChecker\Version\InstalledInterface `
75+ within application container using the ` RoadRunner\VersionChecker\Version\Installed ` class and passing the desired
76+ file path as the ** $executablePath** parameter. After that, you can retrieve the VersionChecker class from
77+ application container.
78+
79+ Example with Spiral Framework container:
80+
81+ ``` php
82+ use RoadRunner\VersionChecker\Version\InstalledInterface;
83+ use RoadRunner\VersionChecker\Version\Installed;
84+
85+ $container->bindSingleton(InstalledInterface::class, new Installed(executablePath: 'some/path'));
86+ $checker = $container->get(VersionChecker::class);
87+ ```
88+
2589## Testing
2690
2791``` bash
0 commit comments