Repository: yeszao/fastphp
Branch: master
Commit: 99886508430c
Files: 26
Total size: 22.3 KB
Directory structure:
gitextract_2es6sksp/
├── .gitignore
├── .htaccess
├── .travis.yml
├── README.md
├── app/
│ ├── controllers/
│ │ └── ItemController.php
│ ├── models/
│ │ └── Item.php
│ └── views/
│ ├── footer.php
│ ├── header.php
│ └── item/
│ ├── add.php
│ ├── delete.php
│ ├── detail.php
│ ├── index.php
│ ├── manage.php
│ └── update.php
├── composer.json
├── config/
│ └── config.php
├── fastphp/
│ ├── Fastphp.php
│ ├── base/
│ │ ├── Controller.php
│ │ ├── Model.php
│ │ └── View.php
│ └── db/
│ ├── Db.php
│ └── Sql.php
├── index.php
├── phpunit.xml
├── static/
│ └── css/
│ └── main.css
└── tests/
└── autoload.php
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.idea
vendor
================================================
FILE: .htaccess
================================================
<IfModule mod_rewrite.c>
# 打开Rerite功能
RewriteEngine On
# 如果请求的是真实存在的文件或目录,直接访问
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# 如果访问的文件或目录不是真事存在,分发请求至 index.php
RewriteRule . index.php
</IfModule>
================================================
FILE: .travis.yml
================================================
language: php
php:
- 5.4
before_script:
- composer install
script:
- phpunit -c phpunit.xml
================================================
FILE: README.md
================================================
# FastPHP
[](https://travis-ci.org/yeszao/fastphp)
[](https://packagist.org/packages/yeszao/fastphp)
[](https://packagist.org/packages/yeszao/fastphp)
[](https://packagist.org/packages/yeszao/fastphp)
[](https://packagist.org/packages/yeszao/fastphp)
## 简述
**fastphp**是一款简单的PHP MVC框架,目的是方便学习《手把手编写自己的PHP MVC框架》教程的同学下载源代码,详细介绍请参考网站:http://www.awaimai.com/128.html 。
要求:
* PHP 5.4.0+
## 目录说明
```
project 根目录
├─app 应用目录
│ ├─controllers 控制器目录
│ ├─models 模块目录
│ ├─views 视图目录
├─config 配置文件目录
├─fastphp 框架核心目录
├─static 静态文件目录
├─index.php 入口文件
```
## 使用
### 1.安装
主要介绍通过composer和git两种安装方法,选择其一即可。
**方法1**:Composer安装(推荐)
```
composer create-project yeszao/fastphp project --no-dev
```
其中,`--no-dev`表示不安装-dev依赖包(PHPUnit)。
**方法2**:Github安装:
```
git clone https://github.com/yeszao/fastphp.git project
```
> 说明:这两个命令都会创建并将代码安装到`project`目录。
### 2. 创建数据库
在数据库中创建名为 project 的数据库,并插入两条记录,命令:
```
CREATE DATABASE `project` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `project`;
CREATE TABLE `item` (
`id` int(11) NOT NULL auto_increment,
`item_name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
INSERT INTO `item` VALUES(1, 'Hello World.');
INSERT INTO `item` VALUES(2, 'Lets go!');
```
### 3.修改数据库配置文件
打开配置文件 config/config.php ,使之与自己的数据库匹配
```
$config['db']['host'] = 'localhost';
$config['db']['username'] = 'root';
$config['db']['password'] = '123456';
$config['db']['dbname'] = 'project';
```
### 4.配置Nginx或Apache
在Apache或Nginx中创建一个站点,把 project 设置为站点根目录(入口文件 index.php 所在的目录)。
然后设置单一入口, Apache服务器配置:
```
<IfModule mod_rewrite.c>
# 打开Rerite功能
RewriteEngine On
# 如果请求的是真实存在的文件或目录,直接访问
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# 如果访问的文件或目录不是真事存在,分发请求至 index.php
RewriteRule . index.php
</IfModule>
```
Nginx服务器配置:
```
location / {
# 重新向所有非真实存在的请求到index.php
try_files $uri $uri/ /index.php$args;
}
```
### 5.测试访问
然后访问站点域名:http://localhost/ 就可以了。
================================================
FILE: app/controllers/ItemController.php
================================================
<?php
namespace app\controllers;
use fastphp\base\Controller;
use app\models\Item;
class ItemController extends Controller
{
// 首页方法,测试框架自定义DB查询
public function index()
{
$keyword = isset($_GET['keyword']) ? $_GET['keyword'] : '';
if ($keyword) {
$items = (new Item())->search($keyword);
} else {
// 查询所有内容,并按倒序排列输出
// where()方法可不传入参数,或者省略
$items = (new Item)->where()->order(['id DESC'])->fetchAll();
}
$this->assign('title', '全部条目');
$this->assign('keyword', $keyword);
$this->assign('items', $items);
$this->render();
}
// 查看单条记录详情
public function detail($id)
{
// 通过?占位符传入$id参数
$item = (new Item())->where(["id = ?"], [$id])->fetch();
$this->assign('title', '条目详情');
$this->assign('item', $item);
$this->render();
}
// 添加记录,测试框架DB记录创建(Create)
public function add()
{
$data['item_name'] = $_POST['value'];
$count = (new Item)->add($data);
$this->assign('title', '添加成功');
$this->assign('count', $count);
$this->render();
}
// 操作管理
public function manage($id = 0)
{
$item = array();
if ($id) {
// 通过名称占位符传入参数
$item = (new Item())->where(["id = :id"], [':id' => $id])->fetch();
}
$this->assign('title', '管理条目');
$this->assign('item', $item);
$this->render();
}
// 更新记录,测试框架DB记录更新(Update)
public function update()
{
$data = array('id' => $_POST['id'], 'item_name' => $_POST['value']);
$count = (new Item)->where(['id = :id'], [':id' => $data['id']])->update($data);
$this->assign('title', '修改成功');
$this->assign('count', $count);
$this->render();
}
// 删除记录,测试框架DB记录删除(Delete)
public function delete($id = null)
{
$count = (new Item)->delete($id);
$this->assign('title', '删除成功');
$this->assign('count', $count);
$this->render();
}
}
================================================
FILE: app/models/Item.php
================================================
<?php
namespace app\models;
use fastphp\base\Model;
use fastphp\db\Db;
/**
* 用户Model
*/
class Item extends Model
{
/**
* 自定义当前模型操作的数据库表名称,
* 如果不指定,默认为类名称的小写字符串,
* 这里就是 item 表
* @var string
*/
protected $table = 'item';
/**
* 搜索功能,因为Sql父类里面没有现成的like搜索,
* 所以需要自己写SQL语句,对数据库的操作应该都放
* 在Model里面,然后提供给Controller直接调用
* @param $title string 查询的关键词
* @return array 返回的数据
*/
public function search($keyword)
{
$sql = "select * from `$this->table` where `item_name` like :keyword";
$sth = Db::pdo()->prepare($sql);
$sth = $this->formatParam($sth, [':keyword' => "%$keyword%"]);
$sth->execute();
return $sth->fetchAll();
}
}
================================================
FILE: app/views/footer.php
================================================
</body>
</html>
================================================
FILE: app/views/header.php
================================================
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title ?></title>
<link rel="stylesheet" href="/static/css/main.css" type="text/css" />
</head>
<body>
<h1><?php echo $title ?></h1>
================================================
FILE: app/views/item/add.php
================================================
<a class="big" href="/item/index">成功添加<?php echo $count ?>条记录,点击返回</a>
================================================
FILE: app/views/item/delete.php
================================================
<a href="/item/index">成功删除<?php echo $count ?>项,点击返回</a>
================================================
FILE: app/views/item/detail.php
================================================
ID:<?php echo $item['id'] ?><br />
Name:<?php echo isset($item['item_name']) ? $item['item_name'] : '' ?>
<br />
<br />
<a class="big" href="/item/index">返回</a>
================================================
FILE: app/views/item/index.php
================================================
<form action="" method="get">
<input type="text" value="<?php echo $keyword ?>" name="keyword">
<input type="submit" value="搜索">
</form>
<p><a href="/item/manage">新建</a></p>
<table>
<tr>
<th>ID</th>
<th>内容</th>
<th>操作</th>
</tr>
<?php foreach ($items as $item): ?>
<tr>
<td><?php echo $item['id'] ?></td>
<td>
<a href="/item/detail/<?php echo $item['id'] ?>" title="查看详情">
<?php echo $item['item_name'] ?>
</a>
</td>
<td>
<a href="/item/manage/<?php echo $item['id'] ?>">编辑</a>
<a href="/item/delete/<?php echo $item['id'] ?>">删除</a>
</td>
</tr>
<?php endforeach ?>
</table>
================================================
FILE: app/views/item/manage.php
================================================
<form <?php if (isset($item['id'])) { ?>
action="/item/update/<?php echo $item['id'] ?>"
<?php } else { ?>
action="/item/add"
<?php } ?>
method="post">
<?php if (isset($item['id'])): ?>
<input type="hidden" name="id" value="<?php echo $item['id'] ?>">
<?php endif; ?>
<input type="text" name="value" value="<?php echo isset($item['item_name']) ? $item['item_name'] : '' ?>">
<input type="submit" value="提交">
</form>
<a class="big" href="/item/index">返回</a>
================================================
FILE: app/views/item/update.php
================================================
<a class="big" href="/item/index">成功修改<?php echo $count ?>项,点击返回</a>
================================================
FILE: composer.json
================================================
{
"name": "yeszao/fastphp",
"description": "Simple and lightweight PHP framework",
"type": "project",
"keywords": [
"framework",
"fastphp",
"mvc"
],
"homepage": "http://www.awaimai.com",
"license": "MIT",
"authors": [
{
"name": "gary",
"email": "galley.meng@gmail.com"
}
],
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8.0"
},
"config": {
"preferred-install": "dist",
"platform": {
"php": "5.4"
}
},
"autoload": {
"psr-4": {
"app\\": "app"
}
}
}
================================================
FILE: config/config.php
================================================
<?php
// 数据库配置
$config['db']['host'] = 'localhost';
$config['db']['username'] = 'root';
$config['db']['password'] = '123456';
$config['db']['dbname'] = 'project';
// 默认控制器和操作名
$config['defaultController'] = 'Item';
$config['defaultAction'] = 'index';
return $config;
================================================
FILE: fastphp/Fastphp.php
================================================
<?php
namespace fastphp;
// 框架根目录
defined('CORE_PATH') or define('CORE_PATH', __DIR__);
/**
* fastphp框架核心
*/
class Fastphp
{
// 配置内容
protected $config = [];
public function __construct($config)
{
$this->config = $config;
}
// 运行程序
public function run()
{
spl_autoload_register(array($this, 'loadClass'));
$this->setReporting();
$this->removeMagicQuotes();
$this->unregisterGlobals();
$this->setDbConfig();
$this->route();
}
// 路由处理
public function route()
{
$controllerName = $this->config['defaultController'];
$actionName = $this->config['defaultAction'];
$param = array();
$url = $_SERVER['REQUEST_URI'];
// 清除?之后的内容
$position = strpos($url, '?');
$url = $position === false ? $url : substr($url, 0, $position);
// 使得可以这样访问 index.php/{controller}/{action}
$position = strpos($url, 'index.php');
if ($position !== false) {
$url = substr($url, $position + strlen('index.php'));
}
// 删除前后的“/”
$url = trim($url, '/');
if ($url) {
// 使用“/”分割字符串,并保存在数组中
$urlArray = explode('/', $url);
// 删除空的数组元素
$urlArray = array_filter($urlArray);
// 获取控制器名
$controllerName = ucfirst($urlArray[0]);
// 获取动作名
array_shift($urlArray);
$actionName = $urlArray ? $urlArray[0] : $actionName;
// 获取URL参数
array_shift($urlArray);
$param = $urlArray ? $urlArray : array();
}
// 判断控制器和操作是否存在
$controller = 'app\\controllers\\'. $controllerName . 'Controller';
if (!class_exists($controller)) {
exit($controller . '控制器不存在');
}
if (!method_exists($controller, $actionName)) {
exit($actionName . '方法不存在');
}
// 如果控制器和操作名存在,则实例化控制器,因为控制器对象里面
// 还会用到控制器名和操作名,所以实例化的时候把他们俩的名称也
// 传进去。结合Controller基类一起看
$dispatch = new $controller($controllerName, $actionName);
// $dispatch保存控制器实例化后的对象,我们就可以调用它的方法,
// 也可以像方法中传入参数,以下等同于:$dispatch->$actionName($param)
call_user_func_array(array($dispatch, $actionName), $param);
}
// 检测开发环境
public function setReporting()
{
if (APP_DEBUG === true) {
error_reporting(E_ALL);
ini_set('display_errors','On');
} else {
error_reporting(E_ALL);
ini_set('display_errors','Off');
ini_set('log_errors', 'On');
}
}
// 删除敏感字符
public function stripSlashesDeep($value)
{
$value = is_array($value) ? array_map(array($this, 'stripSlashesDeep'), $value) : stripslashes($value);
return $value;
}
// 检测敏感字符并删除
public function removeMagicQuotes()
{
if (get_magic_quotes_gpc()) {
$_GET = isset($_GET) ? $this->stripSlashesDeep($_GET ) : '';
$_POST = isset($_POST) ? $this->stripSlashesDeep($_POST ) : '';
$_COOKIE = isset($_COOKIE) ? $this->stripSlashesDeep($_COOKIE) : '';
$_SESSION = isset($_SESSION) ? $this->stripSlashesDeep($_SESSION) : '';
}
}
// 检测自定义全局变量并移除。因为 register_globals 已经弃用,如果
// 已经弃用的 register_globals 指令被设置为 on,那么局部变量也将
// 在脚本的全局作用域中可用。 例如, $_POST['foo'] 也将以 $foo 的
// 形式存在,这样写是不好的实现,会影响代码中的其他变量。 相关信息,
// 参考: http://php.net/manual/zh/faq.using.php#faq.register-globals
public function unregisterGlobals()
{
if (ini_get('register_globals')) {
$array = array('_SESSION', '_POST', '_GET', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
foreach ($array as $value) {
foreach ($GLOBALS[$value] as $key => $var) {
if ($var === $GLOBALS[$key]) {
unset($GLOBALS[$key]);
}
}
}
}
}
// 配置数据库信息
public function setDbConfig()
{
if ($this->config['db']) {
define('DB_HOST', $this->config['db']['host']);
define('DB_NAME', $this->config['db']['dbname']);
define('DB_USER', $this->config['db']['username']);
define('DB_PASS', $this->config['db']['password']);
}
}
// 自动加载类
public function loadClass($className)
{
$classMap = $this->classMap();
if (isset($classMap[$className])) {
// 包含内核文件
$file = $classMap[$className];
} elseif (strpos($className, '\\') !== false) {
// 包含应用(application目录)文件
$file = APP_PATH . str_replace('\\', '/', $className) . '.php';
if (!is_file($file)) {
return;
}
} else {
return;
}
include $file;
// 这里可以加入判断,如果名为$className的类、接口或者性状不存在,则在调试模式下抛出错误
}
// 内核文件命名空间映射关系
protected function classMap()
{
return [
'fastphp\base\Controller' => CORE_PATH . '/base/Controller.php',
'fastphp\base\Model' => CORE_PATH . '/base/Model.php',
'fastphp\base\View' => CORE_PATH . '/base/View.php',
'fastphp\db\Db' => CORE_PATH . '/db/Db.php',
'fastphp\db\Sql' => CORE_PATH . '/db/Sql.php',
];
}
}
================================================
FILE: fastphp/base/Controller.php
================================================
<?php
namespace fastphp\base;
/**
* 控制器基类
*/
class Controller
{
protected $_controller;
protected $_action;
protected $_view;
// 构造函数,初始化属性,并实例化对应模型
public function __construct($controller, $action)
{
$this->_controller = $controller;
$this->_action = $action;
$this->_view = new View($controller, $action);
}
// 分配变量
public function assign($name, $value)
{
$this->_view->assign($name, $value);
}
// 渲染视图
public function render()
{
$this->_view->render();
}
}
================================================
FILE: fastphp/base/Model.php
================================================
<?php
namespace fastphp\base;
use fastphp\db\Sql;
class Model extends Sql
{
protected $model;
public function __construct()
{
// 获取数据库表名
if (!$this->table) {
// 获取模型类名称
$this->model = get_class($this);
// 删除类名最后的 Model 字符
$this->model = substr($this->model, 0, -5);
// 数据库表名与类名一致
$this->table = strtolower($this->model);
}
}
}
================================================
FILE: fastphp/base/View.php
================================================
<?php
namespace fastphp\base;
/**
* 视图基类
*/
class View
{
protected $variables = array();
protected $_controller;
protected $_action;
function __construct($controller, $action)
{
$this->_controller = strtolower($controller);
$this->_action = strtolower($action);
}
// 分配变量
public function assign($name, $value)
{
$this->variables[$name] = $value;
}
// 渲染显示
public function render()
{
extract($this->variables);
$defaultHeader = APP_PATH . 'app/views/header.php';
$defaultFooter = APP_PATH . 'app/views/footer.php';
$controllerHeader = APP_PATH . 'app/views/' . $this->_controller . '/header.php';
$controllerFooter = APP_PATH . 'app/views/' . $this->_controller . '/footer.php';
$controllerLayout = APP_PATH . 'app/views/' . $this->_controller . '/' . $this->_action . '.php';
// 页头文件
if (is_file($controllerHeader)) {
include ($controllerHeader);
} else {
include ($defaultHeader);
}
//判断视图文件是否存在
if (is_file($controllerLayout)) {
include ($controllerLayout);
} else {
echo "<h1>无法找到视图文件</h1>";
}
// 页脚文件
if (is_file($controllerFooter)) {
include ($controllerFooter);
} else {
include ($defaultFooter);
}
}
}
================================================
FILE: fastphp/db/Db.php
================================================
<?php
namespace fastphp\db;
use PDO;
use PDOException;
/**
* 数据库操作类。
* 其$pdo属性为静态属性,所以在页面执行周期内,
* 只要一次赋值,以后的获取还是首次赋值的内容。
* 这里就是PDO对象,这样可以确保运行期间只有一个
* 数据库连接对象,这是一种简单的单例模式
* Class Db
*/
class Db
{
private static $pdo = null;
public static function pdo()
{
if (self::$pdo !== null) {
return self::$pdo;
}
try {
$dsn = sprintf('mysql:host=%s;dbname=%s;charset=utf8', DB_HOST, DB_NAME);
$option = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
return self::$pdo = new PDO($dsn, DB_USER, DB_PASS, $option);
} catch (PDOException $e) {
exit($e->getMessage());
}
}
}
================================================
FILE: fastphp/db/Sql.php
================================================
<?php
namespace fastphp\db;
use \PDOStatement;
class Sql
{
// 数据库表名
protected $table;
// 数据库主键
protected $primary = 'id';
// WHERE和ORDER拼装后的条件
private $filter = '';
// Pdo bindParam()绑定的参数集合
private $param = array();
/**
* 查询条件拼接,使用方式:
*
* $this->where(['id = 1','and title="Web"', ...])->fetch();
* 为防止注入,建议通过$param方式传入参数:
* $this->where(['id = :id'], [':id' => $id])->fetch();
*
* @param array $where 条件
* @return $this 当前对象
*/
public function where($where = array(), $param = array())
{
if ($where) {
$this->filter .= ' WHERE ';
$this->filter .= implode(' ', $where);
$this->param = $param;
}
return $this;
}
/**
* 拼装排序条件,使用方式:
*
* $this->order(['id DESC', 'title ASC', ...])->fetch();
*
* @param array $order 排序条件
* @return $this
*/
public function order($order = array())
{
if($order) {
$this->filter .= ' ORDER BY ';
$this->filter .= implode(',', $order);
}
return $this;
}
// 查询所有
public function fetchAll()
{
$sql = sprintf("select * from `%s` %s", $this->table, $this->filter);
$sth = Db::pdo()->prepare($sql);
$sth = $this->formatParam($sth, $this->param);
$sth->execute();
return $sth->fetchAll();
}
// 查询一条
public function fetch()
{
$sql = sprintf("select * from `%s` %s", $this->table, $this->filter);
$sth = Db::pdo()->prepare($sql);
$sth = $this->formatParam($sth, $this->param);
$sth->execute();
return $sth->fetch();
}
// 根据条件 (id) 删除
public function delete($id)
{
$sql = sprintf("delete from `%s` where `%s` = :%s", $this->table, $this->primary, $this->primary);
$sth = Db::pdo()->prepare($sql);
$sth = $this->formatParam($sth, [$this->primary => $id]);
$sth->execute();
return $sth->rowCount();
}
// 新增数据
public function add($data)
{
$sql = sprintf("insert into `%s` %s", $this->table, $this->formatInsert($data));
$sth = Db::pdo()->prepare($sql);
$sth = $this->formatParam($sth, $data);
$sth = $this->formatParam($sth, $this->param);
$sth->execute();
return $sth->rowCount();
}
// 修改数据
public function update($data)
{
$sql = sprintf("update `%s` set %s %s", $this->table, $this->formatUpdate($data), $this->filter);
$sth = Db::pdo()->prepare($sql);
$sth = $this->formatParam($sth, $data);
$sth = $this->formatParam($sth, $this->param);
$sth->execute();
return $sth->rowCount();
}
/**
* 占位符绑定具体的变量值
* @param PDOStatement $sth 要绑定的PDOStatement对象
* @param array $params 参数,有三种类型:
* 1)如果SQL语句用问号?占位符,那么$params应该为
* [$a, $b, $c]
* 2)如果SQL语句用冒号:占位符,那么$params应该为
* ['a' => $a, 'b' => $b, 'c' => $c]
* 或者
* [':a' => $a, ':b' => $b, ':c' => $c]
*
* @return PDOStatement
*/
public function formatParam(PDOStatement $sth, $params = array())
{
foreach ($params as $param => &$value) {
$param = is_int($param) ? $param + 1 : ':' . ltrim($param, ':');
$sth->bindParam($param, $value);
}
return $sth;
}
// 将数组转换成插入格式的sql语句
private function formatInsert($data)
{
$fields = array();
$names = array();
foreach ($data as $key => $value) {
$fields[] = sprintf("`%s`", $key);
$names[] = sprintf(":%s", $key);
}
$field = implode(',', $fields);
$name = implode(',', $names);
return sprintf("(%s) values (%s)", $field, $name);
}
// 将数组转换成更新格式的sql语句
private function formatUpdate($data)
{
$fields = array();
foreach ($data as $key => $value) {
$fields[] = sprintf("`%s` = :%s", $key, $key);
}
return implode(',', $fields);
}
}
================================================
FILE: index.php
================================================
<?php
// 应用目录为当前目录
define('APP_PATH', __DIR__ . '/');
// 开启调试模式
define('APP_DEBUG', true);
// 加载框架文件
require(APP_PATH . 'fastphp/Fastphp.php');
// 加载配置文件
$config = require(APP_PATH . 'config/config.php');
// 实例化框架类
(new fastphp\Fastphp($config))->run();
================================================
FILE: phpunit.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
bootstrap="tests/autoload.php"
colors="true">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
================================================
FILE: static/css/main.css
================================================
html, body {
margin: 0;
padding: 10px;
font-size: 20px;
}
input {
font-family:georgia,times;
font-size:24px;
line-height:1.2em;
}
a {
color:blue;
font-family:georgia,times;
line-height:1.2em;
text-decoration:none;
}
a:hover {
text-decoration:underline;
}
h1 {
color:#000000;
font-size:41px;
border-bottom:1px dotted #cccccc;
}
td {padding: 1px 30px 1px 0;}
================================================
FILE: tests/autoload.php
================================================
<?php
include __DIR__ . '/../vendor/autoload.php';
gitextract_2es6sksp/
├── .gitignore
├── .htaccess
├── .travis.yml
├── README.md
├── app/
│ ├── controllers/
│ │ └── ItemController.php
│ ├── models/
│ │ └── Item.php
│ └── views/
│ ├── footer.php
│ ├── header.php
│ └── item/
│ ├── add.php
│ ├── delete.php
│ ├── detail.php
│ ├── index.php
│ ├── manage.php
│ └── update.php
├── composer.json
├── config/
│ └── config.php
├── fastphp/
│ ├── Fastphp.php
│ ├── base/
│ │ ├── Controller.php
│ │ ├── Model.php
│ │ └── View.php
│ └── db/
│ ├── Db.php
│ └── Sql.php
├── index.php
├── phpunit.xml
├── static/
│ └── css/
│ └── main.css
└── tests/
└── autoload.php
SYMBOL INDEX (43 symbols across 8 files)
FILE: app/controllers/ItemController.php
class ItemController (line 7) | class ItemController extends Controller
method index (line 10) | public function index()
method detail (line 29) | public function detail($id)
method add (line 40) | public function add()
method manage (line 51) | public function manage($id = 0)
method update (line 65) | public function update()
method delete (line 76) | public function delete($id = null)
FILE: app/models/Item.php
class Item (line 10) | class Item extends Model
method search (line 27) | public function search($keyword)
FILE: fastphp/Fastphp.php
class Fastphp (line 11) | class Fastphp
method __construct (line 16) | public function __construct($config)
method run (line 22) | public function run()
method route (line 33) | public function route()
method setReporting (line 91) | public function setReporting()
method stripSlashesDeep (line 104) | public function stripSlashesDeep($value)
method removeMagicQuotes (line 111) | public function removeMagicQuotes()
method unregisterGlobals (line 126) | public function unregisterGlobals()
method setDbConfig (line 141) | public function setDbConfig()
method loadClass (line 152) | public function loadClass($className)
method classMap (line 175) | protected function classMap()
FILE: fastphp/base/Controller.php
class Controller (line 7) | class Controller
method __construct (line 14) | public function __construct($controller, $action)
method assign (line 22) | public function assign($name, $value)
method render (line 28) | public function render()
FILE: fastphp/base/Model.php
class Model (line 6) | class Model extends Sql
method __construct (line 10) | public function __construct()
FILE: fastphp/base/View.php
class View (line 7) | class View
method __construct (line 13) | function __construct($controller, $action)
method assign (line 20) | public function assign($name, $value)
method render (line 26) | public function render()
FILE: fastphp/db/Db.php
class Db (line 15) | class Db
method pdo (line 19) | public static function pdo()
FILE: fastphp/db/Sql.php
class Sql (line 6) | class Sql
method where (line 30) | public function where($where = array(), $param = array())
method order (line 50) | public function order($order = array())
method fetchAll (line 61) | public function fetchAll()
method fetch (line 72) | public function fetch()
method delete (line 83) | public function delete($id)
method add (line 94) | public function add($data)
method update (line 106) | public function update($data)
method formatParam (line 130) | public function formatParam(PDOStatement $sth, $params = array())
method formatInsert (line 141) | private function formatInsert($data)
method formatUpdate (line 157) | private function formatUpdate($data)
Condensed preview — 26 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (29K chars).
[
{
"path": ".gitignore",
"chars": 15,
"preview": ".idea\r\nvendor\r\n"
},
{
"path": ".htaccess",
"chars": 261,
"preview": "<IfModule mod_rewrite.c>\r\n # 打开Rerite功能\r\n RewriteEngine On\r\n\r\n # 如果请求的是真实存在的文件或目录,直接访问\r\n RewriteCond %{REQUE"
},
{
"path": ".travis.yml",
"chars": 107,
"preview": "language: php\r\nphp:\r\n - 5.4\r\n\r\nbefore_script:\r\n - composer install\r\n\r\nscript:\r\n - phpunit -c phpunit.xml"
},
{
"path": "README.md",
"chars": 2465,
"preview": "# FastPHP\n\n[](https://travis-ci.org/yeszao/fastph"
},
{
"path": "app/controllers/ItemController.php",
"chars": 2176,
"preview": "<?php\r\nnamespace app\\controllers;\r\n\r\nuse fastphp\\base\\Controller;\r\nuse app\\models\\Item;\r\n \r\nclass ItemController extends"
},
{
"path": "app/models/Item.php",
"chars": 772,
"preview": "<?php\r\nnamespace app\\models;\r\n\r\nuse fastphp\\base\\Model;\r\nuse fastphp\\db\\Db;\r\n\r\n/**\r\n * 用户Model\r\n */\r\nclass Item extends "
},
{
"path": "app/views/footer.php",
"chars": 16,
"preview": "</body>\r\n</html>"
},
{
"path": "app/views/header.php",
"chars": 257,
"preview": "<html>\r\n<head>\r\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n <title><?php echo $title "
},
{
"path": "app/views/item/add.php",
"chars": 70,
"preview": "<a class=\"big\" href=\"/item/index\">成功添加<?php echo $count ?>条记录,点击返回</a>"
},
{
"path": "app/views/item/delete.php",
"chars": 56,
"preview": "<a href=\"/item/index\">成功删除<?php echo $count ?>项,点击返回</a>"
},
{
"path": "app/views/item/detail.php",
"chars": 166,
"preview": "ID:<?php echo $item['id'] ?><br />\r\nName:<?php echo isset($item['item_name']) ? $item['item_name'] : '' ?>\r\n\r\n<br />\r\n<b"
},
{
"path": "app/views/item/index.php",
"chars": 813,
"preview": "<form action=\"\" method=\"get\">\r\n <input type=\"text\" value=\"<?php echo $keyword ?>\" name=\"keyword\">\r\n <input type=\"s"
},
{
"path": "app/views/item/manage.php",
"chars": 543,
"preview": "<form <?php if (isset($item['id'])) { ?>\r\n action=\"/item/update/<?php echo $item['id'] ?>\"\r\n <?php } "
},
{
"path": "app/views/item/update.php",
"chars": 68,
"preview": "<a class=\"big\" href=\"/item/index\">成功修改<?php echo $count ?>项,点击返回</a>"
},
{
"path": "composer.json",
"chars": 613,
"preview": "{\r\n \"name\": \"yeszao/fastphp\",\r\n \"description\": \"Simple and lightweight PHP framework\",\r\n \"type\": \"project\",\r\n \"keywo"
},
{
"path": "config/config.php",
"chars": 270,
"preview": "<?php\n\n// 数据库配置\n$config['db']['host'] = 'localhost';\n$config['db']['username'] = 'root';\n$config['db']['password'] = '12"
},
{
"path": "fastphp/Fastphp.php",
"chars": 5591,
"preview": "<?php\r\n\r\nnamespace fastphp;\r\n\r\n// 框架根目录\r\ndefined('CORE_PATH') or define('CORE_PATH', __DIR__);\r\n\r\n/**\r\n * fastphp框架核心\r\n "
},
{
"path": "fastphp/base/Controller.php",
"chars": 596,
"preview": "<?php\r\nnamespace fastphp\\base;\r\n\r\n/**\r\n * 控制器基类\r\n */\r\nclass Controller\r\n{\r\n protected $_controller;\r\n protected $_"
},
{
"path": "fastphp/base/Model.php",
"chars": 468,
"preview": "<?php\r\nnamespace fastphp\\base;\r\n\r\nuse fastphp\\db\\Sql;\r\n\r\nclass Model extends Sql\r\n{\r\n protected $model;\r\n\r\n public"
},
{
"path": "fastphp/base/View.php",
"chars": 1482,
"preview": "<?php\r\nnamespace fastphp\\base;\r\n\r\n/**\r\n * 视图基类\r\n */\r\nclass View\r\n{\r\n protected $variables = array();\r\n protected $"
},
{
"path": "fastphp/db/Db.php",
"chars": 732,
"preview": "<?php\r\nnamespace fastphp\\db;\r\n\r\nuse PDO;\r\nuse PDOException;\r\n\r\n/**\r\n * 数据库操作类。\r\n * 其$pdo属性为静态属性,所以在页面执行周期内,\r\n * 只要一次赋值,以"
},
{
"path": "fastphp/db/Sql.php",
"chars": 4253,
"preview": "<?php\r\nnamespace fastphp\\db;\r\n\r\nuse \\PDOStatement;\r\n\r\nclass Sql\r\n{\r\n // 数据库表名\r\n protected $table;\r\n\r\n // 数据库主键\r"
},
{
"path": "index.php",
"chars": 258,
"preview": "<?php\n// 应用目录为当前目录\ndefine('APP_PATH', __DIR__ . '/');\n\n// 开启调试模式\ndefine('APP_DEBUG', true);\n\n// 加载框架文件\nrequire(APP_PATH "
},
{
"path": "phpunit.xml",
"chars": 297,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<phpunit backupGlobals=\"false\"\r\n bootstrap=\"tests/autoload.php\"\r\n\t\t colo"
},
{
"path": "static/css/main.css",
"chars": 446,
"preview": "html, body {\r\n margin: 0;\r\n padding: 10px;\r\n font-size: 20px;\r\n}\r\n\r\ninput {\r\n font-family:georgia,times;\r\n "
},
{
"path": "tests/autoload.php",
"chars": 53,
"preview": "<?php\r\ninclude __DIR__ . '/../vendor/autoload.php';\r\n"
}
]
About this extraction
This page contains the full source code of the yeszao/fastphp GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 26 files (22.3 KB), approximately 7.2k tokens, and a symbol index with 43 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.