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
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
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':
|
2020-09-06 11:38:10 +02:00
|
|
|
return (bool) ($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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|