mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 16:35:19 +00:00
Merge branch 'dev' of codeberg.org:streams/streams into dev
This commit is contained in:
commit
c36de06026
4 changed files with 50 additions and 140 deletions
|
@ -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'";
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
|
||||
namespace Code\Lib;
|
||||
|
||||
|
||||
use Code\ActivityStreams\UnhandledElementException;
|
||||
|
||||
class BaseObject
|
||||
{
|
||||
|
||||
public $string;
|
||||
public $ldContext;
|
||||
|
||||
/**
|
||||
* @param $input
|
||||
* @param $strict
|
||||
|
@ -16,12 +18,18 @@ class BaseObject
|
|||
|
||||
public function __construct($input = null, $strict = false)
|
||||
{
|
||||
if (isset($input) && is_array($input)) {
|
||||
foreach ($input as $key => $value) {
|
||||
if ($strict && !property_exists($this, $key)) {
|
||||
throw new UnhandledElementException("Unhandled element: $key");
|
||||
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;
|
||||
}
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
|
@ -29,37 +37,44 @@ class BaseObject
|
|||
|
||||
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';
|
||||
}
|
||||
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';
|
||||
return $type;
|
||||
}
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
if ($this->string) {
|
||||
return $this->string;
|
||||
}
|
||||
$returnValue = [];
|
||||
foreach ((array)$this as $key => $value) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue