File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,13 @@ The ``Filters`` class has been changed to allow multiple runs of the same filter
5050with different arguments in before or after. See
5151:ref: `Upgrading Guide <upgrade-460-filters-changes >` for details.
5252
53+ Registrars
54+ ----------
55+
56+ Added check to prevent Auto-Discovery of Registrars from running twice. If it is
57+ executed twice, an exception will be thrown. See
58+ :ref: `upgrade-460-registrars-with-dirty-hack `.
59+
5360.. _v460-interface-changes :
5461
5562Interface Changes
Original file line number Diff line number Diff line change @@ -29,6 +29,28 @@ See :ref:`ChangeLog <v460-behavior-changes-exceptions>` for details.
2929
3030If you have code that catches these exceptions, change the exception classes.
3131
32+ .. _upgrade-460-registrars-with-dirty-hack :
33+
34+ Registrars with Dirty Hack
35+ ==========================
36+
37+ To prevent Auto-Discovery of :ref: `registrars ` from running twice, when a registrar
38+ class is loaded or instantiated, if it instantiates a Config class (which extends
39+ ``CodeIgniter\Config\BaseConfig ``), ``ConfigException `` will be raised.
40+
41+ This is because if Auto-Discovery of Registrars is performed twice, duplicate
42+ values may be added to properties of Config classes.
43+
44+ All registrar classes (**Config/Registrar.php ** in all namespaces) must be modified
45+ so that they do not instantiate any Config class when loaded or instantiated.
46+
47+ If the packages/modules you are using provide such registrar classes, the registrar
48+ classes in the packages/modules need to be fixed.
49+
50+ The following is an example of code that will no longer work:
51+
52+ .. literalinclude :: upgrade_460/001.php
53+
3254Interface Changes
3355=================
3456
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace CodeIgniter \Shield \Config ;
4+
5+ use Config \App ;
6+
7+ class Registrar
8+ {
9+ public function __construct ()
10+ {
11+ $ config = new App (); // Bad. When this class is instantiated, Config\App will be instantiated.
12+
13+ // Does something.
14+ }
15+
16+ public static function Pager (): array
17+ {
18+ return [
19+ 'templates ' => [
20+ 'module_pager ' => 'MyModule\Views\Pager ' ,
21+ ],
22+ ];
23+ }
24+
25+ public static function hack (): void
26+ {
27+ $ config = config ('Cache ' );
28+
29+ // Does something.
30+ }
31+ }
32+
33+ Registrar::hack (); // Bad. When this class is loaded, Config\Cache will be instantiated.
You can’t perform that action at this time.
0 commit comments