2019-02-17 11:34:46 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +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
|
|
|
*/
|
2019-02-17 11:34:46 +01:00
|
|
|
|
|
|
|
namespace App\DataMapper;
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* ClientSettings.
|
2019-02-17 11:34:46 +01:00
|
|
|
*/
|
|
|
|
class BaseSettings
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
public function __construct($obj)
|
|
|
|
{
|
|
|
|
foreach ($obj as $key => $value) {
|
|
|
|
$obj->{$key} = $value;
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
public static function setCasts($obj, $casts)
|
|
|
|
{
|
|
|
|
foreach ($casts as $key => $value) {
|
|
|
|
$obj->{$key} = self::castAttribute($key, $obj->{$key});
|
|
|
|
}
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return $obj;
|
|
|
|
}
|
2019-09-19 07:50:05 +02:00
|
|
|
|
2019-12-30 22:59:12 +01: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);
|
2019-12-30 22:59:12 +01:00
|
|
|
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
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
public static function castSingleAttribute($key, $data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|