arzynik / cana
PHP 面向对象框架
v0.2.3
2012-03-28 00:00 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2024-09-24 04:25:37 UTC
README
cana 是一个用于快速面向对象开发的 MVC PHP 框架。它结合了像 zend 这样的现有 PHP 框架的基本原则,并将其与 Ruby、Python 和 jQuery 中易于使用、扩展的对象支持相结合。cana 的名字本身就说明了它的特点。
你可以做一些很酷的事情
从数据库中获取一个对象并将其缓存到内存中
$shot = new BigBrother_Shot('DEV_DSM_000');
或者做同样的事情,但带有自动对象创建、自动类别名和删除不必要的引号
$shot = Shot::o(DEV_DSM_000);
在多个数据库对象上调用一个函数
Shot::o(DEV_DSM_000,DEV_DSM_100)->delete();
在多个对象上设置属性并将它们保存回数据库
echo Staff::o(DSM,MPR,SSW)->s('permission','MANAGER')->save();
在对象上设置多个属性并保存它
Shot::o(DEV_DSM_000)->s([
'date_due' => '2012-01-01',
'id_deliv_group' => 'LUMA'
])->save();
将数据库对象输出为 JSON
echo Shot::o(DEV_DSM_000)->json();
或者将多个数据库对象作为一个单独的 JSON 对象输出
echo Shot::o(DEV_DSM_000,534)->json();
从数据库查询中修改多个对象的属性
c::db()->get('select * from shots where id_project="marvel"')->producer = 'DSM';
使用数据库对象进行迭代
foreach (c::db()->get('select * from shots where id_project="marvel"') as $shot) {
print_r($shot);
}
设置两个对象的生成者属性,然后从它们的缓存中访问这些 dbos 并输出它们的生成者属性
Shot::o(DEV_DSM_000,534)->producer = 'DSM';
echo Shot::o(DEV_DSM_000)->producer;
echo Shot::o(534)->producer;
这个过滤器将与以下 SQL 相同:((id_project=dev AND shot_name=DSV_DSM_000) OR (id_shot=534))
echo Shot::o(
['shot_name' => 'peanuts', 'id_project' => 'dev'],
'{"shot_name": "BACON"}',
DEV_DSM_000,
'534'
)->filter(
['id_project' => 'dev', 'shot_name' => 'DEV_DSM_000'],
['id_shot' => '534']
);
过滤一组对象以仅在特定项目上设置生成者属性,然后返回完整集合
$shots = Shot::o(['shot_name' => 'peanuts'],'{"shot_name": "BACON"}',DEV_DSM_000,534)
->filter('id_project','devs')
->set('producer','DSM')
->parent();
访问集合中的最后一个项目
echo Shot::o('{"shot_name": "BACON"}',DEV_DSM_000,'534')->eq(-1);
使用几个参数、数组或集合构建一个集合,并将内部的项目合并
i::o(Shot::o(534),Shot_Element::o(4944))->each(function($key, $item) {
echo $this;
});
从一个已存在的数组中创建一个集合,并使用 foreach 迭代它们
foreach (i::o(Project::o('marvel')->shots(), Project::o('uw4')->shots()) as $shot) {
echo $shot;
}
使用查询方法构建一个集合,然后遍历每个项目
Shot_Element::q('
select elements.* from tasks
left join elements on elements.id_shot_element=tasks.id_shot_element
left join shots on shots.id_shot=elements.id_shot
left join projects on projects.id_project=shots.id_project
where id_element="PLATE"
and id_task_status="NONE"
and id_elem_status!="FINL"
and elements.id_deliv_group!="CUT"
and (elements.id_staff="TDA" or elements.id_staff="JPR")
and shots.active=1
and projects.active=1
')->e(function($item) {
// do some cool stuff here
});
在基于 cana 的基本对象上创建测试函数。这使得函数在全局范围内易于访问
c::extend(['test' => function() {
return 'this is a test';
}]);
echo c::test();
使用可以访问对象的功能扩展类
Staff::extend(['simpleFunc' => function($me, $in) {
echo get_class($me).' '.$in;
}]);
Staff::o(DSM)->simpleFunc('got this');
扩展类以返回一个集合结果
Staff::extend(['devices' => function($me) {
return $me->q('select * from device where id_staff="'.$me->id_staff.'"');
}]);
Staff::o(DSM)->devices()->each(function($key, $item) {
print_r($item);
});
其他功能
cana 以我在洛杉矶最喜欢的酒吧——Caña Rum Bar 命名