tim-oetting/lucide-php

A modern PHP package for Lucide icons

dev-main 2024-12-19 02:13 UTC

This package is auto-updated.

Last update: 2025-05-19 03:18:39 UTC


README

A modern PHP package for integrating Lucide icons into your PHP projects.

Installation

You can install the package via composer:

composer require tim-oetting/lucide-php

Requirements

  • PHP 8.0 or higher

Usage

Basic Usage

use TimOetting\LucidePhp\Lucide;

// Using the static icon method
echo Lucide::icon('github');

// Using magic method (alternative syntax)
echo Lucide::github();

Customizing Icons

The package provides a fluent interface to customize your icons:

// Add CSS classes
echo Lucide::github()->withClass('w-6 h-6 text-gray-500');

// Set custom size
echo Lucide::github()->withSize(24);

// Add custom attributes
echo Lucide::github()->withAttributes([
    'class' => 'icon',
    'stroke-width' => '1.5',
    'aria-hidden' => 'true'
]);

// Chain methods
echo Lucide::github()
    ->withSize(32)
    ->withClass('text-blue-500')
    ->withAttributes(['stroke-width' => '1.5']);

Error Handling

The package will throw an IconNotFoundException if the requested icon doesn't exist:

try {
    echo Lucide::nonexistentIcon();
} catch (TimOetting\LucidePhp\IconNotFoundException $e) {
    // Handle the error
}

How It Works

The package loads SVG icons from the icons directory and allows you to manipulate them with various attributes. All icons are rendered as inline SVG, making them easy to style with CSS.

Features

  • 🚀 Simple and intuitive API
  • ⚡️ Fluent interface for icon customization
  • 🎨 Full support for custom attributes
  • 🔒 Secure SVG rendering with proper HTML escaping
  • 💪 Type-safe with PHP 8.0 features
  • 🎯 Zero dependencies

License

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

Credits