mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-21 13:34:00 +00:00
25 lines
549 B
PHP
25 lines
549 B
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Segments\Services;
|
|
|
|
class AddItemToConstantValueArray
|
|
{
|
|
|
|
/**
|
|
* @param array|string|null $array
|
|
* @param $item
|
|
* @return array
|
|
*/
|
|
public function execute($array, $item): array {
|
|
// PHP 8.3: Ensure $array is always an array, even if JSON cast fails
|
|
// Handle cases where value might be empty string, null, or invalid JSON
|
|
if (!is_array($array)) {
|
|
$array = [];
|
|
}
|
|
|
|
$array[] = $item;
|
|
sort($array);
|
|
return $array;
|
|
}
|
|
|
|
} |