├── .gitignore ├── Common.php ├── composer.json └── s ├── App.php ├── Cache.php ├── Config.php ├── Controller.php ├── Db.php ├── Env.php ├── Facade.php ├── Loading.php ├── Request.php ├── Route.php ├── Session.php ├── cache └── File.php ├── db └── Query.php └── facade ├── App.php ├── Cache.php ├── Config.php ├── Controller.php ├── Db.php ├── Env.php ├── Request.php └── Session.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | -------------------------------------------------------------------------------- /Common.php: -------------------------------------------------------------------------------- 1 | =7.1.13" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /s/App.php: -------------------------------------------------------------------------------- 1 | [ 14 | 'expire_time' => 1800, 15 | 'path' => 'runtime/cache', 16 | ], 17 | 'redis' => [ 18 | 'host' => '127.0.0.1', 19 | 'port' => 6379, 20 | 'username' => 'root', 21 | 'password' => 'root', 22 | ] 23 | ]; 24 | 25 | public function __construct() { 26 | $this->config = Config::get('cache') ?: []; 27 | } 28 | 29 | public function dirver($type = 'file', $cofig = []) { 30 | if (!empty($config)) { 31 | $this->config = $config; 32 | } else if (isset($this->defaultConfig[$type])) { 33 | $this->config = $this->defaultConfig[$type]; 34 | } 35 | 36 | $this->config['type'] = $type; 37 | return $this; 38 | } 39 | 40 | public function __call($method, $params) { 41 | $type = isset($this->config['type']) ? $this->config['type'] : ''; 42 | switch ($type) { 43 | case 'file': 44 | $driver = 's\\cache\\File'; 45 | break; 46 | case 'redis': 47 | $driver = 's\\cache\\Redis'; 48 | break; 49 | default: 50 | throw new \Exception('驱动不存在:'.$type); 51 | } 52 | return call_user_func_array([new $driver($this->config), $method], $params); 53 | } 54 | } -------------------------------------------------------------------------------- /s/Config.php: -------------------------------------------------------------------------------- 1 | controllers)) { 23 | if (!is_file($ctrlFile)) { 24 | throw new \Exception('controller not exists:'.$ctrlFile); 25 | return ; 26 | } 27 | 28 | if (!class_exists($class)) { 29 | throw new \Exception('class not exists:'.$class); 30 | return ; 31 | } 32 | 33 | $obj = new ReflectionClass($class); 34 | if (!$obj->hasMethod($action)) { 35 | throw new \Exception('method not exists:'.$action); 36 | return ; 37 | } 38 | 39 | $controller = new $class; 40 | $this->controllers[$class] = $controller; 41 | } 42 | return call_user_func([$this->controllers[$class], $action]); 43 | } 44 | } -------------------------------------------------------------------------------- /s/Db.php: -------------------------------------------------------------------------------- 1 | PDO::CASE_LOWER, 14 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, 15 | PDO::ATTR_ORACLE_NULLS => PDO::NULL_TO_STRING, 16 | PDO::ATTR_PERSISTENT => true 17 | ]; 18 | 19 | public function __construct() {} 20 | 21 | public function connect() 22 | { 23 | $config = Config::get('database'); 24 | $dsn = 'mysql:host='.$config['hostname']; 25 | if (!empty($config['database'])) { 26 | $dsn .= ';dbname='.$db; 27 | } 28 | try { 29 | $this->connection = new PDO($dsn, $config['username'], $config['password'], $this->options); 30 | } catch (\PDOException $e) { 31 | var_export($e->getMessage()); 32 | } 33 | 34 | return new Query($this->connection); 35 | } 36 | 37 | public function __call($method, $params) { 38 | return call_user_func_array([$this->connect(), $method], $params); 39 | } 40 | } -------------------------------------------------------------------------------- /s/Env.php: -------------------------------------------------------------------------------- 1 | __DIR__]); 50 | } 51 | 52 | public static function autoload($class) 53 | { 54 | $file = self::findFile($class); 55 | if ($file && !isset(self::$classMap[$file])) { 56 | include $file; 57 | self::$classMap[$file] = true; 58 | } 59 | } 60 | 61 | public static function findFile($class) 62 | { 63 | $path = strtr($class, '\\', DS).'.php'; 64 | if (isset(self::$prefixLengthsPsr4[$class[0]])) { 65 | foreach (self::$prefixLengthsPsr4[$class[0]] as $k => $v) { 66 | if (0 === strpos($class, $k)) { 67 | foreach (self::$prefixDirsPsr4[$k] as $dir) { 68 | if (is_file($file = $dir . DS . substr($path, $v))) { 69 | return $file; 70 | } 71 | } 72 | } 73 | } 74 | } elseif (is_file($file = ROOT.$path)) { 75 | return $file; 76 | } 77 | return false; 78 | } 79 | 80 | public static function addNamespace($namespace) 81 | { 82 | if (is_array($namespace)) { 83 | foreach ($namespace as $k => $v) { 84 | self::addPsr4($k.'\\', rtrim($v, DS)); 85 | } 86 | } 87 | } 88 | 89 | public static function addPsr4($namespace, $path) 90 | { 91 | if (!isset(self::$prefixDirsPsr4[$namespace])) { 92 | $length = strlen($namespace); 93 | if ('\\' !== $namespace[$length - 1]) { 94 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 95 | } 96 | 97 | self::$prefixDirsPsr4[$namespace] = (array)$path; 98 | self::$prefixLengthsPsr4[$namespace[0]][$namespace] = $length; 99 | } 100 | } 101 | } -------------------------------------------------------------------------------- /s/Request.php: -------------------------------------------------------------------------------- 1 | param($key, 'get'); 69 | } 70 | 71 | public function post($key = null) 72 | { 73 | return $this->param($key, 'post'); 74 | } 75 | 76 | public function __call($method, $params) { 77 | switch ($method) { 78 | case 'module': 79 | $class = 's\Route'; 80 | break; 81 | case 'controller': 82 | $class = 's\Route'; 83 | break; 84 | case 'action': 85 | $class = 's\Route'; 86 | break; 87 | default: 88 | throw new \Exception('call to undefined function: '.$method); 89 | return ; 90 | } 91 | return call_user_func_array([new $class, $method], $params); 92 | } 93 | } -------------------------------------------------------------------------------- /s/Route.php: -------------------------------------------------------------------------------- 1 | parse(); 15 | } 16 | 17 | private function parse() 18 | { 19 | $path = Env::get('route'); 20 | if (is_dir($path)) { 21 | $files = $this->scanFile($path) ?: []; 22 | $filesNum = count($files); 23 | list($i, $routes) = [0, []]; 24 | while ($i < $filesNum) { 25 | if ( is_file($files[$i]) ) { 26 | $includeRes = include $files[$i]; 27 | if (is_array($includeRes)) { 28 | $routes += $includeRes; 29 | } 30 | } 31 | $i++; 32 | } 33 | 34 | $requrl = ltrim(ltrim($_SERVER['REQUEST_URI'], '/'), 'index.php/') ?: 'index'; 35 | if (isset($requrl) && isset($routes[$requrl])) { 36 | $route = explode('/', $routes[$requrl]); 37 | if (count($route) < 3) { 38 | throw new \Exception('路由表达式错误:'.$routes[$requrl].' 路由加载失败,未找到匹配的控制器方法'); 39 | } 40 | $this->module = $route[0]; 41 | $this->ctrl = ucfirst($route[1]); 42 | $this->action = $route[2]; 43 | } else { 44 | throw new \Exception('路由表达式错误:'.$requrl.' 未找到匹配的路由'); 45 | } 46 | } else { 47 | throw new \Exception('路由文件丢失'); 48 | } 49 | } 50 | 51 | private function scanFile($path) 52 | { 53 | global $res; 54 | $files = scandir($path); 55 | foreach ($files as $file) { 56 | if ($file != '.' && $file != '..') { 57 | if (is_dir($path . '/' . $file)) { 58 | $this->scanFile($path . '/' . $file); 59 | } else { 60 | $res[] = $path.'/'.$file; 61 | } 62 | } 63 | } 64 | return $res; 65 | } 66 | 67 | public function module() 68 | { 69 | return $this->module; 70 | } 71 | 72 | public function controller() 73 | { 74 | return $this->ctrl; 75 | } 76 | 77 | public function action() 78 | { 79 | return $this->action; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /s/Session.php: -------------------------------------------------------------------------------- 1 | config = Config::get('session'); 21 | } 22 | 23 | public function init() 24 | { 25 | $config = $this->config; 26 | $isStart = false; 27 | 28 | if (!empty($config['auto_start']) && session_status() != PHP_SESSION_ACTIVE) { 29 | // 开始跨页传递session 使session不依赖于cookie 30 | ini_set('session.use_trans_sid', 1); 31 | 32 | // 自动启动session 33 | ini_set('session.auto_start', 0); 34 | $isStart = true; 35 | } 36 | 37 | // SESSION过期时间 38 | if (isset($config['expire_time'])) { 39 | ini_set('session.gc_maxlifetime', $config['expire_time']); 40 | ini_set('session.cookie_lifetime', $config['expire_time']); 41 | } 42 | 43 | if ($isStart) { 44 | session_start(); 45 | } else { 46 | $this->init = false; 47 | } 48 | return $this; 49 | } 50 | 51 | /** 52 | * 启动session 53 | */ 54 | public function boot() 55 | { 56 | if (is_null($this->init)) { 57 | $this->init(); 58 | } 59 | 60 | if ($this->init === false) { 61 | if (session_status() != PHP_SESSION_ACTIVE) { 62 | session_start(); 63 | } 64 | $this->init = true; 65 | } 66 | } 67 | 68 | public function set($key, $val) 69 | { 70 | if (empty($this->init)) { 71 | $this->boot(); 72 | } 73 | 74 | if (strpos($key, '.')) { 75 | list($key1, $key2) = explode('.', $key); 76 | $_SESSION[$key1][$key2] = $val; 77 | } else { 78 | $_SESSION[$key] = $val; 79 | } 80 | } 81 | 82 | public function get($key = '') 83 | { 84 | if (empty($this->init)) { 85 | $this->boot(); 86 | } 87 | 88 | if (strpos($key, '.')) { 89 | list($key1, $key2) = explode('.', $key); 90 | $val = isset($_SESSION[$key1][$key2]) ? $_SESSION[$key1][$key2] : null; 91 | } else { 92 | $val = isset($_SESSION[$key]) ? $_SESSION[$key] : null; 93 | } 94 | return $val; 95 | } 96 | 97 | public function delete($key = '') 98 | { 99 | if (empty($this->init)) { 100 | $this->boot(); 101 | } 102 | 103 | if (strpos($key, '.')) { 104 | list($key1, $key2) = explode('.', $key); 105 | unset($_SESSION[$key1][$key2]); 106 | } else { 107 | unset($_SESSION[$key]); 108 | } 109 | return $val; 110 | } 111 | } -------------------------------------------------------------------------------- /s/cache/File.php: -------------------------------------------------------------------------------- 1 | config = $config; 16 | $this->init(); 17 | } 18 | 19 | private function init() 20 | { 21 | if ($this->config['path'] != '') { 22 | $path = $this->config['path']; 23 | } else { 24 | $path = 'runtime/cache'; 25 | } 26 | $cachePath = Env::get('root').$path; 27 | $this->cachePath = $cachePath; 28 | !is_dir($cachePath) && mkdir($cachePath, 0755, true); 29 | } 30 | 31 | private function getFile($key) 32 | { 33 | $tag = $this->getTag($key); 34 | $filePath = $this->cachePath.'/'.$tag.'.php'; 35 | return $filePath; 36 | } 37 | 38 | private function getTag($key) 39 | { 40 | return md5($key); 41 | } 42 | 43 | public function set($key = '', $val, $exp = null) 44 | { 45 | $file = $this->getFile($key); 46 | if (is_null($exp)) { 47 | $exp = $this->config['expire_time'] ?: 1800; 48 | } 49 | $data = [serialize($val), time() + $exp]; 50 | $res = file_put_contents($file, $data); 51 | if ($res) { 52 | clearstatcache(); 53 | return true; 54 | } else { 55 | return false; 56 | } 57 | } 58 | 59 | public function get($key = '') 60 | { 61 | $file = $this->getFile($key); 62 | if (!is_file($file)) { 63 | return false; 64 | } 65 | 66 | $res = file_get_contents($file); 67 | if ($res) { 68 | $timestamp = (int)substr($res, strrpos($res, '}')+1); 69 | if (time() > $timestamp) { 70 | $this->unlink($file); 71 | return false; 72 | } 73 | $data = unserialize($res); 74 | return $data; 75 | } else { 76 | return false; 77 | } 78 | } 79 | 80 | public function clear($key) 81 | { 82 | $file = $this->getFile($key); 83 | $this->unlink($file); 84 | if (!is_file($file)) { 85 | return true; 86 | } else { 87 | return false; 88 | } 89 | } 90 | 91 | private function unlink($file) 92 | { 93 | is_file($file) && unlink($file); 94 | } 95 | } -------------------------------------------------------------------------------- /s/db/Query.php: -------------------------------------------------------------------------------- 1 | PDO::FETCH_ASSOC, 45 | 'object' => PDO::FETCH_CLASS 46 | ]; 47 | 48 | public function __construct($connection = null) { 49 | if (!is_null($connection)) { 50 | $this->connection = $connection; 51 | } else { 52 | $this->connection = Db::connect(); 53 | } 54 | } 55 | 56 | /** 57 | * query 原生sql语句查询 58 | * @param string $sql sql语句 59 | * @param string $res 结果集返回数据格式 60 | * @return 结果集或产生的sql语句 61 | */ 62 | public function query($sql = '', $res = 'array') 63 | { 64 | $stmt = $this->connection->query($sql); 65 | return $stmt->fetchAll($this->resultSet[$res]); 66 | } 67 | 68 | /** 69 | * find 单条数据查询 70 | * @param string $res 结果集返回数据格式 71 | * @return 结果集或产生的sql语句 72 | */ 73 | public function find($res = 'array') 74 | { 75 | $this->praseWhere(); 76 | $this->praseSql(); 77 | $stmt = $this->connection->query($this->selectSql); 78 | if (!$this->viewSql) { 79 | return $stmt->fetch($this->resultSet[$res]); 80 | } 81 | return $stmt->queryString.' limit 1'; 82 | } 83 | 84 | /** 85 | * select 数据查询 86 | * @param string $res 结果集返回数据格式 87 | * @return 结果集或产生的sql语句 88 | */ 89 | public function select($res = 'array') 90 | { 91 | $this->praseWhere(); 92 | $this->praseSql(); 93 | $stmt = $this->connection->query($this->selectSql); 94 | if (!$this->viewSql) { 95 | return $stmt->fetchAll($this->resultSet[$res]); 96 | } 97 | return $stmt->queryString; 98 | } 99 | 100 | /** 101 | * insert 单条数据插入 102 | * @param array $data 要插入的数据 103 | * @param bool $getLastId 最后插入ID 104 | * @return 结果、最后插入ID或产生的sql语句 105 | */ 106 | public function insert($data = [], $getLastId = false) 107 | { 108 | $this->data($data, 'insert'); 109 | $this->praseSql('insert'); 110 | $stmt = $this->connection->prepare($this->insertSql); 111 | if (!$this->viewSql) { 112 | $res = $stmt->execute(); 113 | if ($res && $getLastId) { 114 | return $this->connection->lastInsertId(); 115 | } else { 116 | return $res; 117 | } 118 | } 119 | return $stmt->queryString; 120 | } 121 | 122 | /** 123 | * insertAll 批量插入 124 | * @param array $data 要插入的数据 125 | * @return 结果或产生的sql语句 126 | */ 127 | public function insertAll($data = []) 128 | { 129 | $this->data($data, 'insertAll'); 130 | $this->praseSql('insert'); 131 | $stmt = $this->connection->prepare($this->insertSql); 132 | if (!$this->viewSql) { 133 | return $stmt->execute(); 134 | } 135 | return $stmt->queryString; 136 | } 137 | 138 | /** 139 | * update 修改写入 140 | * @param array $data 要写入的数据 141 | * @return 结果或产生的sql语句 142 | */ 143 | public function update($data = []) 144 | { 145 | $this->data($data, 'update'); 146 | $this->praseWhere(); 147 | $this->praseSql('update'); 148 | $stmt = $this->connection->prepare($this->updateSql); 149 | if (!$this->viewSql) { 150 | return $stmt->execute(); 151 | } 152 | return $stmt->queryString; 153 | } 154 | 155 | /** 156 | * delete 删除 157 | * @return 结果或产生的sql语句 158 | */ 159 | public function delete() 160 | { 161 | $this->praseWhere(); 162 | $this->praseSql('delete'); 163 | $stmt = $this->connection->prepare($this->deleteSql); 164 | if (!$this->viewSql) { 165 | return $stmt->execute(); 166 | } 167 | return $stmt->queryString; 168 | } 169 | 170 | /** 171 | * 指定当前操作的数据表 172 | * @param string $table 表名 173 | */ 174 | public function table($table = '') 175 | { 176 | $this->table = $table; 177 | return $this; 178 | } 179 | 180 | /** 181 | * 指定当前操作的数据表字段 182 | * @param string $field 字段 183 | */ 184 | public function field($field = '*') 185 | { 186 | $this->field = $field ?? '*'; 187 | return $this; 188 | } 189 | 190 | /** 191 | * 关联查询 192 | * @param string $join 关联表 193 | * @param string $condition 关联条件 194 | * @param string $type 关联方式 195 | */ 196 | public function join($join, $condition, $type = 'left') 197 | { 198 | $this->join = ' '.$type.' join '.$join.' on '.$condition; 199 | return $this; 200 | } 201 | 202 | /** 203 | * @param string|array $key [只传入key时 是字符串或数组条件 传入另外两个参数时 是条件的字段] 204 | * @param string $operator [逻辑运算符] 205 | * @param string|float|int|bool $val [值] 206 | */ 207 | public function where($key = null, $operator = null, $val = null) 208 | { 209 | if (is_null($operator)) { 210 | switch (is_array($key)) { 211 | case true: 212 | foreach ($key as $v) { 213 | if (is_string($v[2])) { 214 | $this->where .= ' and '.$v[0].' '.$v[1].' "'.$v[2].'"'; 215 | } else { 216 | $this->where .= ' and '.$v[0].' '.$v[1].' '.$v[2]; 217 | } 218 | } 219 | break; 220 | case false: 221 | $this->where .= ' and '.$key; 222 | break; 223 | } 224 | } else { 225 | if (is_string($val)) { 226 | $this->where .= ' and '.$key.' '.$operator.' "'.$val.'"'; 227 | } else { 228 | $this->where .= ' and '.$key.' '.$operator.' '.$val; 229 | } 230 | } 231 | return $this; 232 | } 233 | 234 | /** 235 | * @param string|array $key [只传入key时 是字符串或数组条件 传入另外两个参数时 是条件的字段] 236 | * @param string $operator [逻辑运算符] 237 | * @param string|float|int|bool $val [值] 238 | */ 239 | public function whereOr($key, $operator = null, $val = null) 240 | { 241 | if (is_null($operator)) { 242 | switch (is_array($key)) { 243 | case true: 244 | foreach ($key as $v) { 245 | if (is_string($v[2])) { 246 | $this->where .= ' or '.$v[0].' '.$v[1].' "'.$v[2].'"'; 247 | } else { 248 | $this->where .= ' or '.$v[0].' '.$v[1].' '.$v[2]; 249 | } 250 | } 251 | break; 252 | case false: 253 | $this->where .= ' or '.$key; 254 | break; 255 | } 256 | } else { 257 | if (is_string($val)) { 258 | $this->where .= ' or '.$key.' '.$operator.' "'.$val.'"'; 259 | } else { 260 | $this->where .= ' or '.$key.' '.$operator.' '.$val; 261 | } 262 | } 263 | return $this; 264 | } 265 | 266 | /** 267 | * 分组条件 268 | * @param string $group 分组条件 269 | */ 270 | public function group($group = null) 271 | { 272 | if (!is_null($group)) { 273 | $this->group = 'group by '.$group; 274 | } 275 | return $this; 276 | } 277 | 278 | /** 279 | * 排序条件 280 | * @param string $key 排序字段或条件 281 | * @param string $pos 正序或倒序 282 | */ 283 | public function order($key = null, $pos = null) 284 | { 285 | if (!is_null($key)) { 286 | if (is_null($pos)) { 287 | $this->order = ' order by '.$key; 288 | } else { 289 | $this->order = ' order by '.$key.' '.$pos; 290 | } 291 | } 292 | return $this; 293 | } 294 | 295 | /** 296 | * 指定条数查询 297 | * @param int|string $numStart 开始条数或条数条件 298 | * @param int $num 查询条数 299 | */ 300 | public function limit($numStart = 0, $num = null) 301 | { 302 | if (is_null($num)) { 303 | $this->limit = ' limit '.$numStart; 304 | } else { 305 | $this->limit = ' limit '.$numStart.','.$num; 306 | } 307 | return $this; 308 | } 309 | 310 | /** 311 | * 分页方法 312 | * @param int $page 页码 313 | * @param int $limit 每页查询条数 314 | */ 315 | public function page($page = 1, $limit = 10) 316 | { 317 | $start = ($page - 1) * $limit; 318 | $this->limit = ' limit '.$start.','.$limit; 319 | return $this; 320 | } 321 | 322 | /** 323 | * 分组后查询条件 324 | * @param string|array $key [只传入key时 是字符串或数组条件 传入另外两个参数时 是条件的字段] 325 | * @param string $operator [逻辑运算符] 326 | * @param string|float|int|bool $val [值] 327 | */ 328 | public function having($key = null, $operator = null, $val = null) 329 | { 330 | if (is_null($operator)) { 331 | switch (is_array($key)) { 332 | case true: 333 | $having = ''; 334 | foreach ($key as $v) { 335 | $having .= ' and '.$v[0].' '.$v[1].' '.$v[2]; 336 | } 337 | $having = substr($having, strpos($this->where, ' and') + 4); 338 | break; 339 | case false: 340 | $having = $key; 341 | break; 342 | } 343 | } else { 344 | $having = $key.' '.$operator.' '.$val; 345 | } 346 | $this->having = ' having '.$having; 347 | return $this; 348 | } 349 | 350 | /** 351 | * 查看产生的sql语句 352 | */ 353 | public function viewSql() 354 | { 355 | $this->viewSql = true; 356 | return $this; 357 | } 358 | 359 | /** 360 | * 开启事务 361 | */ 362 | public function transaction() 363 | { 364 | return $this->connection->beginTransaction(); 365 | } 366 | 367 | /** 368 | * 提交事务 369 | */ 370 | public function commit() 371 | { 372 | return $this->connection->commit(); 373 | } 374 | 375 | /** 376 | * 事务回滚 377 | */ 378 | public function rollBack() 379 | { 380 | return $this->connection->rollBack(); 381 | } 382 | 383 | /** 384 | * 准备写入的数据 385 | */ 386 | private function data($data, $type = 'insert') 387 | { 388 | switch ($type) { 389 | case 'insert': 390 | $this->field = implode(',', array_keys($data)); 391 | $prepareData = ''; 392 | foreach ($data as $v) { 393 | if (!is_string($v)) { 394 | $prepareData .= $v; 395 | } else { 396 | $prepareData .= '"'.$v.'"'; 397 | } 398 | } 399 | $this->data = '('.$prepareData.')'; 400 | break; 401 | case 'insertAll': 402 | $this->field = implode(',', array_keys($data[0])); 403 | $prepareData = ''; 404 | foreach ($data as $v) { 405 | $prepareData .= '('; 406 | foreach ($v as $val) { 407 | if (!is_string($val)) { 408 | $prepareData .= $val; 409 | } else { 410 | $prepareData .= '"'.$val.'"'; 411 | } 412 | } 413 | $prepareData .= '),'; 414 | } 415 | $this->data = trim($prepareData, ','); 416 | break; 417 | case 'update': 418 | $prepareData = ''; 419 | foreach ($data as $k=>$v) { 420 | $prepareData .= $k.'='.$v.','; 421 | } 422 | $this->data = trim($prepareData, ','); 423 | break; 424 | } 425 | return $this; 426 | } 427 | 428 | /** 429 | * 准备where语句 430 | */ 431 | private function praseWhere() 432 | { 433 | if ($this->where != '') { 434 | $this->where = ' where '.substr($this->where, strpos($this->where, ' and') + 4); 435 | } 436 | return $this; 437 | } 438 | 439 | /** 440 | * 准备sql语句 441 | */ 442 | private function praseSql($type = 'select') 443 | { 444 | switch ($type) { 445 | case 'select': 446 | $this->selectSql = str_replace('{#table#}', $this->table, $this->selectSql); 447 | $this->selectSql = str_replace('{#field#}', $this->field ?: '*', $this->selectSql); 448 | $this->selectSql = str_replace('{#join#}', $this->join, $this->selectSql); 449 | $this->selectSql = str_replace('{#where#}', $this->where, $this->selectSql); 450 | $this->selectSql = str_replace('{#group#}', $this->group, $this->selectSql); 451 | $this->selectSql = str_replace('{#having#}', $this->having, $this->selectSql); 452 | $this->selectSql = str_replace('{#order#}', $this->order, $this->selectSql); 453 | $this->selectSql = str_replace('{#limit#}', $this->limit, $this->selectSql); 454 | break; 455 | case 'insert': 456 | $this->insertSql = str_replace('{#table#}', $this->table, $this->insertSql); 457 | $this->insertSql = str_replace('{#field#}', $this->field, $this->insertSql); 458 | $this->insertSql = str_replace('{#data#}', $this->data, $this->insertSql); 459 | break; 460 | case 'update': 461 | $this->updateSql = str_replace('{#table#}', $this->table, $this->updateSql); 462 | $this->updateSql = str_replace('{#data#}', $this->data, $this->updateSql); 463 | $this->updateSql = str_replace('{#where#}', $this->where, $this->updateSql); 464 | break; 465 | case 'delete': 466 | $this->deleteSql = str_replace('{#table#}', $this->table, $this->deleteSql); 467 | $this->deleteSql = str_replace('{#where#}', $this->where, $this->deleteSql); 468 | break; 469 | } 470 | return $this; 471 | } 472 | } 473 | -------------------------------------------------------------------------------- /s/facade/App.php: -------------------------------------------------------------------------------- 1 |