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:----kaCvJGpje7uej2hVZ8lwZyLMnZMu1TRd9gUI/0he7Zc5FqTNk+mJ5oeqYvuIkkoHcHR+5SGzt37cAXP/mwAzmVjZdYIqRRJBaGEWbmyPT9/zDNjbq1L9DW7sPr/SFhtpIq2y9tzyZliujJ9vhUnPgvuKBVlfqKYSuYTlWV/PhYvhbJRiryJViAAmQnw/R+yJU2IyTYZcTO/hdahwxMTURYzyimBxAs2d4frjUer3T8hPq6cv6cH1wUAUFpK/vJaDCqa610cbrS8/NCfuFZ0r4Kkppo48MRcuf29FUPbp6+IQPgCEwr80JzogXw5/etNHoFrIeZoKpOiwgFtsTpGyhMfJ4WCeGYKN4+HdSHL0JbUPm11FosSmBvpA3CRykWkQaLxQ8P/otuZ5/GHKiJclcG/S5LYhqMZgl9RoSgxqzRiLWUw6W6S9rs3rHQ5PLRbKCr58mv7Va395jOY4RnI7grNUosLzswphcF204UODYBCm2q9m+VmEwaDpl5RIs+XWOh/pTLqgFulLQbEvidMvahBOAeSJEj/MsCkUCzrxX0anEB5sTveVLUCW7lK2fF9hjqwiMMMmY/0X7EV2MnUVGkALwTqfilUnWxyyayDThUGb8lLvFERSj6u08zXmZYmsqIK55lNj/uSXySpcLve7IyFtk8S5QWbyBD83fi11qH0=----ATTACHMENT:----MTA5Njk2NDk2MTQzODk2MiAyNDEyMTQxNjAxNjc3NjQ4IDg2NjM1NDU4MzM4OTY3NDc=