1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 01:11:34 +02:00
invoiceninja/app/DataMapper/BaseSettings.php

64 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-05-11 05:32:07 +02:00
*/
namespace App\DataMapper;
/**
* ClientSettings.
*/
class BaseSettings
{
public function __construct($obj)
{
foreach ($obj as $key => $value) {
$obj->{$key} = $value;
}
}
public static function setCasts($obj, $casts)
{
foreach ($casts as $key => $value) {
$obj->{$key} = self::castAttribute($key, $obj->{$key});
}
return $obj;
}
2019-09-19 07:50:05 +02:00
public static function castAttribute($key, $value)
{
switch ($key) {
case 'int':
case 'integer':
return (int) $value;
case 'real':
case 'float':
case 'double':
return (float) $value;
case 'string':
return is_null($value) ? '' : (string) $value;
case 'bool':
case 'boolean':
2022-02-27 07:49:49 +01:00
return boolval($value);
case 'object':
return json_decode($value);
case 'array':
case 'json':
return json_decode($value, true);
default:
return $value;
}
}
2019-09-19 07:50:05 +02:00
public static function castSingleAttribute($key, $data)
{
}
}