/**
  * @param string $filePath
  * @throws Exception
  */
 public function __construct($filePath = '')
 {
     if (!file_exists($filePath)) {
         throw new Exception("Config file dont exists {$filePath}");
     }
     parent::__construct(require $filePath);
 }
Beispiel #2
0
 /**
  * @param string $filePath
  * @throws Exception
  */
 public function __construct($filePath = '')
 {
     if (!file_exists($filePath)) {
         throw new Exception("Config file dont exists {$filePath}");
     }
     parent::__construct(json_decode(file_get_contents($filePath), true));
 }
Beispiel #3
0
 /**
  * @param bool|false $reconnect
  * @return mixed
  * @throws Exception
  */
 public static function connect($reconnect = false)
 {
     $hash = md5(static::$connectionName);
     if (!isset(self::$connections[$hash]) || $reconnect === true) {
         if (!static::$config->has('db')) {
             throw new Exception("Invalid configuration object 'root.db.*'");
         }
         if (!static::$config['db']->has('connection')) {
             throw new Exception("Invalid configuration object 'root.db.connection.*'");
         }
         $name = static::$connectionName;
         if (!static::$config['db']['connection']->has($name)) {
             throw new Exception("Invalid configuration object 'root.db.connection.{$name}.*'");
         }
         static::$connections[$hash] = new PdoConnection(static::$config['db']['connection'][$name]);
     }
     return static::$connections[$hash];
 }
Beispiel #4
0
 /**
  * Ini constructor.
  * @param string $filePath
  * @throws Exception
  */
 public function __construct($filePath = '')
 {
     if (!file_exists($filePath)) {
         throw new Exception("Config file dont exists {$filePath}");
     }
     $configArray = parse_ini_file(realpath($filePath), true);
     if (isset($configArray[Config::CONFIG_INI_SECTOR])) {
         $configArray = $this->createConfigArray($configArray);
     }
     parent::__construct($configArray);
 }
Beispiel #5
0
<?php

use Dez\Config\Config;
use Dez\Db\Connection;
error_reporting(E_ALL);
ini_set('display_errors', 'On');
set_exception_handler(function (\Throwable $exception) {
    die('<b>' . get_class($exception) . '</b>: <i>' . $exception->getMessage() . '</b>' . "<pre>{$exception->getFile()}:{$exception->getLine()}</pre>");
});
include_once '../vendor/autoload.php';
$connectionConfig = Config::factory(__DIR__ . '/config.php');
$connectionName = $connectionConfig['db']->get('connection_name', 'development');
$db = new Connection($connectionConfig->path('db.connection')->get($connectionName));
///
$stmt = $db->query('select * from film');
var_dump($stmt->loadArray());
Beispiel #6
0
<?php

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'On');
use Dez\Config\Config;
include_once '../vendor/autoload.php';
$config = new Dez\Config\Adapter\NativeArray('./_config.php');
$configJson = new Dez\Config\Adapter\Json('./_config.json');
$config = Config::factory('./_config.ini')->merge($configJson);
die(var_dump($config->toArray(), $config->toIni(), $config->toJSON(), $config->toPHP()));
Beispiel #7
0
<?php

namespace TestApp;

// composer autoload
use Dez\Config\Config;
use Dez\Mvc\Application\ConfigurableApplication;
use Dez\Mvc\Controller\RuntimeMvcException;
include_once '../vendor/autoload.php';
set_exception_handler(function (\Exception $exception) {
    die(get_class($exception) . ': ' . $exception->getMessage());
});
class TestApp extends ConfigurableApplication
{
    public function initialize()
    {
        return $this;
    }
    public function injection()
    {
        return $this;
    }
}
(new TestApp(Config::factory(__DIR__ . '/config/app.php')))->initialize()->injection()->configure()->run();
Beispiel #8
0
 /**
  * @return \Dez\Config\Adapter\Ini|\Dez\Config\Adapter\Json|\Dez\Config\Adapter\NativeArray|Config
  * @throws \Dez\Config\Exception
  */
 public static function sampleConfiguration()
 {
     $configurationFilePath = realpath(__DIR__ . '/../sample.configuration.php');
     $config = Config::factory($configurationFilePath);
     $config['sample_config_file'] = $configurationFilePath;
     return $config;
 }
Beispiel #9
0
<?php

use Dez\Config\Config;
use Dez\DependencyInjection\Container;
use Dez\Http\Cookies;
use Dez\Http\Request;
use Dez\ORM\Connection as OrmConnection;
use Dez\Session\Adapter\Files;
include_once __DIR__ . '/../vendor/autoload.php';
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$container = Container::instance();
$container->set('request', function () {
    return new Request();
});
$container->set('session', function () {
    return new Files();
});
$container->set('cookies', function () {
    return new Cookies();
});
OrmConnection::init(Config::factory(__DIR__ . '/config/connection.json'), 'dev');