Merge branch 'dev' of codeberg.org:streams/streams into dev

This commit is contained in:
Mike Macgirvin 2024-07-30 05:51:39 +10:00
commit c36de06026
4 changed files with 50 additions and 140 deletions

View file

@ -40,7 +40,7 @@ class dba_pdo extends dba_driver
$dsn .= ';charset=utf8mb4';
}
if ($this->driver_type === 'pgsql' && !strpos($dsn,'client_encoding')) {
if ($this->driver_dbtype === 'pgsql' && !strpos($dsn,'client_encoding')) {
$dsn .= ";options='--client_encoding=UTF8'";
}

View file

@ -3,10 +3,10 @@
namespace Code\ActivityStreams;
class ASObject
use Code\Lib\BaseObject;
class ASObject extends BaseObject
{
public $string;
public $ldContext;
public $id;
public $type;
public $attachment;
@ -70,49 +70,6 @@ class ASObject
return $this;
}
/**
* @param $input
* @param $strict
* @throws UnhandledElementException if $strict
*/
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
*/
public function getLdContext()
{
return $this->ldContext;
}
/**
* @param mixed $ldContext
* @return ASObject
*/
public function setLdContext($ldContext)
{
$this->ldContext = $ldContext;
return $this;
}
/**
* @return mixed
*/
@ -816,27 +773,4 @@ class ASObject
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;
}
}

View file

@ -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;
}
}

View file

@ -2,12 +2,14 @@
namespace Code\Lib;
use Code\ActivityStreams\UnhandledElementException;
class BaseObject
{
public $string;
public $ldContext;
/**
* @param $input
* @param $strict
@ -16,50 +18,63 @@ class BaseObject
public function __construct($input = null, $strict = false)
{
if (isset($input) && is_array($input)) {
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;
}
public function getDataType($element, $object = null)
{
if (is_null($object)) {
$object = $this;
$object = $object ?? $this;
$type = gettype($object[$element]);
if ($type === 'array' && array_is_list($object[$element])) {
return 'list';
}
if (!isset($object[$element])) {
return 'null';
return $type;
}
if (is_string($object[$element])) {
return 'string';
}
if (is_array($object[$element])) {
if (array_is_list($object[$element])
|| empty($object[$element])) {
return 'array';
} else {
return 'object';
}
}
return 'other';
}
public function toArray()
{
if ($this->string) {
return $this->string;
}
$returnValue = [];
foreach ((array) $this as $key => $value) {
if (isset($value)) {
$key = ($key === 'ldcontext') ? '@context' : $key;
$returnValue[$key] = $value;
$key = ($key === 'ldContext') ? '@context' : $key;
$returnValue[$key] = (($value instanceof BaseObject) ? $value->toArray() : $value);
}
}
return $returnValue;
}
/**
* @return mixed
*/
public function getLdContext()
{
return $this->ldContext;
}
/**
* @param mixed $ldContext
* @return BaseObject
*/
public function setLdContext($ldContext)
{
$this->ldContext = $ldContext;
return $this;
}
}