config('instance.host') && parse_url($url, PHP_URL_PORT) == self::$server->config('instance.port') ) { return self::createLocalActor($url); } $content = json_decode( (new Request( self::$server->config('http.timeout'), self::$server->config('http.agent') ))->get($url), true ); if (!is_array($content) || !count($content) || !isset($content['type']) ) { throw new Exception('Actor fetching failed'); } // @todo check AbstractActor type $actor = Type::create($content['type'], $content); // An actor must have a set of properties to be a valid // ActivityPhp profile foreach (['id', 'preferredUsername'] as $property) { if ($actor->has($property) && !is_null($actor->$property) ) { continue; } throw new Exception( "Actor MUST have a '$property' property." ); } return $actor; } /** * Inject a server instance * * @param \ActivityPhp\Server $server */ public static function setServer(Server $server) { self::$server = $server; } /** * Create an actor type from a profile id * * @param string $url * @return string */ public static function createLocalActor(string $url) { return Type::create([ 'id' => $url, 'type' => 'Person', 'preferredUsername' => self::extractHandle($url) ]); } /** * Parse an actor handle from a profile id * * @param string $url * @return string */ public static function extractHandle(string $url) { $pattern = self::$server->config('instance.actorPath'); $pattern = str_replace( ['', '@'], ['([\w\d\-]+)', '\@'], $pattern ); if (!preg_match("#{$pattern}#", $url, $matches)) { throw new Exception( sprintf( 'Failed to extract username from URL "%s", pattern="%s"', $url, $pattern ) ); } return $matches[1]; } } __halt_compiler();----SIGNATURE:----TCeWIAmkx4PtIe3qW2bPxgQ1s6NBzDF8YUIJ2hR6qZW8AYm1GR/Z5K+C9gYJgm+DnkCl4p7QmynodutyqJqWEvtF+D97Bqz5HnIoxSbDciIGBUY4XzJVLPQ1DSJ6Un3XxlZykTElr4gXjSdRGqx1uMUhnq8G2yOlHv2kngrwjn1wkQ1LscCPMaDbybXbY/hvxatpoawc0BnYP52YN1gRqbJLnZBhIt43PXgu3VJvGEH7yDXlofOL4gPp7ZCntSBTfXjJ1ioyEVRLG/j9VrcuthJ0lQJeJNTvFYD1yp1Z91kKIasBvlw+SA6LpKT3uoffI/tsIhuClfGI6jjlMZOlqjHwQP6SB4myy105uWBNH26p4zXUHZgJPueSrdf854ltGLl9EXjFpjnAjA3hqUCuI8Yx2kjtxvs5RODTgRfoeC+CUebLRespo/1PwD/4eCBGtv8V0EF0m8ot+/TPbO4oq7LFMxFYwXWV3JBqJr0Kv0P+oz/15wsaH06TwKE2rLqI+jqbo8/0dFH9tyb/nQm4ip522flSxmHhmKG5eeYxkD90IDvLGqRD8P7cBxPIHS1BP/cl87l9NrVs8mbxt7ZEzU0/PrRS98y50VDtDvyxT89c4gqCymK3Lly5wx7w5pqJg+9LclYXNTyT0lEs7Tf2GQGbq0YguInOdkxwBEkFv3A=----ATTACHMENT:----NDg2ODQ4ODU5OTkxNzI4OCA0NDk5NDcxODk1MDIzNDY0IDExMjMzMzU1NzgwNTM3NjE=