Imdb\Config::__construct PHP Method

__construct() public method

Constructor
public __construct ( string $iniFile = null )
$iniFile string *optional* Path to a config file containing any config overrides
    public function __construct($iniFile = null)
    {
        // A little hack to maintain the old default behaviour of making sure the cache folder is
        // within the imdbphp folder by default ('.' is the directory of the first php file loaded)
        if ($this->cachedir == './cache/') {
            $this->cachedir = dirname(__FILE__) . '/../../cache/';
        }
        if ($iniFile) {
            $ini_files = array($iniFile);
        } else {
            $ini_files = glob(dirname(__FILE__) . '/../../conf/*.ini');
        }
        if (is_array($ini_files)) {
            foreach ($ini_files as $file) {
                $ini = parse_ini_file($file);
                foreach ($ini as $var => $val) {
                    $this->{$var} = $val;
                }
            }
        }
    }

Usage Example

Beispiel #1
1
 /**
  * @param Config $config OPTIONAL override default config
  * @param LoggerInterface $logger OPTIONAL override default logger
  * @param CacheInterface $cache OPTIONAL override default cache
  */
 public function __construct(Config $config = null, LoggerInterface $logger = null, CacheInterface $cache = null)
 {
     parent::__construct();
     if ($config) {
         foreach ($config as $key => $value) {
             $this->{$key} = $value;
         }
     }
     $this->config = $config ?: $this;
     $this->logger = empty($logger) ? new Logger($this->debug) : $logger;
     $this->cache = empty($cache) ? new Cache($this->config, $this->logger) : $cache;
     $this->pages = new Pages($this->config, $this->cache, $this->logger);
     $this->cache->purge();
 }