protected function setUp() { if (!$this->db) { $this->db = \Fobia\DataBase\DbFactory::create('mysql://root@localhost/mysql'); } $this->q = $this->db->createSelectQuery(); }
/** * @covers Fobia\DataBase\Handler\MySQL::getProfiles * @todo Implement testGetProfiles(). */ public function testGetProfilesCreate() { $dbParams = array('dns' => 'mysql://root@localhost/mysql', 'params' => array()); $dbParams['params']['debug'] = true; $dbParams['params']['log_error'] = false; $dbParams['params']['logger'] = new \Psr\Log\NullLogger(); $db = \Fobia\DataBase\DbFactory::create($dbParams); $this->assertInstanceOf("\\Fobia\\DataBase\\Handler\\MySQL", $db); return $db; }
public function testCreate2() { $params = array('host' => 'localhost', 'dbname' => 'mysql', 'driver' => 'mysql', 'user' => 'root', 'pass' => ''); $db = \Fobia\DataBase\DbFactory::create($params); $this->assertInstanceOf('\\Fobia\\DataBase\\Handler\\MySQL', $db); }
/** * @internal */ public function __construct($userSettings = null) { $configDir = '.'; // Пользовательские настройки // -------------------------- if (!is_array($userSettings)) { $userSettings = array('file' => $userSettings); } if ($file = @$userSettings['file']) { unset($userSettings['file']); if (file_exists($file)) { $configDir = dirname($file); $settings = Utils::loadConfig($file); Log::debug("Configuration load: " . realpath($file)); unset($file); $userSettings = array_merge($userSettings, $settings); } } $userSettings = array_merge($this->defaultsSettings, $userSettings); if ($p = $userSettings['templates.path']) { if (substr($p, 0, 1) !== '/') { $userSettings['templates.path'] = SYSPATH . '/' . $p; } } // if (is_array($userSettings['import'])) { // $import = $userSettings['import']; // foreach ($import as $file) { // $file = $configDir . '/' . $file; // $settings = Utils::loadConfig($file); // if ($settings) { // $defaultSettings = array_merge($defaultSettings, $settings); // Log::debug("Configuration import", // array(realpath($file))); // } // } // } parent::__construct((array) $userSettings); $app =& $this; // Если Internet Explorer, то шлем на хуй /* if (preg_match('/(rv:11.0|MSIE)/i', $_SERVER['HTTP_USER_AGENT'])) { $app->log->warning('Bad Browser ', array('HTTP_USER_AGENT'=>$_SERVER['HTTP_USER_AGENT'])); $app->redirect( "http://fobia.github.io/docs/badbrowser.html" ); exit(); } */ // // Автоматическая загрузка секций конфигурации // ---------------------------------------------- $autoload = $this['settings']['app.autoload']; if ($autoload) { $this['settings']['app'] = new \Pimple(); $this['settings']['app']['autoload'] = $autoload; if (is_array($autoload)) { foreach (@$autoload as $cfg => $file) { $this['settings']['app'][$cfg] = function ($c) use($cfg, $file, $configDir) { Log::debug(">> autoload config", array($cfg, $file)); if (!file_exists($configDir . "/{$file}")) { trigger_error("Нет автозагрузочной секции конфигурации '{$cfg}'" . "/{$file}", E_USER_ERROR); return; } return Utils::loadConfig($file); }; } } } unset($autoload, $cfg, $file); // Session // session.gc_maxlifetime = 1440 // ;setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes): // ------------------ $this['session'] = function ($c) { $sid = null; if ($c['settings']['session.cookie'] && @$_COOKIE['SID']) { $sid = $_COOKIE['SID']; session_id($sid); } $session = new \Slim\Session($c['settings']['session.handler']); @$session->start(); if ($c['settings']['session.encrypt'] === true) { $session->decrypt($c['crypt']); } if ($sid === null) { $sid = session_id(); if ($c['settings']['session.cookie']) { @$c->setCookie('SID', $sid, time() + 1440); Log::debug('Session save cookie'); } } Log::debug('Session start', array($sid)); return $session; }; // View // ------------------ $this['view'] = function ($c) { $view = $c['settings']['view']; if ($view instanceof \Slim\Interfaces\ViewInterface !== false) { return $view; } $view = new \Slim\Views\Smarty($c['settings']['templates.path']); $view->parserExtensions = SRC_DIR . '/src/Slim/Views/SmartyPlugins'; $view->parserCompileDirectory = CACHE_DIR . '/templates'; $view->parserCacheDirectory = CACHE_DIR; return $view; }; // Database // ------------------ $this['db'] = function ($c) { $db = \Fobia\DataBase\DbFactory::create($c['settings']['database']); \ezcDbInstance::set($db); return $db; }; // Auth // ------------------ $this['auth'] = function ($c) use($app) { $auth = new \Fobia\Auth\Authentication($app); $auth->authenticate(); return $auth; }; // API // ------------------ // $this['apiHandler'] = function() { // return new \Api\ApiHandler(); // }; // $this['api'] = $this->protect(function($method, $params = null) use ($app) { // $result = $app['apiHandler']->request($method, $params); // return $result; // }); // ------------------ if (!self::$instance[0]) { self::setInstance($this); } }