本文整理汇总了PHP中lithium\data\Connections::applyFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP Connections::applyFilter方法的具体用法?PHP Connections::applyFilter怎么用?PHP Connections::applyFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\data\Connections
的用法示例。
在下文中一共展示了Connections::applyFilter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initConnections
public static function initConnections()
{
static::$_data['db'] = array();
static::$_data['db.queries'] = array();
static::$_data['db.time'] = 0;
static::$_data['db.invalid'] = 0;
Connections::applyFilter('_initAdapter', function ($self, $params, $chain) {
$adapter = $chain->next($self, $params, $chain);
$adapter->applyFilter(array('read', 'create', 'update', 'delete'), function ($self, $params, $chain) {
$options = $params['options'];
$query = $params['query'];
$data = array();
$queries = array();
$data['start'] = microtime(true);
$data['memory'] = memory_get_usage(true);
if (is_object($query) && method_exists($query, 'model')) {
$data['name'] = $query->model() . '::' . $query->type();
} else {
$data['name'] = '?';
}
if ($result = $chain->next($self, $params, $chain)) {
switch (true) {
case method_exists($result, 'data'):
$queries[] = array('explain' => $result->result()->resource()->explain(), 'query' => $result->result()->resource()->info());
break;
case $query->calculate():
$queries[] = array('explain' => $result->explain(), 'query' => $result->info());
break;
default:
}
$data['name'] .= ' (' . count($result) . ')';
} else {
Debugger::inc('db.invalid', 1);
}
$data['end'] = microtime(true);
$data['memory'] = memory_get_usage(true) - $data['memory'];
$data['time'] = $data['end'] - $data['start'];
Debugger::push('events', $data);
Debugger::inc('events.time', $data['time']);
Debugger::push('db', $data);
Debugger::push('db.queries', $queries);
Debugger::inc('db.time', $data['time']);
return $result;
});
return $adapter;
});
}