1 | <?php |
||
10 | class Scope |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | private $locales; |
||
16 | |||
17 | /** |
||
18 | * The active locale. |
||
19 | * |
||
20 | * @var Locale |
||
21 | */ |
||
22 | private static $activeLocale; |
||
23 | |||
24 | /** |
||
25 | * The default locale. In the request path |
||
26 | * it's the hidden segment, e.g. /. |
||
27 | * |
||
28 | * @var Locale |
||
29 | */ |
||
30 | private $default; |
||
31 | |||
32 | /** |
||
33 | * When the canonical scope has a root set to be |
||
34 | * other than the current, that specific root is defined here |
||
35 | * By default the current request root is of use (NULL). |
||
36 | * |
||
37 | * @var null|Root |
||
38 | */ |
||
39 | private $customRoot = null; |
||
40 | |||
41 | 83 | public function __construct(array $locales) |
|
49 | |||
50 | 12 | public function setCustomRoot(Root $customRoot) |
|
56 | |||
57 | 10 | public function customRoot(): ?Root |
|
61 | |||
62 | /** |
||
63 | * Get the locale by segment identifier. |
||
64 | * |
||
65 | * @param $segment |
||
66 | * |
||
67 | * @return null|Locale |
||
68 | */ |
||
69 | 68 | public function findLocale($segment): ?Locale |
|
73 | |||
74 | 32 | public function locales(): array |
|
78 | |||
79 | 61 | public function defaultLocale(): Locale |
|
83 | |||
84 | 19 | public static function activeLocale(): ?Locale |
|
92 | |||
93 | 68 | public static function setActiveLocale(Locale $locale) |
|
97 | |||
98 | /** |
||
99 | * Get the url segment which corresponds with the passed locale. |
||
100 | * |
||
101 | * @param null $locale |
||
102 | * |
||
103 | * @return null|string |
||
104 | */ |
||
105 | 35 | public function segment($locale = null): ?string |
|
113 | |||
114 | 18 | public function activeSegment(): ?string |
|
118 | |||
119 | 27 | public function validateLocale(string $locale = null): bool |
|
127 | |||
128 | 24 | public function validateSegment(string $segment = null): bool |
|
136 | |||
137 | 1 | public function refresh() |
|
141 | } |
||
142 |
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: