Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement