Installation Add the bundle to your Laravel project via Composer:
composer require austral/graphic-items-bundle
Register the bundle in config/app.php under providers:
Austral\GraphicItemsBundle\AustralGraphicItemsBundle::class,
Publish Configuration Publish the default config:
php artisan vendor:publish --provider="Austral\GraphicItemsBundle\AustralGraphicItemsBundle" --tag="config"
This creates config/austral_graphic_items.php.
First Use Case: Displaying Icons
Use the GraphicItem facade to render icons (e.g., from Simple Icons):
use Austral\GraphicItemsBundle\Facades\GraphicItem;
// Render an icon (e.g., GitHub)
echo GraphicItem::icon('github')->size('24px')->render();
Database Setup (if using entities) Run migrations:
php artisan migrate
The bundle provides GraphicItem and GraphicItemFile entities for storing custom graphics.
Rendering Icons
GraphicItem::icon('name')->render() for static icons.size(), color(), or class():
GraphicItem::icon('laravel')->size('32px')->color('#ff2d20')->render();
config/austral_graphic_items.php:
'fallback_icon' => 'question',
'fallback_size' => '16px',
Custom Graphic Items
GraphicItem or GraphicItemFile to store custom SVGs/PNGs:
$customIcon = new \Austral\GraphicItemsBundle\Entity\GraphicItem();
$customIcon->setName('custom-logo');
$customIcon->setContent('<svg>...</svg>');
$entityManager->persist($customIcon);
GraphicItemFile for external files (e.g., uploaded SVGs):
$fileIcon = new \Austral\GraphicItemsBundle\Entity\GraphicItemFile();
$fileIcon->setName('uploaded-icon');
$fileIcon->setFile($uploadedFile); // Symfony UploadedFile
Integration with Austral Ecosystem
austral/design-bundle for theming:
use Austral\DesignBundle\Facades\Design;
echo GraphicItem::icon('twitter')->class(Design::getIconClass())->render();
return response()->json(['icon' => GraphicItem::icon('github')->url()]);
Blade Directives
Register the bundle’s Blade directives in AppServiceProvider:
use Austral\GraphicItemsBundle\Blade\GraphicItemsBladeDirective;
public function boot()
{
GraphicItemsBladeDirective::register();
}
Usage in Blade:
@graphicIcon('github', ['size' => '24px'])
Caching Icons Enable caching in config:
'cache' => [
'enabled' => true,
'ttl' => 3600, // 1 hour
],
Clear cache when icons are updated:
php artisan cache:clear
Missing Dependencies
tools-bundle, entity-bundle, etc.).Class 'Austral\ToolsBundle\...' not found → Run composer require austral/tools-bundle.Icon Not Found
config/austral_graphic_items.php for allowed icons or add custom ones via entities.dd(GraphicItem::getAvailableIcons()); // List all registered icons
File Upload Issues
GraphicItemFile fails to save uploaded files.austral/entity-file-bundle (e.g., public/uploads/icons).GraphicItemFile constraints:
$fileIcon->setAllowedMimeTypes(['image/svg+xml', 'image/png']);
Blade Directive Conflicts
@graphicIcon conflicts with other directives.GraphicItemsBladeDirective or use the facade directly in Blade:
{!! \Austral\GraphicItemsBundle\Facades\GraphicItem::icon('github')->render() !!}
Caching Quirks
php artisan cache:clear
php artisan austral:graphic-items:cache:clear
\Log::info('Available Icons:', GraphicItem::getAvailableIcons());
.env:
APP_DEBUG=true
DOCTRINE_ORM_OPTIMIZED_WRITER=false
config('austral_graphic_items') to verify loaded settings.Custom Icon Sources
Extend the IconSourceInterface to add new icon providers (e.g., Font Awesome):
namespace App\GraphicItems;
use Austral\GraphicItemsBundle\Icon\IconSourceInterface;
class FontAwesomeSource implements IconSourceInterface
{
public function getIcon(string $name): string
{
// Fetch from Font Awesome API or local files
}
}
Register in config:
'icon_sources' => [
\Austral\GraphicItemsBundle\Icon\SimpleIconsSource::class,
App\GraphicItems\FontAwesomeSource::class,
],
Dynamic Icon Generation
Use the GraphicItemBuilder to create icons programmatically:
$builder = new \Austral\GraphicItemsBundle\Icon\GraphicItemBuilder();
$builder->setName('dynamic-icon')->setContent('<svg>...</svg>');
$icon = $builder->build();
Event Listeners
Listen for graphic_item.created or graphic_item.updated events to trigger actions (e.g., cache invalidation):
use Austral\GraphicItemsBundle\Event\GraphicItemEvent;
public function onGraphicItemUpdated(GraphicItemEvent $event)
{
Cache::forget('graphic_items');
}
Testing
Mock the GraphicItem facade in tests:
$this->mock(\Austral\GraphicItemsBundle\Facades\GraphicItem::class)
->shouldReceive('icon')
->andReturnSelf()
->shouldReceive('render')
->andReturn('<svg>Mock Icon</svg>');
How can I help you explore Laravel packages today?