| Server IP : 104.21.84.107 / Your IP : 104.23.197.208 Web Server : Apache/2.4.63 (Ubuntu) System : Linux adminpruebas-Virtual-Machine 6.14.0-37-generic #37-Ubuntu SMP PREEMPT_DYNAMIC Fri Nov 14 22:10:32 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.4.5 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/pregrados/medicina-veterinaria-zootecnia/libraries/regularlabs/src/ |
Upload File : |
<?php
/**
* @package Regular Labs Library
* @version 23.12.10783
*
* @author Peter van Westen <[email protected]>
* @link https://regularlabs.com
* @copyright Copyright © 2023 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
namespace RegularLabs\Library;
defined('_JEXEC') or die;
use DeepCopy\DeepCopy;
require_once dirname(__FILE__, 2) . '/vendor/autoload.php';
class ObjectHelper
{
/**
* Change the case of object keys
* $key_format: 'camel', 'dash', 'dot', 'underscore'
*/
public static function changeKeyCase(
object|array|null $object,
$format,
bool $to_lowercase = true
): object
{
return (object) ArrayHelper::applyMethodToKeys(
[$object, $format, $to_lowercase],
'\RegularLabs\Library\StringHelper',
'toCase'
);
}
/**
* Deep clone an object
*/
public static function clone(object $object): object
{
return (new DeepCopy())->copy($object);
}
/**
* Return the value by the object property key
* A list of keys can be given. The first one that is not empty will get returned
*/
public static function getValue(
object $object,
string|array $keys,
mixed $default = null
): mixed
{
$keys = ArrayHelper::toArray($keys);
foreach ($keys as $key)
{
if (empty($object->{$key}))
{
continue;
}
return $object->{$key};
}
return $default;
}
/**
* Merge 2 objects
*/
public static function merge(object $object1, object $object2): object
{
return (object) [...(array) $object1, ...(array) $object2];
}
/**
* Replace key names
*/
public static function replaceKeys(
string|object $object,
array $replacements,
bool $include_prefixes = false,
string $prefix_delimiter = '_'
): string|object
{
$json = json_encode($object);
foreach ($replacements as $to => $froms)
{
if ( ! is_array($froms))
{
$froms = [$froms];
}
foreach ($froms as $from)
{
$json = str_replace(
'"' . $from . '":',
'"' . $to . '":',
$json
);
if ( ! $include_prefixes)
{
continue;
}
$json = RegEx::replace(
'"' . RegEx::quote($from . $prefix_delimiter) . '([^"]+":)',
'"' . $to . $prefix_delimiter . '\1',
$json
);
}
}
return json_decode($json);
}
}