1 | <?php |
||
9 | class Scope |
||
10 | { |
||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | private $locales; |
||
15 | |||
16 | /** |
||
17 | * The active locale. |
||
18 | * |
||
19 | * @var Locale |
||
20 | */ |
||
21 | private static $activeLocale; |
||
22 | |||
23 | /** |
||
24 | * The default locale. In the request path |
||
25 | * it's the hidden segment, e.g. /. |
||
26 | * |
||
27 | * @var Locale |
||
28 | */ |
||
29 | private $default; |
||
30 | |||
31 | /** |
||
32 | * When the canonical scope has a root set to be |
||
33 | * other than the current, that specific root is defined here |
||
34 | * By default the current request root is of use (NULL). |
||
35 | * |
||
36 | * @var null|Root |
||
37 | */ |
||
38 | private $customRoot = null; |
||
39 | |||
40 | 86 | public function __construct(array $locales) |
|
48 | |||
49 | 12 | public function setCustomRoot(Root $customRoot) |
|
55 | |||
56 | 10 | public function customRoot(): ?Root |
|
60 | |||
61 | /** |
||
62 | * Get the locale by segment identifier. |
||
63 | * |
||
64 | * @param $segment |
||
65 | * |
||
66 | * @return null|Locale |
||
67 | */ |
||
68 | 72 | public function findLocale($segment): ?Locale |
|
72 | |||
73 | 35 | public function locales(): array |
|
77 | |||
78 | 65 | public function defaultLocale(): Locale |
|
82 | |||
83 | 18 | public static function activeLocale(): ?Locale |
|
87 | |||
88 | 72 | public static function setActiveLocale(Locale $locale) |
|
92 | |||
93 | /** |
||
94 | * Get the url segment which corresponds with the passed locale. |
||
95 | * |
||
96 | * @param null $locale |
||
97 | * |
||
98 | * @return null|string |
||
99 | */ |
||
100 | 39 | public function segment($locale = null): ?string |
|
108 | |||
109 | 18 | public function activeSegment(): ?string |
|
113 | |||
114 | 30 | public function validateLocale(string $locale = null): bool |
|
122 | |||
123 | 27 | public function validateSegment(string $segment = null): bool |
|
131 | } |
||
132 |
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: