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:----ADWWekKdDuwTZW2laA/iYMs24nInluQT9oyK2N346CTzTdBZN86nGP3NioF9FosJ5/qk72vF57NqdLtLaNPYH+ZeuhEO1RMFycHQ741NcHacWhnJgA9+ztt17BhWifs5obR9dmEtXdm7+qWopK+td7SRfXZ53kHRvMf0SjSzuRdKXr72nfus18ZbD25+jNc6Nhxy1BpviFWnMpZbW+Pd9r1R0SzUemLgDQRpLsvZM/rqF5d/Pg4eO4HOBfiFb8R9vlIhejqv+zjtfyH6jYr9oQGq3TNskcDEaf9fi/zDPfAAhe4dk6Ml8qO6l2BcahtfCoY2ZGzuFaFW0Yrl6iCSgVI9wERZ7mvtAyXqb/BUqanujEIBMa+Q2qle889XZGNXUfqC2Nr34gQyX1/HOXV1bEGAWEik2AU57p2KS2N3V3JXXBwIsNDJzzVttoMa4cKPAgyc/arWBrv3Vsth246RSaKMJ7ReNARk11nHtkbrGbpl3hrheI74uP0w7d+0IJ4Pjmjp6RP2YhQ8vcE3TdvH3gyikt4CX6xWXxYORYGE0tM3nCK9bYxOks1xMoZ2wK2ciTjbRmQ1PwfLxJlAZJRfEQWq2PX/CLq+jZavBW3M3xwTbh7y2TTFTajOIws2tJFoZMfWvihn1HutHuF7J4O/Qs4NtqeMSmOj+15jf5mWkLo=----ATTACHMENT:----OTg2Njc3MjMwMTg2MzQ5OCA0OTk5MTU3MzU0NzA1OTMwIDEwMjczMDk4NjAzNDcwODU=