Last active
March 10, 2017 06:08
-
-
Save dantaeusb/f31cf680d5207ee72b0fa9ed24b9583d to your computer and use it in GitHub Desktop.
bootstrap-shit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class App | |
{ | |
protected $dbLink; | |
protected $dbConfig = array( | |
'host' => 'localhost', | |
'user' => 'user', | |
'pass' => 'password', | |
'name' => 'mydatabase' | |
); | |
public function getDbAdapter() | |
{ | |
if (is_null($this->dbLink)) { | |
$this->dbLink = new dbAdapter( | |
$this->dbConfig | |
); | |
} | |
return $this->dbLink; | |
} | |
} | |
class dbAdapter | |
{ | |
protected $dbHost = ''; | |
protected $dbUser = ''; | |
protected $dbPass = ''; | |
protected $dbName = ''; | |
protected $link; | |
public function __construct($config = array()) | |
{ | |
$this->dbHost = $config['host']; | |
$this->dbUser = $config['user']; | |
$this->dbPass = $config['pass']; | |
$this->dbName = $config['name']; | |
} | |
public function getLink() | |
{ | |
if (is_null($this->link)) { | |
$this->link = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, $this->dbName); | |
if (mysqli_error($this->link)) { | |
throw new Exception(mysqli_error($this->link)); | |
} | |
if ($this->link) { | |
mysqli_set_charset($this->link, "utf8"); | |
} | |
} | |
return $this->link; | |
} | |
public function runQuery($query) | |
{ | |
return mysqli_query($this->getLink(), $query); | |
} | |
} | |
final class Core | |
{ | |
static private $_app; | |
public static function app() | |
{ | |
if (null === self::$_app) { | |
self::$_app = new App(); | |
} | |
return self::$_app; | |
} | |
} | |
abstract class Model | |
{ | |
protected $dbAdapter; | |
public function __construct() | |
{ | |
$this->dbAdapter = Core::app()->getDbAdapter(); | |
} | |
public function load() | |
{ | |
$this->beforeLoad(); | |
$this->_load(); | |
$this->afterLoad(); | |
return $this; | |
} | |
protected function beforeLoad() | |
{ | |
return $this; | |
} | |
protected function afterLoad() | |
{ | |
return $this; | |
} | |
protected function _load() | |
{ | |
return $this; | |
} | |
} | |
class User | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment