protected function createConnection($connectionName) { $connections = $this->config->get('connections'); if (empty($connections)) { throw new Exception('connections not defined'); } if (empty($connections[$connectionName])) { throw new Exception(sprintf('connection "%s" not defined', $connectionName)); } $connection = $connections[$connectionName]; foreach ($this->requiredOptions as $requiredOption) { if (!isset($connection[$requiredOption])) { throw new Exception(sprintf('option "%s" for "%s" connection not defined', $requiredOption, $connectionName)); } } $options = !empty($connection['options']) ? $connection['options'] : array(); $pdo = new PDO($connection['dsn'], $connection['username'], $connection['password'], $options); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_CLASS); $pdo->setAttribute(\PDO::ATTR_CASE, \PDO::CASE_NATURAL); $pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true); return $pdo; }
<?php set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__); require 'vendor/autoload.php'; $config = \Yabcms\Config::getInstance(); $config->setConfig(__DIR__ . DIRECTORY_SEPARATOR . 'config.php'); $metadata = \Yabcms\Metadata::getInstance();
protected function __construct() { $this->config = Config::getInstance(); }