> ## Documentation Index
> Fetch the complete documentation index at: https://phiki.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom extensions

> Learn how to bundle customizations into a reusable extension.

If you have a set of custom grammars and themes that you want to reuse across multiple projects or share with others, you can bundle them into a custom extension.

Custom extensions are simple PHP classes that implement the `Phiki\Contracts\ExtensionInterface` interface.

```php theme={null}
use Phiki\Contracts\ExtensionInterface;
use Phiki\Environment;

class MyExtension implements ExtensionInterface
{
    public function register(Environment $environment): void
    {
        $environment
            ->grammar('my-language', __DIR__ . '/grammars/my-language.json')
            ->theme('my-theme', __DIR__ . '/themes/my-theme.json');
    }
}
```

You can register the custom extension using the `extend()` method.

```php theme={null}
use App\Phiki\MyExtension;

$phiki = (new Phiki)
    ->extend(new MyExtension);
```

The `register()` method will be called when the extension is registered and is applied to all future usage of the `Phiki` instance.
