1
<?php
2

3
/*
4
 * This file is part of the Solarium package.
5
 *
6
 * For the full copyright and license information, please view the COPYING
7
 * file that was distributed with this source code.
8
 */
9

10
namespace Solarium;
11

12
use Solarium\Core\Client\Client as CoreClient;
13

14
/**
15
 * This class makes the client easier to use (shorter class name) and adds
16
 * a library version check.
17
 */
18
class Client extends CoreClient
19
{
20
    /**
21
     * Version number of the Solarium library.
22
     *
23
     * The version is built up in this format: major.minor.mini
24
     *
25
     * A major release is used for significant release with architectural
26
     * changes and changes that might break backwards compatibility
27
     *
28
     * A minor release adds and enhances features, and might also contain
29
     * bugfixes. It should be backwards compatible, or the incompatibilities
30
     * should be clearly documented with the release.
31
     *
32
     * A mini release only contains bugfixes to existing features and is always
33
     * backwards compatible.
34
     *
35
     * If you develop your application to a specific Solarium version it is best
36
     * to check for that exact major and minor version, leaving the mini version
37
     * open to allow for upgrades in case of bugfixes.
38
     *
39
     * @see checkExact()
40
     * @see checkMinimal()
41
     *
42
     * @var string
43
     */
44
    const VERSION = '6.0.1';
45

46
    /**
47
     * Check for an exact version.
48
     *
49
     * This method can check for all three versioning levels, but they are
50
     * optional. If you only care for major and minor versions you can use
51
     * something like '1.0' as input. Or '1' if you only want to check a major
52
     * version.
53
     *
54
     * For each level that is checked the input has to be exactly the same as
55
     * the actual version. Some examples:
56
     *
57
     * The if the version is 1.2.3 the following checks would return true:
58
     * - 1 (only major version is checked)
59
     * - 1.2 (only major and minor version are checked)
60
     * - 1.2.3 (full version is checked)
61
     *
62
     * These values will return false:
63
     * - 1.0 (lower)
64
     * - 1.2.4 (higher)
65
     *
66
     *
67
     * A string compare is used instead of version_compare because
68
     * version_compare returns false for a compare of 1.0.0 with 1.0
69
     *
70
     * @param string $version
71
     *
72
     * @return bool
73
     */
74 12
    public static function checkExact(string $version): bool
75
    {
76 12
        return 0 === strpos(self::VERSION, $version);
77
    }
78

79
    /**
80
     * Check for a minimal version.
81
     *
82
     * This method can check for all three versioning levels, but they are
83
     * optional. If you only care for major and minor versions you can use
84
     * something like '1.0' as input. Or '1' if you only want to check a major
85
     * version.
86
     *
87
     * For each level that is checked the actual value needs to be the same or
88
     * higher. Some examples:
89
     *
90
     * The if the version is 1.2.3 the following checks would return true:
91
     * - 1.2.3 (the same)
92
     * - 1 (the actual version is higher)
93
     *
94
     * These values will return false:
95
     * - 2 (the actual version is lower)
96
     * - 1.3 (the actual version is lower)
97
     *
98
     * @param string $version
99
     *
100
     * @return bool
101
     */
102 12
    public static function checkMinimal(string $version): bool
103
    {
104 12
        return version_compare(self::VERSION, $version, '>=');
105
    }
106
}

Read our documentation on viewing source code .

Loading