title: Yii 2 initialize component
body: <p>I want to do what exactly Yii2 do with component in <code>config</code> file 
  in yii <code>config</code>:</p>
  
  <pre><code>'someComponent'=&gt;
  [
      'class' =&gt; '\namespace\to\class',
      'param1' =&gt; 'somevalue',
      'param2' =&gt; 'somevalue',
  ]
  </code></pre>
  
  <p>How I can do that Yii do in my own class, give it an array of component file and then my class create and instance and initialize it? </p>
  
  <p>EDIT:</p>
  
  <p>Config file:</p>
  
  <pre><code>'payment' =&gt; [
              'class' =&gt; 'backend\modules\payment\Bank',
              'components' =&gt; [
                  'service'  =&gt; [
                      'class' =&gt; 'backend\modules\payment\components\Service',
                      'adaptors'=&gt;[
                          'BankMeli' =&gt; [
                              'class'=&gt;'backend\modules\payment\adaptors\BankMeli',
                              'test'=&gt;'1',
                          ]
                      ]
                  ],
              ],
          ],
  </code></pre>
  
  <p>Service Component:</p>
  
  <pre><code>namespace backend\modules\payment\components;
  
  use Yii;
  use yii\base\Component;
  
  class Service extends Component
  {
      public $adaptors = [];
      public function init()
      {
          parent::init();
          $adaptors = new \stdClass();
          foreach($this-&gt;adaptors as $key=&gt;$adaptor)
          {
              $class = $adaptor['class'];
              unset($adaptor['class']);
              $adaptors-&gt;$key = Yii::createObject($class,$adaptor);
          }
          $this-&gt;adaptors = $adaptors;
      }
  
      public function run()
      {
  
      }
  }
  </code></pre>
  
  <p>Inner component (BankMeli) that need to get initialized:</p>
  
  <pre><code>namespace backend\modules\payment\adaptors;
  
  
  use Yii;
  use yii\base\Component;
  
  class BankMeli extends Component
  {
      public $test;
  
      public function __construct($config = [])
      {
          parent::__construct($config);
      }
      public function init(){
          parent::init();
      }
  }
  </code></pre>
  
  <p>var_dump(service->adapters) output : </p>
  
  <pre><code>object(stdClass)[61]
    public 'BankMeli' =&gt; 
      object(backend\modules\payment\adaptors\BankMeli)[72]
        public 'test' =&gt; null
        private '_events' (yii\base\Component) =&gt; 
          array (size=0)
            empty
        private '_behaviors' (yii\base\Component) =&gt; null
  </code></pre>
  
  <hr>
  
  <p>SOLVED:</p>
  
  <p>I passed param array inside another array and problem solved:</p>
  
  <pre><code>$adaptors-&gt;$key = Yii::createObject($class,[$adaptor]);
  </code></pre>