<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Wilmer Arambula</title>
    <description>The latest articles on Forem by Wilmer Arambula (@terabytesoftw).</description>
    <link>https://forem.com/terabytesoftw</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1002398%2F58cfffcb-4ab7-46b8-89dd-f6a1f94e7d91.jpg</url>
      <title>Forem: Wilmer Arambula</title>
      <link>https://forem.com/terabytesoftw</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/terabytesoftw"/>
    <language>en</language>
    <item>
      <title>Creating an application in Yii3 - part 4: the final</title>
      <dc:creator>Wilmer Arambula</dc:creator>
      <pubDate>Mon, 09 Jan 2023 16:48:22 +0000</pubDate>
      <link>https://forem.com/terabytesoftw/creating-an-application-in-yii3-part-4-the-final-4mdl</link>
      <guid>https://forem.com/terabytesoftw/creating-an-application-in-yii3-part-4-the-final-4mdl</guid>
      <description>&lt;p&gt;&lt;strong&gt;Part 4:&lt;/strong&gt;  The final.&lt;/p&gt;

&lt;p&gt;The factory is useful if you need to create objects using &lt;a href="https://github.com/yiisoft/definitions"&gt;definition syntax&lt;/a&gt; and/or want to configure defaults for objects created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PSR11DependencyInjectionContainer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nv"&gt;$factoryConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nc"&gt;EngineInterface&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'class'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;EngineMarkOne&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'__construct()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'power'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nv"&gt;$factory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Factory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$container&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$factoryConfig&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$one&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$factory&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;EngineInterface&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$two&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$factory&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'class'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;EngineInterface&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'__construct()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
           &lt;span class="s1"&gt;'power'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;146&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above we define factory config specifying that when we need &lt;code&gt;EngineInterface&lt;/code&gt;, an instance of &lt;code&gt;EngineMarkOne&lt;/code&gt; will be created with &lt;code&gt;power&lt;/code&gt; constructor argument equals to 42. We also specify that all the dependencies requested by the object created should be resolved by &lt;code&gt;PSR11DependencyInjectionContainer&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;First call to &lt;code&gt;create()&lt;/code&gt; uses default configuration of &lt;code&gt;EngineInterface&lt;/code&gt; as is. Second call specifies custom configuration for &lt;code&gt;power&lt;/code&gt; constructor argument. In this case, configuration specified is merged with default configuration overriding its keys when the key name is the same.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/yiisoft/factory"&gt;factory&lt;/a&gt; always create new instance. The &lt;a href="https://github.com/yiisoft/di"&gt;container di&lt;/a&gt; create new instance once and return same on next calls.&lt;/p&gt;

&lt;p&gt;Now that we are clear about the concepts of configuration, &lt;a href="https://github.com/yiisoft/di"&gt;container di&lt;/a&gt; and &lt;a href="https://github.com/yiisoft/factory"&gt;factory&lt;/a&gt;, let's see the complexity of creating an app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer create-project &lt;span class="nt"&gt;--prefer-dist&lt;/span&gt; &lt;span class="nt"&gt;--stability&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;dev yiisoft/app app-template
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take a look at the &lt;a href="https://github.com/yiisoft/app/tree/master/config"&gt;configuration&lt;/a&gt;, and you'll see that changing it is as simple as changing a parameter in &lt;a href="https://github.com/yiisoft/app/blob/master/config/params.php"&gt;params.php&lt;/a&gt;, we've developed the right tools, that will do the job for you, that's simplicity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Welcome to Yii3&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the next post we will talk about &lt;a href="https://github.com/yiisoft/assets"&gt;assets&lt;/a&gt;, &lt;a href="https://github.com/yiisoft/view"&gt;view&lt;/a&gt;, &lt;a href="https://github.com/yiisoft/widget"&gt;widget&lt;/a&gt;, &lt;a href="https://github.com/yiisoft/db"&gt;db&lt;/a&gt; and &lt;a href="https://github.com/yiisoft/active-record"&gt;active-record&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Wilmer Arámbula.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.yiiframework.com/team"&gt;Team Developer YiiFramework&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/Terabytesoftw"&gt;Twitter follow&lt;/a&gt;&lt;/p&gt;

</description>
      <category>yii3</category>
      <category>php</category>
      <category>yiiframework</category>
    </item>
    <item>
      <title>Creating an application in Yii3 - part 3 the container di.</title>
      <dc:creator>Wilmer Arambula</dc:creator>
      <pubDate>Fri, 06 Jan 2023 15:55:35 +0000</pubDate>
      <link>https://forem.com/terabytesoftw/creating-an-application-in-yii3-part-3-the-container-di-564h</link>
      <guid>https://forem.com/terabytesoftw/creating-an-application-in-yii3-part-3-the-container-di-564h</guid>
      <description>&lt;p&gt;In our post today, we will talk about the &lt;a href="https://github.com/yiisoft/di" rel="noopener noreferrer"&gt;container di&lt;/a&gt;,  but first we must know some important terms, which will help us understand the functioning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dependency injection&lt;/strong&gt; according to &lt;strong&gt;Wikipedia “&lt;/strong&gt;In &lt;a href="https://en.wikipedia.org/wiki/Software_engineering" rel="noopener noreferrer"&gt;software engineering&lt;/a&gt;, &lt;strong&gt;dependency injection&lt;/strong&gt; is a &lt;a href="https://en.wikipedia.org/wiki/Software_design_pattern" rel="noopener noreferrer"&gt;design pattern&lt;/a&gt; in which an &lt;a href="https://en.wikipedia.org/wiki/Object_(computer_science)" rel="noopener noreferrer"&gt;object&lt;/a&gt; or &lt;a href="https://en.wikipedia.org/wiki/Subroutine" rel="noopener noreferrer"&gt;function&lt;/a&gt; receives other objects or functions that it depends on. A form of &lt;a href="https://en.wikipedia.org/wiki/Inversion_of_control" rel="noopener noreferrer"&gt;inversion of control&lt;/a&gt;, dependency injection aims to &lt;a href="https://en.wikipedia.org/wiki/Separation_of_concerns" rel="noopener noreferrer"&gt;separate the concerns&lt;/a&gt; of constructing objects and using them, leading to &lt;a href="https://en.wikipedia.org/wiki/Loose_coupling" rel="noopener noreferrer"&gt;loosely&lt;/a&gt; &lt;a href="https://en.wikipedia.org/wiki/Coupling_(computer_programming)" rel="noopener noreferrer"&gt;coupled&lt;/a&gt; programs.&lt;a href="https://en.wikipedia.org/wiki/Dependency_injection#cite_note-1" rel="noopener noreferrer"&gt;[1]&lt;/a&gt;&lt;a href="https://en.wikipedia.org/wiki/Dependency_injection#cite_note-MarkSeeman2011P4-2" rel="noopener noreferrer"&gt;[2]&lt;/a&gt;&lt;a href="https://en.wikipedia.org/wiki/Dependency_injection#cite_note-3" rel="noopener noreferrer"&gt;[3]&lt;/a&gt; The pattern ensures that an object or function which wants to use a given &lt;a href="https://en.wikipedia.org/wiki/Service_(systems_architecture)" rel="noopener noreferrer"&gt;service&lt;/a&gt; should not have to know how to construct those services. Instead, the receiving '&lt;a href="https://en.wikipedia.org/wiki/Client_(computing)" rel="noopener noreferrer"&gt;client&lt;/a&gt;' (object or function) is provided with its dependencies by external code (an 'injector'), which it is not aware of.&lt;a href="https://en.wikipedia.org/wiki/Dependency_injection#cite_note-HollywoodPrinciple.c2-4" rel="noopener noreferrer"&gt;[4]&lt;/a&gt; Dependency injection helps by making implicit dependencies explicit and helps solve the following problems:&lt;a href="https://en.wikipedia.org/wiki/Dependency_injection#cite_note-5" rel="noopener noreferrer"&gt;[5]&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How can a &lt;a href="https://en.wikipedia.org/wiki/Class_(computer_programming)" rel="noopener noreferrer"&gt;class&lt;/a&gt; be independent from the creation of the objects it depends on?&lt;/li&gt;
&lt;li&gt;How can an application, and the objects it uses support different configurations?&lt;/li&gt;
&lt;li&gt;How can the behavior of a piece of code be changed without editing it directly?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition, dependency injection is used for keeping code in-line with the &lt;a href="https://en.wikipedia.org/wiki/Dependency_inversion_principle" rel="noopener noreferrer"&gt;dependency inversion principle&lt;/a&gt;.&lt;a href="https://en.wikipedia.org/wiki/Dependency_injection#cite_note-6" rel="noopener noreferrer"&gt;[6]&lt;/a&gt;&lt;a href="https://en.wikipedia.org/wiki/Dependency_injection#cite_note-7" rel="noopener noreferrer"&gt;[7]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fundamentally, dependency injection consists of &lt;a href="https://en.wikipedia.org/wiki/Parameter_(computer_programming)" rel="noopener noreferrer"&gt;passing parameters to a method&lt;/a&gt;.&lt;/strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Dependency_injection#cite_note-8" rel="noopener noreferrer"&gt;[8]&lt;/a&gt;”&lt;/p&gt;

&lt;p&gt;Let’s look at the following example:&lt;/p&gt;

&lt;p&gt;There are two ways of re-using things in OOP: inheritance and composition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/**
 * Inheritance is simple.
 */&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getCachedValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// ..&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CachedWidget&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;render&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getCachedValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'cachedWidget'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$output&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$output&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// ...        &lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The issue here is that these two are becoming unnecessarily coupled or inter-dependent making them more fragile.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/**
 * Composition.
 */&lt;/span&gt;
&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;CacheInterface&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getCachedValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;CacheInterface&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getCachedValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// ..&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CachedWidget&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;CacheInterface&lt;/span&gt; &lt;span class="nv"&gt;$cache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Dependency injection.&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;CacheInterface&lt;/span&gt; &lt;span class="nv"&gt;$cache&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$cache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;render&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getCachedValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'cachedWidget'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$output&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$output&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// ...        &lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above we've avoided unnecessary inheritance and used interface to reduce coupling. You can replace cache implementation without changing so it is becoming more stable&lt;code&gt;CachedWidget&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The here is a dependency: an object another object depends on. The process of putting an instance of dependency into an object () is called &lt;strong&gt;dependency injection&lt;/strong&gt;. There are multiple ways to perform it:&lt;code&gt;CacheInterface CachedWidget&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Constructor injection. Best for mandatory dependencies.&lt;/li&gt;
&lt;li&gt;Method injection. Best for optional dependencies.&lt;/li&gt;
&lt;li&gt;Property injection. Better to be avoided in PHP except maybe data transfer objects.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Using the container di&lt;/strong&gt;: Usage of the &lt;a href="https://github.com/yiisoft/di" rel="noopener noreferrer"&gt;container di&lt;/a&gt; is fairly simple: You first initialize it with an array of &lt;em&gt;definitions&lt;/em&gt;. The array keys are usually interface names. It will then use these definitions to create an object whenever that type is requested. This happens for example when fetching a type directly from the container somewhere in the application. But objects are also created implicitly if a definition has a dependency to another definition.&lt;/p&gt;

&lt;p&gt;Usually a single container is used for the whole application. It is often configured either in the entry script such as or a configuration file:&lt;code&gt;index.php&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Di\Container&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Di\ContainerConfig&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ContainerConfig&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;withDefinitions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$definitions&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/**
 * Definitions.
 * Very important all the values, parameters must go between square brackets.
 */&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nc"&gt;EngineInterface&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;EngineMarkOne&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'full_definition'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'class'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;EngineMarkOne&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'__construct()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="s1"&gt;'$propertyName'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'value'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'setX()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="s1"&gt;'closure'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;SomeFactory&lt;/span&gt; &lt;span class="nv"&gt;$factory&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$factory&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'args'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="s1"&gt;'static_call_preferred'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;MyFactory&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'args'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="s1"&gt;'static_call_supported'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;MyFactory&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'create'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="s1"&gt;'object'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As seen above an object can be defined in several ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the simple case an interface definition maps an id to a particular class.&lt;/li&gt;
&lt;li&gt;A full definition describes how to instantiate a class in more detail:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;class&lt;/code&gt; contains the name of the class to be instantiated.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;__construct()&lt;/code&gt; holds an array of constructor arguments.&lt;/li&gt;
&lt;li&gt;The rest of the config are property values (prefixed with ) and method calls, postfixed with . They are set/called in the order they appear in the array.&lt;code&gt;$()&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Closures are useful if instantiation is tricky and can better be described in code. When using these, arguments are auto-wired by type. could be used to get current container instance. &lt;code&gt;ContainerInterface&lt;/code&gt;
&lt;/li&gt;

&lt;li&gt;If it is even more complicated, it is a good idea to move such code into a factory and reference it as a static call.&lt;/li&gt;

&lt;li&gt;While it is usually not a good idea, you can also set an already instantiated object into the container.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/yiisoft/definitions" rel="noopener noreferrer"&gt;Definitions&lt;/a&gt;  is describing a way to create and configure a service, an object or return any other value. It must implement  &lt;code&gt;Yiisoft\Definitions\Contract\DefinitionInterface&lt;/code&gt; that has a single method &lt;code&gt;resolve(ContainerInterface $container)&lt;/code&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;References are typically stored in the container or a factory and are resolved into object at the moment of obtaining a service instance or creating an object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array definition&lt;/strong&gt; allows describing a service or an object declaratively:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;\Yiisoft\Definitions\ArrayDefinition&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$definition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ArrayDefinition&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;fromConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'class'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;MyServiceInterface&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'__construct()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; 
        &lt;span class="s1"&gt;'$propertyName'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'value'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'setName()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'Alex'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$definition&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$container&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;class&lt;/code&gt;: contains the name of the class to be instantiated.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;__construct()&lt;/code&gt;: holds an array of constructor arguments.&lt;/p&gt;

&lt;p&gt;The rest of the config are property values (prefixed with &lt;code&gt;$&lt;/code&gt;) and method calls, postfixed with &lt;code&gt;()&lt;/code&gt;. They are set/called in the order they appear in the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Callable definition&lt;/strong&gt; builds an object by executing a callable injecting dependencies based on types used in its signature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;\Yiisoft\Definitions\CallableDefinition&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$definition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CallableDefinition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;SomeFactory&lt;/span&gt; &lt;span class="nv"&gt;$factory&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$factory&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'args'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$definition&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$container&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// or &lt;/span&gt;

&lt;span class="nv"&gt;$definition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CallableDefinition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;MyFactory&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'args'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$definition&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$container&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// or&lt;/span&gt;

&lt;span class="nv"&gt;$definition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CallableDefinition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;MyFactory&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'create'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$definition&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$container&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above we use a closure, a static call and a static method passed as array-callable. In each case we determine and pass dependencies based on the types of arguments in the callable signature.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameter definition&lt;/strong&gt; resolves an object based on information from &lt;code&gt;ReflectionParameter&lt;/code&gt;&lt;br&gt;
instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;\Yiisoft\Definitions\ParameterDefinition&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$definition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ParameterDefinition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$reflectionParameter&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$definition&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$container&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Value&lt;/strong&gt; &lt;strong&gt;definition&lt;/strong&gt; resolves value passed as is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;\Yiisoft\Definitions\ValueDefinition&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$definition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ValueDefinition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'int'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$definition&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$container&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 42&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt; point to other definitions so when defining a definition you can use other definitions as its dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nc"&gt;InterfaceA&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;ConcreteA&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'alternativeForA'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;ConcreteB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="nc"&gt;MyService&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'__construct()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="nc"&gt;Reference&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'alternativeForA'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Optional reference returns &lt;code&gt;null&lt;/code&gt; when there's no corresponding definition in container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nc"&gt;MyService&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'__construct()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="c1"&gt;// If container doesn't have definition for `EventDispatcherInterface`&lt;/span&gt;
            &lt;span class="c1"&gt;// reference returns `null` when resolving dependencies&lt;/span&gt;
            &lt;span class="nc"&gt;Reference&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;EventDispatcherInterface&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
        &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Dynamic&lt;/strong&gt; reference  defines a dependency to a service not defined in the container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;
   &lt;span class="nc"&gt;MyService&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
       &lt;span class="s1"&gt;'__construct()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
           &lt;span class="nc"&gt;DynamicReference&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                         &lt;span class="p"&gt;[&lt;/span&gt;
                  &lt;span class="s1"&gt;'class'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;SomeClass&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                  &lt;span class="s1"&gt;'$someProp'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;
               &lt;span class="p"&gt;],&lt;/span&gt;
           &lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="p"&gt;]&lt;/span&gt;
   &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order to pass an array of IDs as references to a property or an argument,  &lt;code&gt;Yiisoft\Definitions\ReferencesArray&lt;/code&gt; or  &lt;code&gt;Yiisoft\Definitions\DynamicReferencesArray&lt;/code&gt;&lt;br&gt;
 could be used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
   &lt;span class="s1"&gt;'yiisoft/data-response'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
       &lt;span class="s1"&gt;'contentFormatters'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
           &lt;span class="s1"&gt;'text/html'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;HtmlDataResponseFormatter&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="s1"&gt;'application/xml'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;XmlDataResponseFormatter&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="s1"&gt;'application/json'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;JsonDataResponseFormatter&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="p"&gt;],&lt;/span&gt;
   &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;contentnegotiator&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;

&lt;span class="nc"&gt;ContentNegotiator&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'__construct()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'contentFormatters'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;ReferencesArray&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
             &lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'yiisoft/data-response'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'contentFormatters'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After explaining the functioning, it seems that the configurations are complex, but they are not, the &lt;a href="https://github.com/yiisoft/di" rel="noopener noreferrer"&gt;container di&lt;/a&gt;, does all the work for you, applying the best practices, you just have to learn the syntax of the container and the references, and everything will be simple, now  let's see the actual example in our &lt;a href="https://github.com/yiisoft/app" rel="noopener noreferrer"&gt;app template&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;File: config/common/logger.php

&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Psr\Log\LoggerInterface&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Definitions\ReferencesArray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Log\Logger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Log\Target\File\FileTarget&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cd"&gt;/** @var array $params */&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nc"&gt;LoggerInterface&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'class'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'__construct()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'targets'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;ReferencesArray&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                            &lt;span class="p"&gt;[&lt;/span&gt;
                   &lt;span class="nc"&gt;FileTarget&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;File: config/common/translator.php

&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Aliases\Aliases&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Translator\CategorySource&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Translator\IntlMessageFormatter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Translator\Message\Php\MessageSource&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cd"&gt;/** @var array $params */&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;// Configure application CategorySource&lt;/span&gt;
    &lt;span class="s1"&gt;'translation.app'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'definition'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Aliases&lt;/span&gt; &lt;span class="nv"&gt;$aliases&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CategorySource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'yiisoft/translator'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'defaultCategory'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MessageSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$aliases&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'@messages'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;IntlMessageFormatter&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="s1"&gt;'tags'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'translation.categorySource'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;file: config/web/application.php

&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Handler\NotFoundHandler&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Definitions\DynamicReference&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Definitions\Reference&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Injector\Injector&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cd"&gt;/** @var array $params */&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nc"&gt;\Yiisoft\Yii\Http\Application&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'__construct()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'dispatcher'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;DynamicReference&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Injector&lt;/span&gt; &lt;span class="nv"&gt;$injector&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$injector&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MiddlewareDispatcher&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;withMiddlewares&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'middlewares'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
            &lt;span class="p"&gt;}),&lt;/span&gt;
            &lt;span class="s1"&gt;'fallbackHandler'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Reference&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NotFoundHandler&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="nc"&gt;\Yiisoft\Yii\Middleware\Locale&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'__construct()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'locales'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'locale'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'locales'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="s1"&gt;'ignoredRequests'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'locale'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'ignoredRequests'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="s1"&gt;'withEnableSaveLocale()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we understand how to do any configuration of any &lt;a href="https://www.yiiframework.com/" rel="noopener noreferrer"&gt;YiiFramework&lt;/a&gt; package or external, it is not necessary to have a single long and complex configuration file, we can organize it according to the group of configurations and &lt;a href="https://github.com/yiisoft/config" rel="noopener noreferrer"&gt;Yii config&lt;/a&gt; will do the work for you, as well as the container it applies the definitions for you, with the automatic wiring facility in controllers, which makes it easy to access any container dependency without the need to use &lt;strong&gt;static access&lt;/strong&gt; to it, or depend on the &lt;strong&gt;container itself&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In our next post we will talk about the factory, and how to get all the &lt;strong&gt;power, flexibility and simplicity&lt;/strong&gt; of &lt;a href="https://www.yiiframework.com/" rel="noopener noreferrer"&gt;YiiFramework&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Wilmer Arámbula.&lt;br&gt;&lt;br&gt;
&lt;a href="https://www.yiiframework.com/team" rel="noopener noreferrer"&gt;Team Developer YiiFramework&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/Terabytesoftw" rel="noopener noreferrer"&gt;Twitter follow&lt;/a&gt;&lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>Creating an application in Yii3 - part 2 the concept of configuration.</title>
      <dc:creator>Wilmer Arambula</dc:creator>
      <pubDate>Thu, 05 Jan 2023 19:45:50 +0000</pubDate>
      <link>https://forem.com/terabytesoftw/creating-an-application-in-yii3-366e</link>
      <guid>https://forem.com/terabytesoftw/creating-an-application-in-yii3-366e</guid>
      <description>&lt;p&gt;In this second post, we will cover the configuration, certainly one of the main parts when creating an app, according to &lt;strong&gt;Wikipedia&lt;/strong&gt; the configuration is defined “as a data set that determines the value of some variables of a computer program or an operating system. These options are usually loaded during the start of the program and in some cases it is necessary to restart it in order to see the changes”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.yiiframework.com/"&gt;YiiFramework&lt;/a&gt; it has a powerful tool to make configurations easier, when configuring the container di, we present &lt;a href="https://github.com/yiisoft/config"&gt;Yii Config&lt;/a&gt;, your solution for building configurations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/yiisoft/config"&gt;Yii config&lt;/a&gt; is a composer plugin provides assembling of configurations distributed with composer packages. It allows putting configuration needed to use a package right inside thus implementing a plugin system. The package becomes a plugin holding both the code and its configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The package consist of two parts: &lt;strong&gt;composer plugin&lt;/strong&gt; and &lt;strong&gt;config loader&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;After composer updates its autoload file, and that happens after &lt;code&gt;dump-autoload, require, update or remove&lt;/code&gt;, composer plugin:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scans installed packages for &lt;code&gt;config-plugin&lt;/code&gt; extra option in their &lt;code&gt;composer.json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Writes a merge plan into &lt;code&gt;config/.merge-plan.php&lt;/code&gt;. It includes configuration from each package &lt;code&gt;composer.json&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the application entry point, usually &lt;code&gt;index.php&lt;/code&gt;, we create an instance of config loader and require a configuration we need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Config\Config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Yiisoft\Config\ConfigPaths&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ConfigPaths&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;dirname&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;__DIR__&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="c1"&gt;// defined root path.&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$web&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$config&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'web'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// access config web group.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now once we understand the concept, let’s look at an example of our app template configuration.&lt;/p&gt;

&lt;p&gt;The first thing is to define our configuration in the extra section of &lt;code&gt;composer.json&lt;/code&gt;, here we will tell &lt;a href="https://github.com/yiisoft/config"&gt;Yii Config&lt;/a&gt;, which configuration should collect, let’s see the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"extra"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"config-plugin-options"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"source-directory"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"config"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"config-plugin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"common"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"common/**.php"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"params"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"params.php"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"web"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"$common"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"web/**.php"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"console"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"$common"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"console/*.php"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;source directory:&lt;/strong&gt; We simply define the path where our configuration files will be, it can be any name in our example we will call it &lt;code&gt;config&lt;/code&gt;, and the plugin will automatically look for the &lt;code&gt;config folder&lt;/code&gt; in the &lt;strong&gt;root directory&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;config-plugin:&lt;/strong&gt; In this section we will define our configuration skeleton, let’s see the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\ root directory.
    common\ configuration to be used in all defined groups.
        - application-parameters.php
        - i18n.php
        - logger.php
        - psr17.php
        - router.php
        - translator.php         
    web\ configuration used in the web group.
        - application.php
    console\ configuration** used in the console group.
params.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see in the example above, we have defined the configuration of our packages in files &lt;code&gt;.php&lt;/code&gt;&lt;strong&gt;&lt;em&gt;(it doesn't matter if they are &lt;a href="https://www.yiiframework.com/"&gt;YiiFramework&lt;/a&gt; packages or not)&lt;/em&gt;&lt;/strong&gt;, this allows us to define the configuration of each component in a very simple way to understand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;file: params.php

&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'app'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'charset'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'UTF-8'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'locale'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'en'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;file: application-parameters.php

&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\ApplicationParameters&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cd"&gt;/** @var array $params */&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nc"&gt;ApplicationParameters&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'class'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;ApplicationParameters&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'charset()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'app'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'charset'&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;
        &lt;span class="s1"&gt;'name()'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'app'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are going to understand how the definition works inside the &lt;code&gt;.php&lt;/code&gt; file, the first thing we do is define the class to configure in our &lt;strong&gt;container di&lt;/strong&gt;, in this case &lt;code&gt;ApplicationParameters::class&lt;/code&gt;, the other thing we observe is a comment &lt;code&gt;/** @ var array $params */&lt;/code&gt;, here we can see the magic of &lt;a href="https://github.com/yiisoft/config"&gt;Yii Config&lt;/a&gt;, it automatically allows you to access the parameters defined in the &lt;code&gt;params group&lt;/code&gt;, and thus be able to use them in the configuration.&lt;/p&gt;

&lt;p&gt;Using a language analogy, we can translate the previous configuration to &lt;code&gt;php&lt;/code&gt; in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$applicacionParameters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ApplicacionParameters&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="err"&gt;→&lt;/span&gt;&lt;span class="nf"&gt;charset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'app'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'charset'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="err"&gt;→&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'app'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The syntax would basically be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class/interface =&amp;gt; [
    'class' =&amp;gt; implementation::class,
    // very important all the values, parameters must go between square brackets.
    'property' =&amp;gt; [value]
    'method() =&amp;gt; [parameters],
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we understand the concept in our next post, we will fully describe our configurations, and explain in detail the use of the &lt;a href="https://github.com/yiisoft/di"&gt;&lt;strong&gt;container di&lt;/strong&gt;&lt;/a&gt; and the &lt;strong&gt;&lt;a href="https://github.com/yiisoft/factory"&gt;factory&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Wilmer Arámbula.                                                                                                                         &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.yiiframework.com/team"&gt;Team Developer YiiFramework&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/Terabytesoftw"&gt;Twitter follow&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>yii3</category>
      <category>yiiframework</category>
    </item>
    <item>
      <title>Creating an application in Yii3 - part 1 introduction.</title>
      <dc:creator>Wilmer Arambula</dc:creator>
      <pubDate>Thu, 05 Jan 2023 18:53:22 +0000</pubDate>
      <link>https://forem.com/terabytesoftw/creating-an-application-in-yii3-53d4</link>
      <guid>https://forem.com/terabytesoftw/creating-an-application-in-yii3-53d4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Yii3&lt;/strong&gt; are a set of &lt;strong&gt;agnostic packages&lt;/strong&gt; that facilitate the creation of a &lt;strong&gt;web&lt;/strong&gt; application, &lt;strong&gt;API&lt;/strong&gt; or &lt;strong&gt;console&lt;/strong&gt;. Its strength is to use what we only need, in this way, we will only have dependencies that we will use throughout the development of our project.&lt;/p&gt;

&lt;p&gt;We are now going to give an explanation of the packages that make up a standard application in Yii3:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yii Application Template:&lt;/strong&gt; &lt;a href="https://github.com/yiisoft/app" rel="noopener noreferrer"&gt;Template Yii3&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://github.com/httpsoft/http-message" rel="noopener noreferrer"&gt;HTTP Message&lt;/a&gt;. This package is a lightweight, fast, high-performance and strict implementation of the &lt;a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md" rel="noopener noreferrer"&gt;PSR-7 HTTP Message&lt;/a&gt; and &lt;a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-17-http-factory.md" rel="noopener noreferrer"&gt;PSR-17 HTTP Factories&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/php-fig/container" rel="noopener noreferrer"&gt;Container interface&lt;/a&gt;. This repository holds all interfaces related to &lt;a href="https://www.php-fig.org/psr/psr-11/" rel="noopener noreferrer"&gt;PSR-11 (Container Interface)&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/php-fig/http-message" rel="noopener noreferrer"&gt;PSR Http Message.&lt;/a&gt; This repository holds all interfaces/classes/traits related to &lt;a href="http://www.php-fig.org/psr/psr-7/" rel="noopener noreferrer"&gt;PSR-7&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/php-fig/http-server-handler" rel="noopener noreferrer"&gt;HTTP Server Request Handlers for Middleware.&lt;/a&gt; This repository holds the &lt;code&gt;RequestHandlerInterface&lt;/code&gt; related to &lt;a href="https://www.php-fig.org/psr/psr-15/" rel="noopener noreferrer"&gt;PSR-15 (HTTP Server Request Handlers)&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/symfony/console" rel="noopener noreferrer"&gt;Symfony console component.&lt;/a&gt; The Console component eases the creation of beautiful and testable command line interfaces.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/vlucas/phpdotenv" rel="noopener noreferrer"&gt;PHP dotenv.&lt;/a&gt; Loads environment variables from &lt;code&gt;.env&lt;/code&gt; to &lt;code&gt;getenv(), $_ENV&lt;/code&gt; and &lt;code&gt;$_SERVER&lt;/code&gt;
automagically.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/aliases" rel="noopener noreferrer"&gt;Yii aliases.&lt;/a&gt; The package aim is to store path aliases, i.e. short name representing a long path (a file path, a URL, etc.). Path alias value may have another value as its part. For  example, &lt;code&gt;@vendor&lt;/code&gt; may store path to &lt;code&gt;vendor&lt;/code&gt; directory while &lt;code&gt;@bin&lt;/code&gt; may store &lt;code&gt;@vendor/bin&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/assets" rel="noopener noreferrer"&gt;Yii assets.&lt;/a&gt; The package implements client-side asset (such as CSS and JavaScript) management for PHP. It helps resolve dependencies and get lists of files ready for generating HTML &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;tags.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/cache" rel="noopener noreferrer"&gt;Yii cache.&lt;/a&gt; This library is a wrapper around &lt;a href="https://www.php-fig.org/psr/psr-16/" rel="noopener noreferrer"&gt;PSR-16&lt;/a&gt; compatible caching libraries providing own features. It is used in &lt;a href="https://www.yiiframework.com/" rel="noopener noreferrer"&gt;Yii Framework&lt;/a&gt;  but is usable separately.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/cache-file" rel="noopener noreferrer"&gt;Yii cache-file.&lt;/a&gt; This package implements file-based &lt;a href="https://www.php-fig.org/psr/psr-16/" rel="noopener noreferrer"&gt;PSR-16&lt;/a&gt; cache.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/config" rel="noopener noreferrer"&gt;Yii config.&lt;/a&gt; This &lt;a href="https://getcomposer.org/" rel="noopener noreferrer"&gt;Composer&lt;/a&gt; plugin provides assembling of configurations distributed with composer packages. It allows putting configuration needed to use a package right inside thus implementing a plugin system. The package becomes a plugin holding both the code and its configuration.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/csrf" rel="noopener noreferrer"&gt;Yii csrf.&lt;/a&gt; The package provides &lt;a href="https://www.php-fig.org/psr/psr-15/" rel="noopener noreferrer"&gt;PSR-15&lt;/a&gt; middleware for CSRF protection.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/data-response" rel="noopener noreferrer"&gt;Yii data-response.&lt;/a&gt; The package allows responding with data that is automatically converted into &lt;a href="https://www.php-fig.org/psr/psr-7/" rel="noopener noreferrer"&gt;PSR-7&lt;/a&gt; response.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/definitions" rel="noopener noreferrer"&gt;Yii definitions.&lt;/a&gt; The package provides syntax constructs describing a way to create and configure a service or an object. It is used by &lt;a href="https://github.com/yiisoft/di" rel="noopener noreferrer"&gt;yiisoft/di&lt;/a&gt; and &lt;a href="https://github.com/yiisoft/factory" rel="noopener noreferrer"&gt;yiisoft/factory&lt;/a&gt; but could be used in other &lt;a href="https://www.php-fig.org/psr/psr-11/" rel="noopener noreferrer"&gt;PSR-11&lt;/a&gt; compatible packages as well.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/di" rel="noopener noreferrer"&gt;Yii di.&lt;/a&gt; &lt;a href="http://www.php-fig.org/psr/psr-11/" rel="noopener noreferrer"&gt;PSR-11&lt;/a&gt; compatible &lt;a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="noopener noreferrer"&gt;dependency injection&lt;/a&gt; container that is able to instantiate and configure classes resolving dependencies.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/error-handler" rel="noopener noreferrer"&gt;Yii error-handler.&lt;/a&gt; The package provides advanced error handling.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/factory" rel="noopener noreferrer"&gt;Yii Factory.&lt;/a&gt; This package provides abstract object factory allowing to create objects by given definition with dependencies resolved by a &lt;a href="https://www.php-fig.org/psr/psr-11/" rel="noopener noreferrer"&gt;PSR-11&lt;/a&gt; container.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/files" rel="noopener noreferrer"&gt;Yii files.&lt;/a&gt; The package provides useful methods to manage files and directories.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/html" rel="noopener noreferrer"&gt;Yii html.&lt;/a&gt; The package provides various tools to help with dynamic server-side generation of HTML.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/http" rel="noopener noreferrer"&gt;Yii http.&lt;/a&gt; Constants for HTTP protocol headers, methods and statuses. All along with short descriptions and RFC links. PSR-7, PSR-17 PhpStorm meta for HTTP protocol headers, methods and statuses.&lt;code&gt;ContentDispositionHeader&lt;/code&gt; that has static methods to generate &lt;code&gt;Content-Disposition&lt;/code&gt; header name and value. &lt;code&gt;HeaderValueHelper&lt;/code&gt; that has static methods to parse the header value parameters.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/i18n" rel="noopener noreferrer"&gt;Yii internationalization library.&lt;/a&gt; The package provides common internationalization utilities: &lt;code&gt;Locale&lt;/code&gt; stores locale information created from BCP 47 formatted string. Can parse locale string, modify locale parts, form locale string from parts, and derive fallback locale.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/log" rel="noopener noreferrer"&gt;Yii log.&lt;/a&gt; This package provides &lt;a href="https://www.php-fig.org/psr/psr-3/" rel="noopener noreferrer"&gt;PSR-3&lt;/a&gt; compatible logging library. It is used in &lt;a href="http://www.yiiframework.com/" rel="noopener noreferrer"&gt;Yii Framework&lt;/a&gt;
 but is usable separately.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/log-target-file" rel="noopener noreferrer"&gt;Yii log-target-file.&lt;/a&gt; This package provides the File target for the &lt;a href="https://github.com/yiisoft/log" rel="noopener noreferrer"&gt;yiisoft/log&lt;/a&gt;. The target: Records log messages in a file, allows you to configure log files rotation and provides the ability to compress rotated log files.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/router" rel="noopener noreferrer"&gt;Yii router&lt;/a&gt;. The package provides &lt;a href="https://www.php-fig.org/psr/psr-7/" rel="noopener noreferrer"&gt;PSR-7&lt;/a&gt; compatible request routing and a &lt;a href="https://www.php-fig.org/psr/psr-15/" rel="noopener noreferrer"&gt;PSR-15 middleware&lt;/a&gt;
ready to be used in an application. Instead of implementing routing from ground up, the package provides an interface for configuring routes and could be used with an adapter package. Currently, the only adapter available is &lt;a href="https://github.com/yiisoft/router-fastroute" rel="noopener noreferrer"&gt;FastRoute&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/router-fastroute" rel="noopener noreferrer"&gt;Yii router-fastroute.&lt;/a&gt; The package provides FastRoute adapter for &lt;a href="https://github.com/yiisoft/router" rel="noopener noreferrer"&gt;Yii Router&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/translator" rel="noopener noreferrer"&gt;Yii translator.&lt;/a&gt; This package allows translating messages into several languages. It can work with both Yii-based applications and standalone PHP applications.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/translator-message-php" rel="noopener noreferrer"&gt;Yii translator-message-php.&lt;/a&gt; The package provides message storage backend based on PHP arrays to be used with &lt;code&gt;[yiisoft/translator](https://github.com/yiisoft/translator)&lt;/code&gt; package.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/view" rel="noopener noreferrer"&gt;Yii view.&lt;/a&gt; This library provides templates rendering abstraction supporting layout-view-subview hierarchy, custom renderers with PHP-based as default and more. It is used in &lt;a href="https://www.yiiframework.com/" rel="noopener noreferrer"&gt;Yii Framework&lt;/a&gt; but is supposed to be usable separately.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/yii-console" rel="noopener noreferrer"&gt;Yii console.&lt;/a&gt; This Yii Framework package provides a console that could be added to an application.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/yii-debug" rel="noopener noreferrer"&gt;Yii debug.&lt;/a&gt;This extension provides a debugger for &lt;a href="http://www.yiiframework.com/" rel="noopener noreferrer"&gt;Yii framework&lt;/a&gt; applications. When this extension is used, a debugger toolbar will appear at the bottom of every page. The extension also provides a set of standalone pages to display more detailed debug information.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/yii-event" rel="noopener noreferrer"&gt;Yii event.&lt;/a&gt; This package is a configuration wrapper for the &lt;a href="https://github.com/yiisoft/event-dispatcher" rel="noopener noreferrer"&gt;yiisoft/event-dispatcher&lt;/a&gt; package. It is intended to make event listener declaration simpler than you could ever imagine. All you need is to use any &lt;a href="https://www.php-fig.org/psr/psr-11/" rel="noopener noreferrer"&gt;PSR-11&lt;/a&gt; compatible DI container.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/yii-http" rel="noopener noreferrer"&gt;Yii yii-http.&lt;/a&gt; This Yii framework package provides the application class, as well as the events and handlers needed to interact with HTTP. The package is implemented using &lt;a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md" rel="noopener noreferrer"&gt;PSR-7&lt;/a&gt; interfaces.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/yii-middleware" rel="noopener noreferrer"&gt;Yii yii-middleware.&lt;/a&gt; The package provides middleware classes that implement &lt;a href="https://github.com/php-fig/http-server-middleware" rel="noopener noreferrer"&gt;PSR 15&lt;/a&gt;. For more information on how to use middleware in the &lt;a href="http://www.yiiframework.com/" rel="noopener noreferrer"&gt;Yii Framework&lt;/a&gt;, see the &lt;a href="https://github.com/yiisoft/docs/blob/master/guide/en/structure/middleware.md" rel="noopener noreferrer"&gt;Yii middleware guide&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/yii-runner-console" rel="noopener noreferrer"&gt;Yii runner console.&lt;/a&gt; The package contains a bootstrap for running Yii3 console application.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/yii-runner-http" rel="noopener noreferrer"&gt;Yii yii-runner.&lt;/a&gt; The package contains a bootstrap for running Yii3 HTTP application.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yiisoft/yii-view" rel="noopener noreferrer"&gt;Yii yii-view.&lt;/a&gt; The package is an extension of the &lt;a href="https://github.com/yiisoft/view/" rel="noopener noreferrer"&gt;Yii View Rendering Library&lt;/a&gt;. It adds WEB-specific functionality and compatibility with &lt;a href="https://www.php-fig.org/psr/psr-7/" rel="noopener noreferrer"&gt;PSR-7&lt;/a&gt; interfaces.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As we can see this composed of 36 packages, we can also see, that we can integrate third-party packages, without major problem, we just need to configure it in the container di.&lt;/p&gt;

&lt;p&gt;In the next post, we will talk about how to create the application using &lt;strong&gt;yiisoft/app&lt;/strong&gt;, in addition to explaining its configuration in detail.&lt;/p&gt;

&lt;p&gt;Wilmer Arámbula.&lt;br&gt;&lt;br&gt;
&lt;a href="https://www.yiiframework.com/team" rel="noopener noreferrer"&gt;Team Developer YiiFramework&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/Terabytesoftw" rel="noopener noreferrer"&gt;Twitter follow&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mentalhealth</category>
    </item>
  </channel>
</rss>
