mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 16:15:13 +00:00
refactor Link-derived objects
This commit is contained in:
parent
19bcfd0de2
commit
5c8584ef00
1 changed files with 3 additions and 42 deletions
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace Code\ActivityStreams;
|
||||
|
||||
class Link
|
||||
use Code\Lib\BaseObject;
|
||||
|
||||
class Link extends BaseObject
|
||||
{
|
||||
public $type;
|
||||
public $href;
|
||||
|
@ -15,24 +17,6 @@ class Link
|
|||
public $preview;
|
||||
|
||||
|
||||
public function __construct($input = null, $strict = false)
|
||||
{
|
||||
if (isset($input)) {
|
||||
if (is_string($input)) {
|
||||
$this->string = $input;
|
||||
}
|
||||
elseif(is_array($input)) {
|
||||
foreach ($input as $key => $value) {
|
||||
$key = ($key === '@context') ? 'ldcontext' : $key;
|
||||
if ($strict && !property_exists($this, $key)) {
|
||||
throw new UnhandledElementException("Unhandled element: $key");
|
||||
}
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
|
@ -52,8 +36,6 @@ class Link
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
|
@ -198,25 +180,4 @@ class Link
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
if ($this->string) {
|
||||
return $this->string;
|
||||
}
|
||||
$returnValue = [];
|
||||
foreach ((array) $this as $key => $value) {
|
||||
if (isset($value)) {
|
||||
$key = ($key === 'ldcontext') ? '@context' : $key;
|
||||
if ($value instanceof ASObject || $value instanceof Link) {
|
||||
$returnValue[$key] = $value->toArray();
|
||||
}
|
||||
else {
|
||||
$returnValue[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $returnValue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue