[ActivityStreamsTwo] Introduce a structure for data representation in ActivityStreams 2.0
Type factory borrowed from landrok/activitypub
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Plugin\ActivityStreamsTwo\Util\Model\AS2ToEntity;
|
||||
|
||||
use App\Core\Security;
|
||||
use App\Entity\Note;
|
||||
use DateTime;
|
||||
|
||||
abstract class AS2ToNote
|
||||
{
|
||||
/**
|
||||
* @param array $args
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return Note
|
||||
*/
|
||||
public static function translate(array $args): Note
|
||||
{
|
||||
$map = [
|
||||
'isLocal' => false,
|
||||
'created' => new DateTime($args['published'] ?? 'now'),
|
||||
'rendered' => $args['content'] ?? null,
|
||||
'modified' => new DateTime(),
|
||||
];
|
||||
if (!is_null($map['rendered'])) {
|
||||
$map['content'] = Security::sanitize($map['rendered']);
|
||||
}
|
||||
|
||||
$obj = new Note();
|
||||
foreach ($map as $prop => $val) {
|
||||
$set = "set{$prop}";
|
||||
$obj->{$set}($val);
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user