public static function instance() { if (!isset(self::$instance)) { $class = __CLASS__; self::$instance = new $class(); } return self::$instance; }
private function __construct() { $type = '@DB_TYPE@'; $host = '@DB_HOST@'; $name = '@DB_NAME@'; $user = '******'; $pass = '******'; try { $this->dbh = new PDO("{$type}:host={$host};dbname={$name}", $user, $pass); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (Exception $e) { $ldoc = LittleDropsOfCode::instance(); $ldoc->setErrorPage('db'); } }
<?php $page = LittleDropsOfCode::instance()->getPage(); $tracker = "http://github.com/lcabrini/littledropsofcode/issues"; ?> <h2>404</h2> <p>You are looking for the page <span class="missing"><?php echo $page; ?> </span>, which does not exist.</p> <p>If you got here by clicking a link on the site, there is probably a bug hiding somewhere in the code. Please report it to our issue tracking system at <a href="<?php echo $tracker; ?> "><?php echo $tracker; ?> </a>.</p>
<?php function __autoload($class) { require_once LIBLDOC_PATH . "/classes/{$class}.php"; } Database::instance(); $ldoc = LittleDropsOfCode::instance(); $ldoc->action();
<?php $user = User::instance(); $v = $user->validate($_POST); if ($v['valid']) { $u = User::instance()->add($_POST); ActivityLog::instance()->registration($u); LittleDropsOfCode::instance()->setPage('post-register'); } else { LittleDropsOfCode::instance()->setPage('register'); }
<?php $auth = new Authenticator(); $res = $auth->authenticate($_POST); if ($res['auth']) { Session::instance()->login($_POST['username']); LittleDropsOfCode::instance()->setPage('home'); } else { LittleDropsOfCode::instance()->setPage('login'); }