Coder Social home page Coder Social logo

laravel-webfinger's Introduction

Create a Webfinger in Laravel

This creates a webfinger, a way to attach information to an email address, or an other online resource. Once installed you should see your JSON webfinger profile at /.well-known/webfinger.

Installation

You can install the package via composer:

composer require surface/laravel-webfinger

You must add the configuration to your .env file:

WEBFINGER_INSTANCE=mastodon.instance
WEBFINGER_USERNAME=your-username

You can publish the config file with:

php artisan vendor:publish --provider="Surface\LaravelWebfinger\LaravelWebfingerServiceProvider"

Extending the Resource

The resource which is converted to the JSON response is bound to the service container. This allows you to easily override the resource and add extra information. To change the binding, add the following to your app service provider.

use App\Http\Resources\Webfinger as WebfingerResource;
use Surface\LaravelWebfinger\Http\Resources\Webfinger as PackageWebfinger;
use Surface\LaravelWebfinger\Service\Webfinger as WebfingerService;

$this->app->bind(
    PackageWebfinger::class,
    static fn (Container $app): WebfingerResource => new WebfingerResource(
        ...$app->make(WebfingerService::class)
    )
);

Then you would create your custom resource which extends the base.

<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Support\Stringable;
use Surface\LaravelWebfinger\Http\Resources\Webfinger as JsonResource;

class Webfinger extends JsonResource
{
    protected string $website;

    public function __construct(protected Stringable $instance, protected Stringable $username)
    {
        parent::__construct($instance, $username);

        $this->website = 'https://www.example.com';
    }

    public function links(Request $request): array
    {
        return [
            ...parent::links($request),
            [
                'rel' => 'self',
                'type' => 'text/html',
                'href' => $this->website,
            ],
        ];
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.