Skip to content

Commit 6a919cd

Browse files
committed
Update
1 parent 2954a1c commit 6a919cd

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "floatphp/kernel",
3-
"version" : "1.4.0",
3+
"version" : "1.4.1",
44
"type": "library",
55
"description": "FloatPHP Kernel Components",
66
"keywords": ["php","micro-framework","framework","PSR","ORM","jakiboy","composer"],

src/Orm.php

+19-9
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function read($id = null) : array
153153
if ( $id ) $this->{$this->key} = $id;
154154
$sql = "{$this->getSelectQuery()} ";
155155
$sql .= "{$this->getWhereQuery(single: true)} ";
156-
$sql .= "{$this->getLimitQuery(limit: 1)};";
156+
$sql .= "{$this->getLimitQuery(1)};";
157157
return $this->getRow($sql);
158158
}
159159

@@ -211,7 +211,7 @@ public function delete($id = null) : bool
211211
if ( $id ) $this->{$this->key} = $id;
212212
$sql = "{$this->getDeleteQuery()} ";
213213
$sql .= "{$this->getWhereQuery(single: true)} ";
214-
$sql .= "{$this->getLimitQuery(limit: 1)};";
214+
$sql .= "{$this->getLimitQuery(1)};";
215215
return (bool)$this->execute($sql);
216216
}
217217

@@ -271,14 +271,15 @@ public function query(string $sql, ?array $bind = null, ?string $type = null, ?i
271271
* @param mixed $columns
272272
* @param array $sort
273273
* @param int $limit
274+
* @param ?int $page
274275
* @return array
275276
*/
276-
public function search($columns = '*', array $sort = [], ?int $limit = 0) : array
277+
public function search($columns = '*', array $sort = [], int $limit = 0, ?int $page = null) : array
277278
{
278279
$sql = "{$this->getSelectQuery($columns)} ";
279280
$sql .= "{$this->getWhereQuery()} ";
280281
$sql .= "{$this->getSortQuery($sort)} ";
281-
$sql .= "{$this->getLimitQuery($limit)};";
282+
$sql .= "{$this->getLimitQuery($limit, $page)};";
282283
return (array)$this->execute($sql);
283284
}
284285

@@ -296,7 +297,7 @@ public function searchOne($columns = '*', array $sort = []) : array
296297
$sql = "{$this->getSelectQuery($columns)} ";
297298
$sql .= "{$this->getWhereQuery()} ";
298299
$sql .= "{$this->getSortQuery($sort)} ";
299-
$sql .= "{$this->getLimitQuery(limit: 1)};";
300+
$sql .= "{$this->getLimitQuery(1)};";
300301
return $this->getRow($sql);
301302
}
302303

@@ -308,14 +309,15 @@ public function searchOne($columns = '*', array $sort = []) : array
308309
* @param string $column
309310
* @param array $sort
310311
* @param int $limit
312+
* @param ?int $page
311313
* @return array
312314
*/
313-
public function searchColumn(string $column, array $sort = [], ?int $limit = 0) : array
315+
public function searchColumn(string $column, array $sort = [], int $limit = 0, ?int $page = null) : array
314316
{
315317
$sql = "{$this->getSelectQuery($column)} ";
316318
$sql .= "{$this->getWhereQuery()} ";
317319
$sql .= "{$this->getSortQuery($sort)} ";
318-
$sql .= "{$this->getLimitQuery($limit)};";
320+
$sql .= "{$this->getLimitQuery($limit, $page)};";
319321
return $this->getColumn($sql);
320322
}
321323

@@ -912,13 +914,21 @@ private function getSortQuery(array $sort = []) : string
912914
*
913915
* @access private
914916
* @param int $limit
917+
* @param ?int $page
915918
* @return string
916919
*/
917-
private function getLimitQuery(?int $limit = 0) : string
920+
private function getLimitQuery(int $limit = 0, ?int $page = null) : string
918921
{
919922
$sql = '';
920923
if ( $limit ) {
921-
$sql .= "LIMIT {$limit}";
924+
if ( !$this->isType('null', $page) ) {
925+
$page = $page ?: 1;
926+
$offset = ($page - 1) * $limit;
927+
$sql .= "LIMIT {$offset}, {$limit}";
928+
929+
} else {
930+
$sql .= "LIMIT {$limit}";
931+
}
922932
}
923933
return $sql;
924934
}

src/View.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ protected function getDefaultCallables() : array
157157
'getTimeout' => function () : int {
158158
return $this->getTimeout();
159159
},
160-
'getToken' => function (?string $source = null) : string {
161-
return $this->getToken(action: $source);
160+
'getToken' => function (?string $action = null) : string {
161+
return $this->getToken($action);
162162
},
163163
'getLanguage' => function () : string {
164164
return $this->getLanguage();
@@ -169,7 +169,7 @@ protected function getDefaultCallables() : array
169169
'hasRole' => function ($role = null, $userId = null) : bool {
170170
return $this->hasRole($role, $userId);
171171
},
172-
'hasCapability' => function ($capability = null, $userId = null) {
172+
'hasCapability' => function ($capability = null, $userId = null) : bool {
173173
return $this->hasCapability($capability, $userId);
174174
},
175175
'translate' => function (?string $string) : string {

0 commit comments

Comments
 (0)