mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 09:15:19 +00:00
47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Code\Lib;
|
||
|
|
||
|
|
||
|
use Code\ActivityStreams\UnhandledElementException;
|
||
|
|
||
|
class BaseObject
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* @param $input
|
||
|
* @param $strict
|
||
|
* @throws UnhandledElementException if $strict
|
||
|
*/
|
||
|
|
||
|
public function __construct($input = null, $strict = false)
|
||
|
{
|
||
|
if ($input) {
|
||
|
if (is_array($input)) {
|
||
|
foreach ($input as $key => $value) {
|
||
|
if (property_exists($this, $key)) {
|
||
|
$this->{$key} = $value;
|
||
|
} else {
|
||
|
if ($strict) {
|
||
|
throw new UnhandledElementException("Unhandled element: $key");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
public function toArray()
|
||
|
{
|
||
|
$returnValue = [];
|
||
|
foreach ((array)$this as $key => $value) {
|
||
|
if (isset($value)) {
|
||
|
$key = ($key === 'ldcontext') ? '@context' : $key;
|
||
|
$returnValue[$key] = $value;
|
||
|
}
|
||
|
}
|
||
|
return $returnValue;
|
||
|
}
|
||
|
}
|