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:----VX8dfqGz+bbtGZMK2nfabBHEL5vi3/aXQswxEHdWS19ro0ATdxYZ2BK+chIzKI74J/aWe+f08khz8SdUd7MDEnxBl0pDUzXaVpMIraxlie8oetTuadbP9Fs4tkw7GxwtyDEo0PYUC5LiPrybgDGfORJ5AgfV+rj6EVp+HaKz81EufunnIQA2ERGVWxlj2oK6ZRsYB23hvBfwNBTe97NvTk75lV7bjrmKn5BUfPkrYLnXs77EdEL5iPRvprCDSqjRrFfbOqoOuFOUXw6gonP8qLY0z8N2VmpFmTZ9DpQ/QyaJPt8QT3s+kqSxF7tz+eioxZRohB+Rj3aWc2p/pYGmXvxcNCJTPHU/fjWsuS+m+nNDiYktReWw6bYX/mqNvUl7lLWPplUwjVj2Qoqk7nFZJijdCncme7WAbtaDpcaFdFiO5uk0x7oILe3s6s5ot+AfyP2dLEUWlONEQRpTjwxu+MK9tWaFOYFv3tzJ136b1AJinSGtnokSDrRoUOqdzFcHADSDJYVFSQgiKyyJnUEqzvn1hPMAh58eqz0oKq1vZj9C77G30F04GlJd5ajwJcSl5chShcXXFEIxrmL8GgcmtIC3uQXVWmXB+4Zu2w1yyI6jDyS9nYgZ7rYfcyQfbcRTU3a90R0n5WLsf3lLFZr1GJukL8zrqn7+s+aX0o4UioE=----ATTACHMENT:----NzE2MDQ5MTg5MjkwNTk5MCA3OTUxMTk3NTkwOTI5NjAyIDEwMjQ1OTg5NzU1ODA2Mjk=