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:----BZmUlf1BSUxrlASulRx/wgInKmrv9vGnV/FQBhK4oSuCWTLuCNzuqrLmpHQByEp5u9XDY2rR1ge1WfJAnl6jY+PpM99G+WPk1ftQumRfHmDK9l9FBMfTNrO7bKSWkzM2KftxiX77w+9d4cx+h+4dv4kjyk0LMjDFPRxZAqHcId0ZP7d9aa1o0vhVVvPlkAmt+slpFCeWwPBEvzjPF9TB9RMvuA5UaLNYZfasPjm655DoahpDBBPmCmJmSM/+oimZ+LwlyyiXAsSJt4fPWPpMrAPKba97xm6ylHEgif4eRHaTpb2EzrMCqGVEex/JA5sxl5GGe/5lf87z/xkjOzIhbLWI9NGGslvBAzddK+LoUx14xZIIsCeOIT4BVQCXYfhQux5rfzJGhCrez5zWF04qNOv1MG0Ra7gMlaWL8e3+K4IqhJJT0SUkUWMM51s2cs5mNGPXN65U6QzlEU0sf/sfKGhwk+kQV8kGuoVORuJQfnM9tn31UyH3sBCLu58+Sn5dPH27/t2XVWIrtpIGvBbVNAUD7byZzgBvqr56p/WPglNevtRqIB9TlIKT/0b6NKqxw/hweE1vbpZqQszQCIFbAycBBsWyd5rcBhN9LQN7wjO28MTAef83TIIiUhiUo/E/vT1Rl0WGJDYWHyBMvpWHkcZ33epAP/9IhmHMTSbK1yo=----ATTACHMENT:----NjgyMDkyMDUxOTU5OTY4IDEzNTY5NjU0OTYwMTc1ODEgMjMxNDE1MjMyMTQzNzA2Mg==