Skip to content

Commit

Permalink
made PHP compatible with 8
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Feb 22, 2021
1 parent edfbbb0 commit 04d47d5
Showing 1 changed file with 9 additions and 27 deletions.
36 changes: 9 additions & 27 deletions php/flatted.php
Expand Up @@ -3,7 +3,7 @@
/*!
* ISC License
*
* Copyright (c) 2018-2020, Andrea Giammarchi, @WebReflection
* Copyright (c) 2018-2021, Andrea Giammarchi, @WebReflection
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -60,7 +60,7 @@ public static function stringify($value, $options = 0, $depth = 512) {
}

// private helpers
private static function asString(&$value) {
private static function asString($value) {
return $value instanceof FlattedString ? $value->value : $value;
}

Expand All @@ -76,42 +76,25 @@ private static function keys(&$value) {
$obj = new ReflectionObject($value);
$props = $obj->getProperties();
$keys = array();
foreach ($props as $prop) {
foreach ($props as $prop)
$keys[] = $prop->getName();
}
return $keys;
}

private static function loop($obj, $keys, &$input, &$set, &$output) {
foreach ($keys as $key) {
$value = $obj ? $output->$key : $output[$key];
if ($value instanceof FlattedString) {
if ($value instanceof FlattedString)
Flatted::ref($obj, $key, $input[$value->value], $input, $set, $output);
}
}
return $output;
}

private static function relate(&$known, &$input, &$value) {
if (is_string($value)) {
$key = array_search($value, $known->key, true);
if ($key !== false) {
return $known->value[$key];
}
return Flatted::index($known, $input, $value);
}
if (is_array($value)) {
if (is_string($value) || is_array($value) || is_object($value)) {
$key = array_search($value, $known->key, true);
if ($key !== false) {
if ($key !== false)
return $known->value[$key];
}
return Flatted::index($known, $input, $value);
}
if (is_object($value)) {
$key = array_search($value, $known->key, true);
if ($key !== false) {
return $known->value[$key];
}
return Flatted::index($known, $input, $value);
}
return $value;
Expand All @@ -137,7 +120,7 @@ private static function ref($obj, &$key, &$value, &$input, &$set, &$output) {
private static function transform(&$known, &$input, &$value) {
if (is_array($value)) {
return array_map(
function (&$value) use(&$known, &$input) {
function ($value) use(&$known, &$input) {
return Flatted::relate($known, $input, $value);
},
$value
Expand All @@ -146,15 +129,14 @@ function (&$value) use(&$known, &$input) {
if (is_object($value)) {
$object = new stdClass;
$keys = Flatted::keys($value);
foreach ($keys as $key) {
foreach ($keys as $key)
$object->$key = Flatted::relate($known, $input, $value->$key);
}
return $object;
}
return $value;
}

private static function wrap(&$value) {
private static function wrap($value) {
if (is_string($value)) {
return new FlattedString($value);
}
Expand Down

0 comments on commit 04d47d5

Please sign in to comment.