mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-23 18:07:42 +02:00
Copy BoolCast
behavior from db-web
This commit is contained in:
parent
d540ad4c0e
commit
97b009c39f
32
library/Icinga/Model/Behavior/BoolCast.php
Normal file
32
library/Icinga/Model/Behavior/BoolCast.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
|
||||
|
||||
namespace Icinga\Model\Behavior;
|
||||
|
||||
use ipl\Orm\Contract\PropertyBehavior;
|
||||
|
||||
//TODO: Is copied from icingadb-web
|
||||
class BoolCast extends PropertyBehavior
|
||||
{
|
||||
public function fromDb($value, $key, $_)
|
||||
{
|
||||
switch ($value) {
|
||||
case 'y':
|
||||
return true;
|
||||
case 'n':
|
||||
return false;
|
||||
default:
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function toDb($value, $key, $_)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $value ? 'y' : 'n';
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user