count($optFilter); $paginatedStorage = true; } else { $amount = count($collection); $paginatedStorage = false; } $rows = max(1, $optRows); $total = ceil($amount / $rows); $page = max(1, min($optPage, $total)); $offset = ($page - 1) * $rows; $result = array( 'success' => true, 'offset' => $offset, 'amount' => $amount, 'total' => $total, 'page' => $page, 'rows' => $rows ); if ($paginatedStorage) { $result['data'] = $collection->findPage($page, $rows, $optFilter); } else { $result['data'] = array_slice($collection, $offset, $rows); } if (is_callable($dataRenderer)) { $result['data'] = $dataRenderer($result['data']); } $result['length'] = count($result['data']); return $result; } }