1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the `liip/LiipImagineBundle` project. |
5
|
|
|
* |
6
|
|
|
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Liip\ImagineBundle\Utility\Framework; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
15
|
|
|
|
16
|
|
|
class SymfonyFramework |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @return bool |
20
|
|
|
*/ |
21
|
|
|
public static function hasDefinitionSharing() |
22
|
|
|
{ |
23
|
|
|
return method_exists('\Symfony\Component\DependencyInjection\Definition', 'setShared') |
24
|
|
|
&& method_exists('\Symfony\Component\DependencyInjection\Definition', 'isShared'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return bool |
29
|
|
|
*/ |
30
|
|
|
public static function hasDefinitionScoping() |
31
|
|
|
{ |
32
|
|
|
return method_exists('\Symfony\Component\DependencyInjection\Definition', 'setScope') |
33
|
|
|
&& method_exists('\Symfony\Component\DependencyInjection\Definition', 'getScope'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
|
|
public static function hasDirectContainerBuilderLogging() |
40
|
|
|
{ |
41
|
|
|
return method_exists('\Symfony\Component\DependencyInjection\ContainerBuilder', 'log'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param int $major |
46
|
|
|
* @param int|null $minor |
47
|
|
|
* @param int|null $patch |
48
|
|
|
* |
49
|
|
|
* @return bool |
50
|
|
|
*/ |
51
|
|
|
public static function isKernelGreaterThanOrEqualTo($major, $minor = null, $patch = null) |
52
|
|
|
{ |
53
|
|
|
return static::kernelVersionCompare('>=', $major, $minor, $patch); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param int $major |
58
|
|
|
* @param int|null $minor |
59
|
|
|
* @param int|null $patch |
60
|
|
|
* |
61
|
|
|
* @return bool |
62
|
|
|
*/ |
63
|
|
|
public static function isKernelLessThan($major, $minor = null, $patch = null) |
64
|
|
|
{ |
65
|
|
|
return static::kernelVersionCompare('<', $major, $minor, $patch); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $operator |
70
|
|
|
* @param int $major |
71
|
|
|
* @param int|null $minor |
72
|
|
|
* @param int|null $patch |
73
|
|
|
* |
74
|
|
|
* @return bool |
75
|
|
|
*/ |
76
|
|
|
private static function kernelVersionCompare($operator, $major, $minor = null, $patch = null) |
77
|
|
|
{ |
78
|
|
|
$vernum = $major; |
79
|
|
|
$kernel = Kernel::MAJOR_VERSION; |
80
|
|
|
|
81
|
|
|
if ($minor) { |
|
|
|
|
82
|
|
|
$vernum .= '.'.$minor; |
83
|
|
|
$kernel .= '.'.Kernel::MINOR_VERSION; |
84
|
|
|
|
85
|
|
|
if ($patch) { |
|
|
|
|
86
|
|
|
$vernum .= '.'.$patch; |
87
|
|
|
$kernel .= '.'.Kernel::RELEASE_VERSION; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return version_compare($kernel, $vernum, $operator); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: