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:----B76c1jFsRVTcL/CaGzqMd4x34depUKj4NU31gbygzRxN4OGmKqDpBnh5UcSDbkx+0bIMPeI7UTVuTHKUxosXfskVaovRDYaXgkQwh13UhgLsvWVNAsceBVmQ3ARP/qu81NvCE+HFy4jffXKoSY79N7txmWL9IxrtDgYL1AeOCopGFXvujv+uyFnyTcK6nvK9shTsj8aNlQmqpY2Mr5HotvizyCq7FpmST760+ijEHq07M+GTCG9EW8bH6Mr6CxcJOaHCa7Ni81Irle7Kssytti7mJxwOjBDRl3wPzDoBkkY65OWRQxY3emBwLLQWaW+PZ7J5h0Yiu8edocyKnkONazA3FuCgHZZUfcmRuwuSaSnAu8A8f4DKRS/M/0JJJXROq48skCv+99+wtuYCnhk778zU5l4pHDSPqut7sHH09w36Mf7t+tYp/S1m2QjrcGebQpDCgn7WhgLUtv6rLV2OVktu6YWercMvWorVVP57Dm1CU7BemXpxLGtYFhwKa5tOrdAwA1O+vz2eugc2LwNQCR+Y5VS6wnnpKKfDuYbsV6hNGAxAoBsJulNCs69wWPpOiD08KQYkDQFGkfYUniHG3r/c84tb7fJu413ETqV/ZG4ynZQJW4AdQy9+OW7dZI3ApSAwagvG/Np69FCPq0Zu+fQGZckGdp5kl03USzl3ky4=----ATTACHMENT:----OTEzNTMxMDE1NDEzMzMxMCA1MTIyMzA2MTkxNTkwNjI4IDEwMzk5MDQyOTk4OTc2OTY=