2019-02-17 11:34:46 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-02-17 11:34:46 +01:00
|
|
|
|
|
|
|
namespace App\DataMapper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ClientSettings
|
|
|
|
*/
|
|
|
|
class BaseSettings
|
|
|
|
{
|
|
|
|
|
2019-03-02 22:44:08 +01:00
|
|
|
public function __construct($obj)
|
|
|
|
{
|
|
|
|
foreach($obj as $key => $value)
|
2019-09-19 07:50:05 +02:00
|
|
|
$obj->{$key} = $value;
|
2019-02-17 11:34:46 +01:00
|
|
|
}
|
2019-03-02 22:44:08 +01:00
|
|
|
|
2019-09-19 07:50:05 +02:00
|
|
|
public static function setCasts($obj, $casts)
|
|
|
|
{
|
|
|
|
foreach ($casts as $key => $value)
|
|
|
|
$obj->{$key} = self::castAttribute($key, $obj->{$key});
|
|
|
|
|
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
2019-10-29 12:44:54 +01:00
|
|
|
public static function castAttribute($key, $value)
|
2019-09-19 07:50:05 +02:00
|
|
|
{
|
|
|
|
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':
|
|
|
|
return (bool)($value);
|
|
|
|
case 'object':
|
|
|
|
return json_decode($value);
|
|
|
|
case 'array':
|
|
|
|
case 'json':
|
|
|
|
return json_decode($value, true);
|
|
|
|
default:
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
2019-03-02 22:44:08 +01:00
|
|
|
|
2019-09-21 06:09:25 +02:00
|
|
|
public static function castSingleAttribute($key, $data)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-17 11:34:46 +01:00
|
|
|
}
|