22CodeIgniter Internals Overview
33##############################
44
5- This guide should help contributors understand how the core of the framework works,
6- and what needs to be done when creating new functionality. Specifically, it
5+ This guide should help contributors understand how the core of the framework works,
6+ and what needs to be done when creating new functionality. Specifically, it
77details the information needed to create new packages for the core.
88
99Dependencies
1010============
1111
12- All packages should be designed to be completely isolated from the rest of the
13- packages, if possible. This will allow them to be used in projects outside of CodeIgniter.
14- Basically, this means that any dependencies should be kept to a minimum.
12+ All packages should be designed to be completely isolated from the rest of the
13+ packages, if possible. This will allow them to be used in projects outside of CodeIgniter.
14+ Basically, this means that any dependencies should be kept to a minimum.
1515Any dependencies must be able to be passed into the constructor. If you do need to use one
16- of the other core packages, you can create that in the constructor using the
16+ of the other core packages, you can create that in the constructor using the
1717Services class, as long as you provide a way for dependencies to override that::
1818
1919 public function __construct(Foo $foo=null)
@@ -27,17 +27,17 @@ Type hinting
2727============
2828
2929PHP7 provides the ability to `type hint <http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration >`_
30- method parameters and return types. Use it where possible. Return type hinting
30+ method parameters and return types. Use it where possible. Return type hinting
3131is not always practical, but do try to make it work.
3232
3333At this time, we are not using strict type hinting.
3434
3535Abstractions
3636============
3737
38- The amount of abstraction required to implement a solution should be the minimal
39- amount required. Every layer of abstraction brings additional levels of technical
40- debt and unnecessary complexity. That said, don't be afraid to use it when it's
38+ The amount of abstraction required to implement a solution should be the minimal
39+ amount required. Every layer of abstraction brings additional levels of technical
40+ debt and unnecessary complexity. That said, don't be afraid to use it when it's
4141needed and can help things.
4242
4343* Don't create a new container class when an array will do just fine.
@@ -46,46 +46,46 @@ needed and can help things.
4646Testing
4747=======
4848
49- Any new packages submitted to the framework must be accompanied by unit tests.
49+ Any new packages submitted to the framework must be accompanied by unit tests.
5050The target is 80%+ code coverage of all classes within the package.
5151
5252* Test only public methods, not protected and private unless the method really needs it due to complexity.
5353* Don't just test that the method works, but test for all fail states, thrown exceptions, and other pathways through your code.
5454
55- You should be aware of the extra assertions that we have made, provisions for
56- accessing private properties for testing, and mock services.
55+ You should be aware of the extra assertions that we have made, provisions for
56+ accessing private properties for testing, and mock services.
5757We have also made a **CITestStreamFilter ** to capture test output.
58- Do check out similar tests in ``tests/system/ ``, and read the "Testing" section
58+ Do check out similar tests in ``tests/system/ ``, and read the "Testing" section
5959in the user guide, before you dig in to your own.
6060
61- Some testing needs to be done in a separate process, in order to setup the
62- PHP globals to mimic test situations properly. See
61+ Some testing needs to be done in a separate process, in order to setup the
62+ PHP globals to mimic test situations properly. See
6363``tests/system/HTTP/ResponseSendTest `` for an example of this.
6464
6565Namespaces and Files
6666====================
6767
68- All new packages should live under the ``CodeIgniter `` namespace.
68+ All new packages should live under the ``CodeIgniter `` namespace.
6969The package itself will need its own sub-namespace
7070that collects all related files into one grouping, like ``CodeIgniter\HTTP ``.
7171
72- Files MUST be named the same as the class they hold, and they must match the
73- :doc: `Style Guide <./styleguide.rst >`, meaning CamelCase class and file names.
74- They should be in their own directory that matches the sub-namespace under the
72+ Files MUST be named the same as the class they hold, and they must match the
73+ :doc: `Style Guide <./styleguide.rst >`, meaning CamelCase class and file names.
74+ They should be in their own directory that matches the sub-namespace under the
7575**system ** directory.
7676
77- Take the Router class as an example. The Router lives in the ``CodeIgniter\Router ``
77+ Take the Router class as an example. The Router lives in the ``CodeIgniter\Router ``
7878namespace. Its two main classes,
7979**RouteCollection ** and **Router **, are in the files **system/Router/RouteCollection.php ** and
8080**system/Router/Router.php ** respectively.
8181
8282Interfaces
8383----------
8484
85- Most base classes should have an interface defined for them.
85+ Most base classes should have an interface defined for them.
8686At the very least this allows them to be easily mocked
87- and passed to other classes as a dependency, without breaking the type-hinting.
88- The interface names should match the name of the class with "Interface" appended
87+ and passed to other classes as a dependency, without breaking the type-hinting.
88+ The interface names should match the name of the class with "Interface" appended
8989to it, like ``RouteCollectionInterface ``.
9090
9191The Router package mentioned above includes the
@@ -95,8 +95,8 @@ interfaces to provide the abstractions for the two classes in the package.
9595Handlers
9696--------
9797
98- When a package supports multiple "drivers", the convention is to place them in
99- a **Handlers ** directory, and name the child classes as Handlers.
98+ When a package supports multiple "drivers", the convention is to place them in
99+ a **Handlers ** directory, and name the child classes as Handlers.
100100You will often find that creating a ``BaseHandler ``, that the child classes can
101101extend, to be beneficial in keeping the code DRY.
102102
@@ -105,34 +105,44 @@ See the Log and Session packages for examples.
105105Configuration
106106=============
107107
108- Should the package require user-configurable settings, you should create a new
109- file just for that package under **app/Config **.
108+ Should the package require user-configurable settings, you should create a new
109+ file just for that package under **app/Config **.
110110The file name should generally match the package name.
111111
112112Autoloader
113113==========
114114
115- All files within the package should be added to **system/Config/AutoloadConfig.php **,
116- in the "classmap" property. This is only used for core framework files, and helps
115+ All files within the package should be added to **system/Config/AutoloadConfig.php **,
116+ in the "classmap" property. This is only used for core framework files, and helps
117117to minimize file system scans and keep performance high.
118118
119119Command-Line Support
120120====================
121121
122- CodeIgniter has never been known for it's strong CLI support. However, if your
123- package could benefit from it, create a new file under **system/Commands **.
122+ CodeIgniter has never been known for it's strong CLI support. However, if your
123+ package could benefit from it, create a new file under **system/Commands **.
124124The class contained within is simply a controller that is intended for CLI
125- usage only. The ``index() `` method should provide a list of available commands
125+ usage only. The ``index() `` method should provide a list of available commands
126126provided by that package.
127127
128- Routes must be added to **system/Config/Routes.php ** using the ``cli() `` method
128+ Routes must be added to **system/Config/Routes.php ** using the ``cli() `` method
129129to ensure it is not accessible through the browser, but is restricted to the CLI only.
130130
131131See the **MigrationsCommand ** file for an example.
132132
133133Documentation
134134=============
135135
136- All packages must contain appropriate documentation that matches the tone and
137- style of the rest of the user guide. In most cases, the top portion of the package's
136+ All packages must contain appropriate documentation that matches the tone and
137+ style of the rest of the user guide. In most cases, the top portion of the package's
138138page should be treated in tutorial fashion, while the second half would be a class reference.
139+
140+ Modification of the ``env `` file
141+ ================================
142+
143+ CodeIgniter is shipped with a template ``env `` file to support adding secrets too sensitive to
144+ be stored in a version control system. Contributors adding new entries to the env file should
145+ always ensure that these entries are commented, i.e., starting with a hash (``# ``). This is
146+ because we have spark commands that actually copy the template file to a ``.env `` file (which
147+ is actually the live version actually read by CodeIgniter for secrets) if the latter is missing.
148+ As much as possible, we do not want settings to go live unexpectedly without the user's knowledge.
0 commit comments