. */ namespace Component\FreeNetwork\Controller; use App\Core\Event; use function App\Core\I18n\_m; use App\Util\Exception\ClientException; use App\Util\Exception\NoSuchActorException; use Component\FreeNetwork\Util\Discovery; use Component\FreeNetwork\Util\WebfingerResource; use Component\FreeNetwork\Util\XrdController; use Symfony\Component\HttpFoundation\Request; /** * @package WebFingerPlugin * * @author James Walker * @author Mikael Nordfeldth * @author Diogo Peralta Cordeiro */ class Webfinger extends XrdController { protected $resource; // string with the resource URI protected $target; // object of the WebFingerResource class public function handle(Request $request): array { // throws exception if resource is empty $this->resource = Discovery::normalize($this->string('resource')); try { if (Event::handle('StartGetWebFingerResource', [$this->resource, &$this->target, $this->params()])) { Event::handle('EndGetWebFingerResource', [$this->resource, &$this->target, $this->params()]); } } catch (NoSuchActorException $e) { throw new ClientException($e->getMessage(), 404); } if (!$this->target instanceof WebfingerResource) { // TRANS: Error message when an object URI which we cannot find was requested throw new ClientException(_m('Resource not found in local database.'), 404); } return parent::handle($request); } /** * Configures $this->xrd which will later be printed. */ protected function setXRD() { $this->xrd->subject = $this->resource; foreach ($this->target->getAliases() as $alias) { if ($alias != $this->xrd->subject && !\in_array($alias, $this->xrd->aliases)) { $this->xrd->aliases[] = $alias; } } $this->target->updateXRD($this->xrd); } }