public function testStore() { Repository::store('items', 'item', 'value'); $config = Config::item('item'); $this->assertInternalType('string', $config); $this->assertEquals('value', $config); }
/** * Startup the system. * * @return void */ public static function start() { // Load the application config. Config::file(path('config') . 'app.php'); // Initialize the URI. Uri::initialize(); // Attempt a database connection. Database::initialize(); // Initilize the session. Session::initialize(); // Initialize auth. Auth::initialize(); // Assign class aliases. $aliases = Config::item('aliases'); // Check aliases is a valid array first. if (is_array($aliases)) { foreach ($aliases as $alias => $class) { class_alias($class, $alias); } } }
/** * Connect to the database. * * @return \PDO */ private static function connect() { // Setup connection settings. $driver = Config::item('driver', 'database'); $host = Config::item('host', 'database'); $username = Config::item('username', 'database'); $password = Config::item('password', 'database'); $name = Config::item('name', 'database'); $dsn = sprintf('%s:host=%s;dbname=%s', $driver, $host, $name); $options = [PDO::ATTR_PERSISTENT => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]; // Don't attempt a connection if we have no database username, name // or driver. if ($driver === '' || $username === '' || $name === '') { return null; } // Attempt to connect to the database. try { $connection = new PDO($dsn, $username, $password, $options); } catch (PDOException $error) { throw new Exception($error->getMessage()); } // Return connection if successful. return $connection ?? null; }
/** * Get the password field name. * * @return string. */ public static function passwordField() : string { return Config::item('password', 'auth'); }