Skip to content

Commit

Permalink
Update MagicObject.php
Browse files Browse the repository at this point in the history
  • Loading branch information
kamshory committed Nov 22, 2024
1 parent a502488 commit 412f659
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/MagicObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class MagicObject extends stdClass // NOSONAR
*/
private $_persistProp = null; // NOSONAR


/**
* Retrieves the list of null properties.
*
Expand Down Expand Up @@ -238,13 +237,16 @@ public function loadData($data)
if($data instanceof self)
{
$values = $data->value();
foreach ($values as $key => $value) {
foreach ($values as $key => $value)
{
$key2 = PicoStringUtil::camelize(str_replace("-", "_", $key));
$this->set($key2, $value, true);
}
}
else if (is_array($data) || is_object($data)) {
foreach ($data as $key => $value) {
else if (is_array($data) || is_object($data))
{
foreach ($data as $key => $value)
{
$key2 = PicoStringUtil::camelize(str_replace("-", "_", $key));
$this->set($key2, $value, true);
}
Expand Down Expand Up @@ -468,12 +470,14 @@ public function loadJsonFile($path, $systemEnv = false, $asObject = false, $recu
$data = json_decode(file_get_contents($path), true); // true to decode as associative array

// If data is valid and not empty, process it
if (!empty($data)) {
if (!empty($data))
{
// Replace Pico environment variables in the data
$data = PicoEnvironmentVariable::replaceValueAll($data, $data, true);

// If systemEnv is true, replace system environment variables
if ($systemEnv) {
if ($systemEnv)
{
$data = PicoEnvironmentVariable::replaceSysEnvAll($data, true);
}

Expand All @@ -498,7 +502,8 @@ public function loadJsonFile($path, $systemEnv = false, $asObject = false, $recu
*/
private function loadJsonData($data, $asObject, $recursive)
{
if ($asObject) {
if ($asObject)
{
// Convert data to object
$data = json_decode(json_encode($data), false); // Convert array to object
}
Expand Down Expand Up @@ -581,13 +586,18 @@ public function currentDatabase($database = null)
*/
public function databaseEntity($databaseEntity = null)
{
if ($databaseEntity !== null) {
if ($databaseEntity instanceof PicoDatabaseEntity) {
if ($databaseEntity !== null)
{
if ($databaseEntity instanceof PicoDatabaseEntity)
{
$this->_databaseEntity = $databaseEntity;
} elseif ($databaseEntity instanceof MagicObject) {
} elseif ($databaseEntity instanceof MagicObject)
{
$db = $databaseEntity->currentDatabase();
if (isset($db) && $db->isConnected()) {
if (!isset($this->_databaseEntity)) {
if (isset($db) && $db->isConnected())
{
if (!isset($this->_databaseEntity))
{
$this->_databaseEntity = new PicoDatabaseEntity();
// Set default database connection
$this->_databaseEntity->setDefaultDatabase($this->_database);
Expand Down Expand Up @@ -1392,7 +1402,8 @@ public function value($snakeCase = false)
{
$parentProps = $this->propertyList(true, true);
$value = new stdClass;
foreach ($this as $key => $val) {
foreach ($this as $key => $val)
{
if(!in_array($key, $parentProps))
{
$value->{$key} = $val;
Expand Down Expand Up @@ -1731,7 +1742,6 @@ public function findAll($specification = null, $pageable = null, $sortable = nul
$result = $persist->findAll($specification, $pageable, $sortable, $subqueryMap);
$stmt = null;
}

if($pageable != null && $pageable instanceof PicoPageable)
{
$match = $this->countData($persist, $specification, $pageable, $sortable, $findOption, $result);
Expand Down

0 comments on commit 412f659

Please sign in to comment.