Helper to rend HTML tags to load fonts from services like Google Fonts, Adobe Fonts and Fontawesome

Maintainers

Package info

github.com/straylightagency/php-fonts

pkg:composer/straylightagency/fonts

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2025-12-31 13:57 UTC

This package is auto-updated.

Last update: 2026-03-01 00:48:50 UTC


README

Helper to rendering HTML tags to load fonts from services like Google Fonts, Bunny Fonts, Adobe Fonts or FontAwesome.

Installation

Require this package with composer.

composer require straylightagency/fonts

Laravel without auto-discovery:

If you do not use auto-discovery, add the ServiceProvider to the providers array in bootstrap/providers.php :

Straylightagency\Fonts\Laravel\FontsServiceProvider::class,

Then add this line to your facades in config/app.php :

'Fonts' => Straylightagency\Fonts\Laravel\Fonts::class,

Usage

Without Laravel

This package can be used without Laravel. Just instantiate the FontsManager class as a regular object.

use Straylightagency\Fonts\FontsManager;

$fontsManager = new FontsManager;

You can inject the object in your favorite dependency container.

With Laravel

The package provides by default a Facade for Laravel application. You can call methods directly using the Facade or use the alias instead.

Print the tags based on the fonts you need through a driver :

@php
    use Straylightagency\Fonts\Laravel\Fonts;

    Fonts::googleV2('Oswald', ['300', '400'])
         ->googleV2('Open Sans', ['300..800'])
         ->googleV2('Chakra Petch', 'ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700')
         ->fontawesome('12b534g387')
         ->print();
@endphp

API Documentation

Examples bellow are using Laravel Facade Fonts. The facade directly call the FontsManager class.

Define the driver to use by default when the method load is called.

FontsManager::setDefault(driver_name: string);

Add a new driver into the FontsManager. $closure must return an instance of the driver that extend the Driver class.

FontsManager::withDriver(driver_name: string, closure: Closure);

Get a driver by his name. If the driver has not already been instantiated, make a new instance.

FontsManager::use(driver_name: string);

Load a font using the default driver that was set using setDefault method. By default, it's the GoogleV2Driver.

FontsManager::load(font_name: string, font_weights: string|array = [ Fonts::regular ]);

Load a font using the Google Fonts driver

FontsManager::google(font_name: string, font_weights: string|array = [ Fonts::regular ]);

Load a font using the Google Fonts V2 driver

FontsManager::googleV2(font_name: string, font_weights: string|array = [ Fonts::regular ]);

Load a font using the BunnyFonts driver

FontsManager::bunny(font_name: string, font_weights: string|array = [ Fonts::regular ]);

Load a fonts kit from Adobe Fonts

FontsManager::adobe(kit_id: string);

Load an icons kit using the FontAwesome driver

FontsManager::fontawesome(kit_id: string);

Generate an HTML code of every driver instantiated with at least 1 font set.

$html = FontsManager::toHtml();

Print the code generated by the method toHtml

FontsManager::print();

Requirement

PHP 8.3 or above

See also

Credits

License

The MIT License (MIT).