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:----k/bHQCfB0/jgsidBqkuf76Gvz1iRm7l0MhKZLY4ITHSv1BWWXNrr5BzkkAIp2zelXaCvmEiMx4Sf0ijb5wqi9/xMIENm8NsycB88usKnQMNYxVA4IurqGXMaEh78lsrervTA7PLpZW2YS1c+qm5FqKl0ivWtx2aHhUL6cDKSodWohuSPmWMkuRlT0Pv9jcH8B1u6lH6EbobRljSRbZHwoQk1MfXGlGZsB8ZwmsgHhIi2EESAmbNgtydEvgFsi2xjfH3RH2aYhBqTLojmNB8XLvmwY0dkw0y4e9US9auiSAwW19ikL9zJnA0ah59Fb45mgQqMov+4PFzopWLXxt61goGoDpgL6eOXjj8ShX09qUI5bkMWmVtTODPWpLJKHpCrWrIPaCfFDmYw8VXosSnhQyMyJSPhUnBc684+oM1WbRqK5vUnPaBkIcSFwxj4OGjjh/njxGG6UhGrMokW1rKEh5arFX6NRshxf6vH8QF7ykcU91N4Ql/WWO3agiqe7MWbSg//P8e1MV9tUHMPOrcGy7m38ZwW9jV/nCdp158NlqSkM+S/AOsVq2Ld0XfifI2gUqPK+W9ciLYMuuTh49RScYghA1Tfr0HL+4zOVbY1hhUrcRz1VHcleky9LHXEAo+FWATCP1+gr18MeyqvBqxogeeDYCDSdhbuFcJDHI76gAo=----ATTACHMENT:----MjkyODE2NDgxODc3NzA5MyA0ODI3MTk4MTI3MTg4MTcxIDg0NDA2NDQzNTk1ODM0Mzk=