Skip to content

Commit 2627e3a

Browse files
samdarkgithub-actions[bot]
authored andcommitted
Update translation
1 parent 8683f84 commit 2627e3a

7 files changed

Lines changed: 1127 additions & 234 deletions

File tree

_translations/po/es/guide_concept_di-container.md.po

Lines changed: 176 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
msgid ""
77
msgstr ""
88
"Project-Id-Version: PACKAGE VERSION\n"
9-
"POT-Creation-Date: 2026-01-16 07:58+0000\n"
9+
"POT-Creation-Date: 2026-01-16 10:36+0000\n"
1010
"PO-Revision-Date: 2025-09-04 07:37+0500\n"
1111
"Last-Translator: Automatically generated\n"
1212
"Language-Team: none\n"
@@ -111,12 +111,17 @@ msgstr ""
111111

112112
#. type: Plain text
113113
#: ../src/guide/concept/di-container.md
114-
msgid "We've avoided unnecessary inheritance and used interface to reduce coupling. You can replace cache implementation without changing `CachedWidget` so it's becoming more stable."
114+
msgid "We've avoided unnecessary inheritance and used `CacheInterface` in the `CacheWidget` to reduce coupling. You can replace cache implementation without changing `CachedWidget` so it's becoming more stable. The less edits are made to the code, the less chance of breaking it."
115115
msgstr ""
116116

117117
#. type: Plain text
118118
#: ../src/guide/concept/di-container.md
119-
msgid "The `CacheInterface` here is a dependency: an object another object depends on. The process of putting an instance of dependency into an object (`CachedWidget`) is called dependency injection. There are many ways to perform it:"
119+
msgid "The `CacheInterface` here is a dependency: a contract our object needs to function. In other words, our object depends on the contract."
120+
msgstr ""
121+
122+
#. type: Plain text
123+
#: ../src/guide/concept/di-container.md
124+
msgid "The process of putting an instance of a contract into an object (`CachedWidget`) is called dependency injection. There are many ways to perform it:"
120125
msgstr ""
121126

122127
#. type: Bullet: '- '
@@ -198,12 +203,12 @@ msgstr ""
198203

199204
#. type: Bullet: '- '
200205
#: ../src/guide/concept/di-container.md
201-
msgid "Define how to instantiate such an API wrapper."
206+
msgid "Define how to instantiate such common dependencies."
202207
msgstr ""
203208

204209
#. type: Bullet: '- '
205210
#: ../src/guide/concept/di-container.md
206-
msgid "Instantiate it when required and only once per request."
211+
msgid "Instantiate them when required and only once per request."
207212
msgstr ""
208213

209214
#. type: Plain text
@@ -213,7 +218,7 @@ msgstr ""
213218

214219
#. type: Plain text
215220
#: ../src/guide/concept/di-container.md
216-
msgid "A dependency injection (DI) container is an object that knows how to instantiate and configure objects and all their dependent objects. [Martin Fowler's article](https://martinfowler.com/articles/injection.html) has well explained why DI container is useful. Here we will mainly explain the usage of the DI container provided by Yii."
221+
msgid "A dependency injection (DI) container is an object that knows how to instantiate and configure objects and all objects they depend on."
217222
msgstr ""
218223

219224
#. type: Plain text
@@ -229,6 +234,24 @@ msgstr ""
229234
msgid "Yii provides the DI container feature through the [yiisoft/di](https://github.com/yiisoft/di) package and [yiisoft/injector](https://github.com/yiisoft/injector) package."
230235
msgstr ""
231236

237+
#. type: Plain text
238+
#: ../src/guide/concept/di-container.md
239+
#, no-wrap
240+
msgid ""
241+
"> [!NOTE]\n"
242+
"> The container contains only shared instances. If you need a factory, use the dedicated\n"
243+
"> [yiisoft/factory](https://github.com/yiisoft/factory) package.\n"
244+
msgstr ""
245+
246+
#. type: Plain text
247+
#: ../src/guide/concept/di-container.md
248+
#, no-wrap
249+
msgid ""
250+
"> [!TIP]\n"
251+
"> [Martin Fowler's article](https://martinfowler.com/articles/injection.html) has well\n"
252+
"> explained why DI container is useful. Here we will mainly explain the usage of the DI container provided by Yii.\n"
253+
msgstr ""
254+
232255
#. type: Title ###
233256
#: ../src/guide/concept/di-container.md
234257
#, no-wrap
@@ -290,44 +313,169 @@ msgstr ""
290313

291314
#. type: Plain text
292315
#: ../src/guide/concept/di-container.md
293-
msgid "There are extra methods of declaring dependencies:"
316+
msgid "You can provide arguments with names as well:"
294317
msgstr ""
295318

296319
#. type: Fenced code block (php)
297320
#: ../src/guide/concept/di-container.md
298321
#, no-wrap
299322
msgid ""
300323
"return [\n"
301-
" // declare a class for an interface, resolve dependencies automatically\n"
302-
" EngineInterface::class => EngineMarkOne::class,\n"
303-
"\n"
304-
" // array definition (same as above)\n"
305-
" 'full_definition' => [\n"
306-
" 'class' => EngineMarkOne::class,\n"
307-
" '__construct()' => [42], \n"
308-
" '$propertyName' => 'value',\n"
309-
" 'setX()' => [42],\n"
324+
" MyServiceInterface::class => [\n"
325+
" 'class' => MyService::class,\n"
326+
" '__construct()' => ['amount' => 42],\n"
327+
" 'setDiscount()' => ['discount' => 10],\n"
310328
" ],\n"
329+
"];\n"
330+
msgstr ""
331+
332+
#. type: Plain text
333+
#: ../src/guide/concept/di-container.md
334+
msgid "That's basically it. You define a map of interfaces to classes and define how to configure them. When an interface is requested in constructor or elsewhere, container creates an instance of a class and configures it as per the configuration:"
335+
msgstr ""
336+
337+
#. type: Fenced code block (php)
338+
#: ../src/guide/concept/di-container.md
339+
#, no-wrap
340+
msgid ""
341+
"final class MyAction\n"
342+
"{\n"
343+
" public function __construct(\n"
344+
" private readonly MyServiceInterface $myService\n"
345+
" ) {\n"
346+
" }\n"
347+
" \n"
348+
" public function __invoke() \n"
349+
" {\n"
350+
" $this->myService->doSomething();\n"
351+
" }\n"
352+
"}\n"
353+
msgstr ""
354+
355+
#. type: Plain text
356+
#: ../src/guide/concept/di-container.md
357+
msgid "There are extra methods of declaring dependency configuration."
358+
msgstr ""
359+
360+
#. type: Plain text
361+
#: ../src/guide/concept/di-container.md
362+
msgid "For simplest cases where there are no custom values needed and all the constructor dependencies could be obtained from a container, you can use a class name as a value."
363+
msgstr ""
364+
365+
#. type: Fenced code block (php)
366+
#: ../src/guide/concept/di-container.md
367+
#, no-wrap
368+
msgid ""
369+
"interface EngineInterface\n"
370+
"{\n"
371+
" \n"
372+
"}\n"
311373
"\n"
312-
" // closure\n"
313-
" 'closure' => static function(ContainerInterface $container) {\n"
314-
" return new MyClass($container->get('db'));\n"
315-
" },\n"
316-
"\n"
317-
" // static call\n"
318-
" 'static_call' => [MyFactory::class, 'create'],\n"
319-
"\n"
320-
" // instance of an object\n"
321-
" 'object' => new MyClass(),\n"
374+
"final class EngineMarkOne implements EngineInterface\n"
375+
"{\n"
376+
" public function __construct(CacheInterface $cache) {\n"
377+
" } \n"
378+
"}\n"
379+
msgstr ""
380+
381+
#. type: Plain text
382+
#: ../src/guide/concept/di-container.md
383+
msgid "In the above example, if we already have cache defined in the container, nothing besides the class name is needed:"
384+
msgstr ""
385+
386+
#. type: Fenced code block (php)
387+
#: ../src/guide/concept/di-container.md
388+
#, no-wrap
389+
msgid ""
390+
"return [\n"
391+
" // declare a class for an interface, resolve dependencies automatically\n"
392+
" EngineInterface::class => EngineMarkOne::class,\n"
322393
"];\n"
323394
msgstr ""
324395

325-
#. type: Title ###
396+
#. type: Plain text
397+
#: ../src/guide/concept/di-container.md
398+
msgid "If you have a dependency that has public properties, you can configure it as well."
399+
msgstr ""
400+
401+
#. type: Fenced code block (php)
402+
#: ../src/guide/concept/di-container.md
403+
#, no-wrap
404+
msgid ""
405+
"final class NameProvider\n"
406+
"{\n"
407+
" public string $name;\n"
408+
"}\n"
409+
msgstr ""
410+
411+
#. type: Plain text
412+
#: ../src/guide/concept/di-container.md
413+
msgid "Here's how to do it for the example above:"
414+
msgstr ""
415+
416+
#. type: Fenced code block (php)
417+
#: ../src/guide/concept/di-container.md
418+
#, no-wrap
419+
msgid ""
420+
"NameProvider::class => [\n"
421+
" 'class' => NameProvider::class, \n"
422+
" '$name' => 'Alex',\n"
423+
"],\n"
424+
msgstr ""
425+
426+
#. type: Plain text
427+
#: ../src/guide/concept/di-container.md
428+
msgid "In this example, you may notice `NameProvider` specified twice. The key is what you may request as dependency and the value is how to create it."
429+
msgstr ""
430+
431+
#. type: Plain text
432+
#: ../src/guide/concept/di-container.md
433+
msgid "If the configuration is tricky and requires some logic, a closure can be used:"
434+
msgstr ""
435+
436+
#. type: Fenced code block (php)
326437
#: ../src/guide/concept/di-container.md
327438
#, no-wrap
328-
msgid "Injecting dependencies <span id=\"injecting-dependencies\"></span>"
439+
msgid ""
440+
"MyServiceInterface::class => static function(ContainerInterface $container) {\n"
441+
" return new MyService($container->get('db'));\n"
442+
"},\n"
329443
msgstr ""
330444

445+
#. type: Plain text
446+
#: ../src/guide/concept/di-container.md
447+
msgid "As an argument, a container is passed to a closure. It can be used to resolve dependencies."
448+
msgstr ""
449+
450+
#. type: Plain text
451+
#: ../src/guide/concept/di-container.md
452+
msgid "It's possible to use a static method call:"
453+
msgstr ""
454+
455+
#. type: Fenced code block (php)
456+
#: ../src/guide/concept/di-container.md
457+
#, no-wrap
458+
msgid "MyServiceInterface::class => [MyFactory::class, 'create'],\n"
459+
msgstr ""
460+
461+
#. type: Plain text
462+
#: ../src/guide/concept/di-container.md
463+
msgid "Or an instance of an object:"
464+
msgstr ""
465+
466+
#. type: Fenced code block (php)
467+
#: ../src/guide/concept/di-container.md
468+
#, no-wrap
469+
msgid "MyServiceInterface::class => new MyService(),\n"
470+
msgstr ""
471+
472+
#. type: Title ###
473+
#: ../src/guide/concept/di-container.md
474+
#, fuzzy, no-wrap
475+
#| msgid "Detaching event handlers <span id=\"detaching-event-handlers\"></span>"
476+
msgid "Injecting dependencies properly <span id=\"injecting-dependencies\"></span>"
477+
msgstr "Desacoplar Gestores de Eventos <span id=\"detaching-event-handlers\"></span>"
478+
331479
#. type: Plain text
332480
#: ../src/guide/concept/di-container.md
333481
msgid "Directly referencing a container in a class is a bad idea since the code becomes non-generic, coupled to the container interface and, what's worse, dependencies are becoming hidden. Because of that, Yii inverts the control by automatically injecting objects from a container in some constructors and methods based on method argument types."

0 commit comments

Comments
 (0)