bugo/fa-icon-builder

Dependency-free PHP toolset to generate Font Awesome icon classes, HTML tags, and collections (Solid/Regular/Brands). Perfect for projects where you need to work with FA icons without loading CSS/JS.

0.1 2025-07-28 08:57 UTC

This package is auto-updated.

Last update: 2025-07-28 09:01:22 UTC


README

PHP Coverage

По-русски

Description

Dependency-free PHP toolset to generate Font Awesome icon classes, HTML tags, and collections (Solid/Regular/Brands). Perfect for projects where you need to work with FA icons without loading CSS/JS.

Installation

composer require bugo/fa-icon-builder

Using

A unique decorator is provided for each icon set:

// 'fa-brands fa-windows'
echo BrandsIcon::make('windows');

// 'fa-regular fa-user'
echo RegularIcon::make('user');

// 'fa-solid fa-user'
echo SolidIcon::make('user');

If you need support for legacy classes, simply pass true as the second parameter:

// 'fas fa-user'
echo SolidIcon::make('user', true);

Extended example:

$icon = Icon::make('user', IconStyle::Solid);

// '<i class="fa-solid fa-user fa-2xl text-red-500 fa-fw" title="User" aria-hidden="true"></i>'
var_dump(
    $icon
        ->color('text-red-500')
        ->size('2xl')
        ->title('User')
        ->fixedWidth()
        ->ariaHidden()
        ->html()
);

Additional classes can be passed via the addClass method:

$icon = SolidIcon::make('heart');

// '<i class="fa-solid fa-heart fa-beat"></i>'
var_dump(
    $icon
        ->addClass('fa-beat')
        ->html()
);

Additionally, random icon retrieval is available:

var_dump(Icon::random());

You can retrieve the entire collection with all classes at once:

var_dump(Icon::collection());

Or a specific collection set:

var_dump(Icon::collection(IconStyle::Brands));

var_dump(BrandsIcon::collection());

You might also find the IconBuilder class useful, which can create an icon by its class:

var_dump(IconBuilder::make(Icon::random()));