-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointer.php
More file actions
57 lines (45 loc) · 1.29 KB
/
Copy pathPointer.php
File metadata and controls
57 lines (45 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/core/blob/master/LICENSE
*/
namespace Quid\Core\Col;
use Quid\Core;
use Quid\Orm;
// pointer
// class for a column which the value is a pointer to another row in the database
class Pointer extends Core\ColAlias
{
// config
protected static array $config = [
'required'=>true,
'validate'=>['pointer'=>[self::class,'custom']]
];
// onGet
// méthode appelé sur get, retourne la row ou null
final protected function onGet($return,?Orm\Cell $cell,array $option)
{
return (is_string($return))? static::getRow($return):$return;
}
// getRow
// retourne la row ou null
final public static function getRow(?string $value):?Core\Row
{
return (is_string($value) && strlen($value))? static::boot()->db()->fromPointer($value):null;
}
// custom
// méthode de validation custom pour le champ pointeur
final public static function custom($value):?bool
{
$return = null;
$row = static::getRow($value);
if(!empty($row))
$return = true;
return $return;
}
}
// init
Pointer::__init();
?>