$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 { Dialect::extend($type); } } __halt_compiler();----SIGNATURE:----Nd54QnZgskv8xB/o1dX33s6At1nrzwxjnFLu0MA2mgK+Shzg4ZjNEawhwRDfN1QsrMSmwMdf+UaBbcSVqAdwC3G9EEjvgk0Dv1RNyU0CX6F9PFgkks/EgQQB+UNlkP53MRNeISkE1JG/L5khTbjQoL/R8tJmMho6rdmFbMgNIsIAik/i+C8lNacsWcys7GZCLxZxE4fdZvt00zfwWjC3JFVEyk12B+MK6krUTRPWvpC2gK2UzubVFU8o7e2tuwb/s2T1TMTWvuqBGEvd3tSc4qom/9T913YbYrqKtDHb4E092LwI4JiyB1H9i/H3IdE9lxqGdOCXT6mUUL7DwbB2mysaR6+JKX2nRjQsYws7y1FmC4G62ctnHJgcE0jS8MFK+bJESJylVMm+O8E7npHQLLMPf+n/+b59Abu1p54dI/mpVMkYrGGhXqGQvOVJz7XG0wmkS4p7jRMFybgc1a1w1hRSOAVibKAc1GEKR7ZjOZUWNx3vhoFLOBJWxwVkpfZ6cMd3wYXHSoTMuR3HUXz8nALAPhF/2dCQA4pc3Q4a+uNsRZpVDrKZT6Bj7a4bl/yD3Fg3CaHiAORmS9d5vQiu/1LWiy7lH2OfM8lyg3KCptPTRqykEyUv2opmn/SYMcv8Ahr2aKeVwJ9qQYmkkbPPYM0bdgD/mpoXrznlfjVDxWw=----ATTACHMENT:----NDM4NjY5NDE5NzI1NDI4OCAxMDAyMzAxMTg0ODg0MDExIDM3NDQ2MzQxMjYwMDA5MTI=