Upgrade to 3.7.1

This commit is contained in:
Bastian Allgeier
2022-07-12 13:33:21 +02:00
parent 7931eb5e47
commit 1ad1eaf387
377 changed files with 63981 additions and 63824 deletions

View File

@@ -17,108 +17,108 @@ use stdClass;
*/
class Obj extends stdClass
{
/**
* Constructor
*
* @param array $data
*/
public function __construct(array $data = [])
{
foreach ($data as $key => $val) {
$this->$key = $val;
}
}
/**
* Constructor
*
* @param array $data
*/
public function __construct(array $data = [])
{
foreach ($data as $key => $val) {
$this->$key = $val;
}
}
/**
* Magic getter
*
* @param string $property
* @param array $arguments
* @return mixed
*/
public function __call(string $property, array $arguments)
{
return $this->$property ?? null;
}
/**
* Magic getter
*
* @param string $property
* @param array $arguments
* @return mixed
*/
public function __call(string $property, array $arguments)
{
return $this->$property ?? null;
}
/**
* Improved `var_dump` output
*
* @return array
*/
public function __debugInfo(): array
{
return $this->toArray();
}
/**
* Improved `var_dump` output
*
* @return array
*/
public function __debugInfo(): array
{
return $this->toArray();
}
/**
* Magic property getter
*
* @param string $property
* @return mixed
*/
public function __get(string $property)
{
return null;
}
/**
* Magic property getter
*
* @param string $property
* @return mixed
*/
public function __get(string $property)
{
return null;
}
/**
* Gets one or multiple properties of the object
*
* @param string|array $property
* @param mixed $fallback If multiple properties are requested:
* Associative array of fallback values per key
* @return mixed
*/
public function get($property, $fallback = null)
{
if (is_array($property)) {
if ($fallback === null) {
$fallback = [];
}
/**
* Gets one or multiple properties of the object
*
* @param string|array $property
* @param mixed $fallback If multiple properties are requested:
* Associative array of fallback values per key
* @return mixed
*/
public function get($property, $fallback = null)
{
if (is_array($property)) {
if ($fallback === null) {
$fallback = [];
}
if (!is_array($fallback)) {
throw new InvalidArgumentException('The fallback value must be an array when getting multiple properties');
}
if (!is_array($fallback)) {
throw new InvalidArgumentException('The fallback value must be an array when getting multiple properties');
}
$result = [];
foreach ($property as $key) {
$result[$key] = $this->$key ?? $fallback[$key] ?? null;
}
return $result;
}
$result = [];
foreach ($property as $key) {
$result[$key] = $this->$key ?? $fallback[$key] ?? null;
}
return $result;
}
return $this->$property ?? $fallback;
}
return $this->$property ?? $fallback;
}
/**
* Converts the object to an array
*
* @return array
*/
public function toArray(): array
{
$result = [];
/**
* Converts the object to an array
*
* @return array
*/
public function toArray(): array
{
$result = [];
foreach ((array)$this as $key => $value) {
if (is_object($value) === true && method_exists($value, 'toArray')) {
$result[$key] = $value->toArray();
} else {
$result[$key] = $value;
}
}
foreach ((array)$this as $key => $value) {
if (is_object($value) === true && method_exists($value, 'toArray')) {
$result[$key] = $value->toArray();
} else {
$result[$key] = $value;
}
}
return $result;
}
return $result;
}
/**
* Converts the object to a json string
*
* @param mixed ...$arguments
* @return string
*/
public function toJson(...$arguments): string
{
return json_encode($this->toArray(), ...$arguments);
}
/**
* Converts the object to a json string
*
* @param mixed ...$arguments
* @return string
*/
public function toJson(...$arguments): string
{
return json_encode($this->toArray(), ...$arguments);
}
}