$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:----WdU/OH8/6nEdvfWSyG+ip0OZVZprbcxRCz0rzJ1Qgl4fey9ncST7yk3LvPNPA7Q9Had8eATZksW3BnIpDsXm3SYw6nlBVnGVrWxofPqqy+wnSmnncKD3J0ZEB9Zgut4w4c1nN+fH97cdRPWD+s6pyisIpqfNEHXfTHLpOYGicaVicmpCoidk/bN7o3Ixi8BA0EoaLoQ7/MUgNeeCozf3XwrxBRHYlnEA9C7ZpGIOQuJdG88qzD2tdbi2HRxxCYEmPEe1m0W9u2/6/Owrwc+xti15ZIbaCVrZPv5ZpBzKok5iMKWxJip5t6/JkAUoAL9vvoTtOgwXj2VF95ZyX7vMziEBou52/0xN1pQi6IFcUY/F+XKn1CBS7bHtn0tQLMF0fntmIYNPq3WCcSYZaoSejcaE+vGmbQsWy7Q9ogR+WKmWgKMeOCZcGKQdZfthK5E3xgWZwZz5PETN2ezpVAT8etURdtWdWkcZf8qHUZYdAnDtLXTi1Zk207X/hArmBuKDqTxJRdVNsGhB9uOkTV7hJwMcTdKu+bs6hJBxu5jxU/OVz1QFMQFd5ZGIJr3y+BmUjBceCZsvV0HK0CKgOjx45PFIkqdCA+MgdiBeIgHDBpOHP+TsX3JnQ/bGT7h2c7/uQ/moAYzAen2x2JuBx7qmALMbBgQ+VYl8IlJafZpubaI=----ATTACHMENT:----OTAyODE0MTg4NjkzMTkyNyAzMDM0MTYxNDEyMjM3MDU5IDU2OTkxMzg5MTM3MzQwMA==