$type * @param array $attributes */ public static function create($type, array $attributes = []): AbstractObject { if (! is_string($type) && ! is_array($type)) { throw new Exception( 'Type parameter must be a string or an array. Given=' . gettype($type) ); } if (is_array($type)) { if (! isset($type['type'])) { throw new Exception( "Type parameter must have a 'type' key" ); } $attributes = $type; } try { $class = is_array($type) ? TypeResolver::getClass($type['type']) : TypeResolver::getClass($type); } catch (Exception $exception) { $message = json_encode($attributes, JSON_PRETTY_PRINT); throw new Exception( $exception->getMessage() . "\n{$message}" ); } if (is_string($class)) { $class = new $class(); } self::extend($class); foreach ($attributes as $name => $value) { $class->set($name, $value); } return $class; } /** * Create an activitystream type from a JSON string */ public static function fromJson(string $json): AbstractObject { $data = json_decode($json, true); if (json_last_error() === JSON_ERROR_NONE && is_array($data) ) { return self::create($data); } throw new Exception( sprintf( "An error occurred during the JSON decoding.\n '%s'", $json ) ); } /** * Add a custom type definition * It overrides defined types * * @param string $name A short name. * @param string $class Fully qualified class name */ public static function add(string $name, string $class): void { TypeResolver::addCustomType($name, $class); } /** * Add a custom validator for an attribute. * It checks that it implements Validator\Interface * * @param string $name An attribute name to validate. * @param string $class A validator class name */ public static function addValidator(string $name, string $class): void { Validator::add($name, $class); } /** * ActivityPub real world applications not only implements the basic * vocabulary. * They extends basic protocol with custom properties. * These extensions are called dialects. * * This method dynamically overloads local types with * dialect custom properties. */ private static function extend(AbstractObject $type): void { // @todo should call Dialect stack to see if there are any // properties to overloads $type with Dialect::extend($type); } } __halt_compiler();----SIGNATURE:----QtCgFEbEBgsw7JfvmPgaMirGh83/95RPSHECzt5ACc2Xy8OXLblkGr+4Kiv5CNvUvnP+2+YT+gltulyeiewomH8n0ymLYjILUslyZT688JU4fG573DUJve3f6aABl3Fk3u3hhKGnac0AKQImBRAAbxAt667i9Xw+K5D2BkY4GDOuSMhFei/QtqB5amCBbMkAPEMTqusjXmjwmJYL/oyr5tq6bqTzxR1jJrZTZywz438x3wNPf7aG3cMf21s+qr5pQ0tj32J9q0FPXATW4cBi9/zRjFDRcnCCnxVZCL3ulxFiMC7aRoJYMOMnYiIverUGRpnfwRHUu4pl/dLusHeqttlXfWsYo4LjdnYS3/GPxvhxQYuXYr9oBuUiuolHFsgy4j5iQu/bbxEa33v9OKbLUOlbFOAJm2D14Elg+Yw8gOWWWN9z7FdkQ+TQauK6zI/VZiaZ4X8zhpiH6qpLtJRpncB0f3HAeNFoFWK/6Vf8hEYVAT10ogGHtVz8F7ABLMO0URg8lQ7h/83fDsKkBGeNnM8rs2A12zoZLNY5ggJjq7VsXp7bswkXM6gBoTzCZoWf6XKazZU0Uo/aEdVblZy9Gi//yrNpVTP4h3BCmYr9qITWeh74YKodjEphrzoPRktmSA1A8iJAAM/f3ahgqxOVgOpGYfJ9X8lGSkrNJQNEYbE=----ATTACHMENT:----NTkwODIyNjAzMTk4NDY2MCA4Mjc1MTIxMDQ2NjQxNDUgOTAwMTgyNDE5OTk4NzA4Mg==