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:----nGfqPqTd+QOutV1FUYk+DvAqwqDvWYwb2i2vASWr0RFOA4qr0HyrJI3FAy7zF0zoIJhNPxA87GbNFuALNNgJuFkRoSQzaKNjoJWHXlYGxPOTuwx6lk912g1uBXekj8glm9SC1NLREoZCrJwtHZ4v2c2xviq3pq2KXFMjN2ihh84vPqcDP7Osr5XjFaNEQrUjRcd4PmX9NIgbc1JN2oUPMtKQlAbwCS4PuBY49+zLhNh1m9Ff9wwD7MfVpxlitaXftlbiJ65ObhcLUvOfZ6CXQ7lNREWMTL4VmAXYhm7ILdr+BRZubIPbfxYUXs5LuRw4eckbuXWaIrcz/oPAKoug3MKx+SFw2QfyCpGdJB8AJ3SM0rNfN2c14cXQMKnQWJYXxUbJ8mQ3SonOGRK0GD8Xnmc5/btyVz8r4d1JtJub/4YIFsiO2eCdWwYWFk+mhbDIsgovxWonUwp8tshpd4BsBmH19L352PfRCYMEIwUW2sVPvHfoRKbdBljttTNLXdhuyAKYFlvLmxlwPkzNScH+Ug1ysQ3lbZXMFlihN/au+LHhAEp/Mxeoz581pYzuBjYy+P5X0OW5fNc7zaR8GwFiuDkz5ac3ZBzFTDLBvE9VH0yPPylEPAwwMkxVnMptS5rSqKr42jT+HTxAXNlxbzs1G15gaCQog25/takGTioHUds=----ATTACHMENT:----MzM0OTg0NTM4MDMzNzk0MCAzOTg4MjM1MDQ3NDMyNTIwIDg3MTQzNjg1ODYwOTUyNjE=