You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/6.x/extend/services.md
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -158,6 +158,30 @@ The same pattern could be applied to widgets (`CraftCms\Cms\Dashboard\Dashboard:
158
158
To make the transition a bit easier, we’ve brought along some of Yii’s “component” features that were upstream of Craft services.
159
159
Your services (and other data models) can extend `CraftCms\Cms\Component\Component` to get access to [validation](validation.md), macros, array-style access, and more.
160
160
161
+
### Configuration
162
+
163
+
Laravel is broadly less config-driven than Yii.
164
+
Services can be instantiated from anywhere (and at any time), so it’s expected that they know how to resolve their configuration, internally (usually by grabbing values with `config(...)` at runtime).
165
+
As a result of flattening the application’s overall architecture, Yii’s [application configuration](guide:structure-applications#application-configurations) is no longer relevant—there is no centrally-defined component “tree” to initialize from config.
166
+
167
+
Components bridge this gap by accepting a “configuration” array in their constructors, which is mapped and typecast onto its public properties.
168
+
In many cases, we have elected to replace this top-down pattern with a combination of other strategies:
169
+
170
+
- Initialize with defaults that draw from general config settings and other `config(...)` calls;
171
+
- Provide methods to dynamically or temporarily reconfigure a service for the duration of a closure;
172
+
173
+
You may have already been exposed to the second strategy when rendering templates, in earlier versions of Craft:
174
+
175
+
```php
176
+
use CraftCms\Cms\View\TemplateMode;
177
+
178
+
TemplateMode::with(TemplateMode::Site, function () {
0 commit comments