README.md
4.14 KB
#Hood
概述
框架命名( Hood ) 发动机罩引擎罩来源于Yohood, 框架基于 Yaf 在数据层封装了Dao、Cache、Concurrent、Debug、Server 6个主要模块
框架以简单快捷为目的.
安装
php版本要求 php 5.4+ 以上版本, 必要模块 Pdo_MySQL、Yaf、Yar
https://github.com/laruence/php-yaf
https://github.com/laruence/yar
Yaf 文档
http://php.net/manual/zh/book.yaf.php
配置文件
1、数据库配置
[mysql]
charset = UTF8
persistent = TRUE
collation = utf8_unicode_ci
timeout = 3
[database]
erp_admin.username = root
erp_admin.passwd = root
erp_admin.write = 127.0.0.1:3306
erp_admin.read = 192.168.1.106:3306
erp_admin.dbname = erp_admin
hood.username = root
hood.passwd = root
hood.write = 127.0.0.1:3306
hood.read = 192.168.1.106:3306
hood2.username = root
hood2.passwd = root
hood2.write = 127.0.0.2:3306
hood2.read = 192.168.2.106:3306
2、缓存配置
[memcached]
servers.hosts = 127.0.0.1:11211:90,127.0.0.1:11212:10
erp.hosts = 127.0.0.1:11211:90,127.0.0.1:11212:106
[redis]
servers.hosts = 127.0.0.1:6379
Dao
Dao 提供主要如下方法
1、数据操作
insert、delete、update
2、查询数据
fetchAll、fetchRow、fetchPairs、fetchOne、fetchColumn、fetchObject、fetchClassRow、fetchClass、fetchAssoc、
3、其他设置
setModality 设置读写服务器
cache 缓存设置
tag 缓存标签
key 缓存key
expire 缓存过期时间
数据库操作借鉴Java的 mybatis 把SQL已配置文件形式存储
class SqlMap
{
const INSERT_DEMO = 'insert into demo (`username`,`email`) values (:username,:email)';
const UPDATA_DEMO_BY_ID = 'update demo set `username`=:username,`email`=:email where `id`=:id';
const SELECT_DEMO_BY_ID = 'select * from `demo` where id=:id';
}
Insert
$this->dao()->insert(SqlMap::INSERT_DEMO, array(
'username' => $username,
'email' => $email
))->lastInsertId();
setModality(设置读写模式)
$this->dao()->setModality('read')->insert(SqlMap::INSERT_DEMO, array(
'username' => $username,
'email' => $email
))->lastInsertId();
update
$this->dao()->tag('demo_' . $id)->update(SqlMap::UPDATA_DEMO_BY_ID, array(
'username' => $username,
'email' => $email,
'id' => $id
))->rowCount();
fetchClassRow
$this->dao()->tag('demo_' . $id)->key('demo_row')->expire(300)->setFetchClass('Models\Hood\Demo\Form')
->fetchClassRow(SqlMap::SELECT_DEMO_BY_ID, array( 'id' => $id ));
fetchAssoc
$this->dao()->tag('demo_' . $id)->key('demo_info')->fetchAssoc(SqlMap::SELECT_DEMO_BY_ID, array('id' => $id));
Cache
$mc = hoodCache::Memcached($node, $child_node);
$mc->add($key , $val);
hoodCache::Memcached()->get($key);
hoodCache::Redis()->get($key);
Concurrent
1、RPC ( PHP )
1、普通接口数据请求
Concurrent::yarClient($uri)->getDemoInfoByID($id);
2、平行数据请求
Concurrent::yarConcurrent($uri)->calls('getDemoInfoByID', 1,function ($demoData) {
xxxx
})->calls('getDemoInfoByID', 2,function ($demoData) {
xxxxx
})->loop();
2、CURL Concurrent
```php
use Hood\Concurrent;
$CurlMulti = Concurrent::curlMulti();
$CurlMulti->call('http://www.baidu.com',function ($curl_info, $curl_data, $callback_data) {
print_r($curl_info);
}, 1)->call('http://www.sogou.com',function ($curl_info, $curl_data, $callback_data) {
print_r($curl_info);
}, 2)->finish();
$CurlMulti = Concurrent::curlMulti();
$CurlMulti->callRest('http://www.qin.com/index/demo', 'get', function ($curl_info, $curl_data, $callback_data) {
print_r($curl_data);
}, array('a' => 1))->finish();
```