Skip to content

Commit 0956afd

Browse files
committed
docs: add docs
1 parent 7a1e8cc commit 0956afd

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

user_guide_src/source/changelogs/v4.6.0.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ The ``Filters`` class has been changed to allow multiple runs of the same filter
5050
with 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

5562
Interface Changes

user_guide_src/source/installation/upgrade_460.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ See :ref:`ChangeLog <v460-behavior-changes-exceptions>` for details.
2929

3030
If 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+
3254
Interface Changes
3355
=================
3456

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.

0 commit comments

Comments
 (0)