title: How can I pass configuration to Database class
body: <p>I have a database class in which i want to pass configuration. I have to keep the "framework" and the Application files separate.
  here is my configuration class
  </p>
  
  <pre><code>&lt;?php namespace Fzaffa\System;
  
  class Config {
  
      private $items = [];
  
      public function get($name)
      {
          list($file, $key) = $this-&gt;parseName($name);
          $this-&gt;includeIfNotCached($file);
          $item = $this-&gt;parseItemToReturn($key, $file);
  
          return $item;
      }
  
      /**
       * @param $file
       */
      private function includeIfNotCached($file)
      {
          if ( ! array_key_exists($file, $this-&gt;items))
          {
              $arr = include __DIR__ . '/App/Config/' . $file . '.php';
              $this-&gt;items[$file] = $arr;
          }
      }
  
      /**
       * @param $name
       * @return array
       */
      private function parseName($name)
      {
          if (strpos($name, '.'))
          {
              list($file, $key) = explode('.', $name);
  
              return [$file, $key];
          }
  
          return [$name, null];
      }
  
      /**
       * @param $key
       * @param $file
       * @return mixed
       */
      private function parseItemToReturn($key, $file)
      {
          if ($key)
          {
              return $this-&gt;items[$file][$key];
          }
          else
          {
              return $this-&gt;items[$file];
          }
      }
  }
  </code></pre>
  
  <p>and here is my Database class
  </p>
  
  <pre><code>&lt;?php namespace Fzaffa\System;
  
  use PDO;
  
  class Database {
  
      private $host = 'localhost';
      private $dbname = 'mycms';
      private $user = 'homestead';
      private $pass = 'secret';
      private $dbh;
      private $error;
      private $statement;
  
      public function __construct()
      {
          $dsn = 'mysql:host=' . $this-&gt;host . ';dbname=' . $this-&gt;dbname . ";charset=utf8";
          $options = [
              PDO::ATTR_PERSISTENT =&gt; true,
              PDO::ATTR_ERRMODE    =&gt; PDO::ERRMODE_EXCEPTION
          ];
  
          try
          {
              $this-&gt;dbh = new PDO($dsn, $this-&gt;user, $this-&gt;pass, $options);
          } catch (PDOException $e)
          {
              $this-&gt;error = $e-&gt;getMessage();
          }
      }
  </code></pre>
  
  <p>I would like to be able to instantiate the configuration object in the index.php (where all bootstrapping and routing happens) like so
      $config = new \Fzaffa\system\Config;
  and then use the config variables inside classes like $class->get('database.username')</p>
  
  <p>The config file being application specific need to stay separate and inside the /App/ folder.</p>
  
  <p>Is there a way I can do it without an IoC container and without having to pass the config object through all the hierarchy to the model (Where I instantiate the \Fzaffa\Sysyem\Database object)?</p>
  
  <p>Thank you in advance.</p>