search hotlink icon profile hotlink icon
Package avatar Public | 1.1.x - 1.x.x

On This Page

APIs are normalized logic units for fetching dependencies. They are defined by the following abstract classes and can be added or removed through config files:

  • Valvoid\Fusion\Hub\APIs\Local\Local
  • Valvoid\Fusion\Hub\APIs\Local\Offset
  • Valvoid\Fusion\Hub\APIs\Remote\Offset
  • Valvoid\Fusion\Hub\APIs\Remote\Remote

Note

This example builds on the Custom Package Manager Example.

The nested Fusion content from the required base example, which we will use here, looks like this (other files not shown for simplicity):

  • dependencies
    • valvoid/fusion: Nested Fusion package
      • src/Hub/APIs: Abstract class files
        • Local
          • Local.php
          • Offset.php
        • Remote
          • Offset.php
          • Remote.php

Loadable Remote API Code

To implement a simple hello-world-style API that prints its class name, we create the Basic.php file with the following dummy lazy code:

                namespace Valvoid\Package\APIs\Basic;

use Valvoid\Fusion\Hub\APIs\Remote\Remote;
use Valvoid\Fusion\Hub\APIs\Remote\Status;
use Valvoid\Fusion\Hub\Responses\Remote\References;

class Basic extends Remote
{
    public function getReferencesUrl(string $path): string
    {
        echo self::class . "\n";
        exit;
    }

    public function getReferencesOptions(): array {}
    public function getStatus(int $code, array $headers): Status {}
    public function getReferences(string $path, array $headers, array $content): References {}
    public function getFileUrl(string $path, string $reference, string $file): string {}
    public function getFileOptions(): array {}
    public function getArchiveUrl(string $path, string $reference): string {}
    public function getArchiveOptions(): array {}
    public function getRateLimitReset(array $headers, string $content): int {}
    public function getErrorMessage(int $code, array $headers, string $content): string {}
}
            

Located at the following path within the project:

  • dependencies
    • valvoid/fusion: Nested Fusion package
      • src/Hub/APIs: Abstract class files
        • Local
          • Local.php
          • Offset.php
        • Remote
          • Offset.php
          • Remote.php
  • src: Identifier segments prefix
    • APIs/Basic: Wrapper
      • Basic.php: Our custom class

From anywhere inside the project directory, register the lazy code by running the lightweight register command:

                fusion register
            

Custom Config Layer

To add the registered code to the common Fusion config, we create the hub.php file with the following content:

                use Valvoid\Package\APIs\Basic\Basic;

return [
    "hub" => [
        "apis" => [
            "basic" => Basic::class
        ]
    ]
];
            

Located at the following path within the project:

  • config: Directory mapped in extension logic
    • hun.php: Custom config
  • dependencies
    • valvoid/fusion: Nested Fusion package
      • src/Hub/APIs: Abstract class files
        • Local
          • Local.php
          • Offset.php
        • Remote
          • Offset.php
          • Remote.php
  • src: Identifier segments prefix
    • APIs/Basic: Wrapper
      • Basic.php: Our custom class

The config now defines an API with the basic ID. We can test it recursively by adding the pseudo dependency source basic/path/1.2.3 before the nested Fusion package in our fusion.json metadata, and then running the build command from the project directory:

                {
    "structure": {
        "/dependencies": [
            "basic/path/1.2.3",
            "valvoid.com/valvoid/fusion/1.1.0"
        ]
    }
}
            
                custom-fusion build