Octicons-PHP
A simple PHP library for displaying the Github Octicons font icons in svg format., (*1)
Installation
Installation with composer:, (*2)
composer require edwinhoksberg/octicons-php
Usage
<?php
use Octicons\Octicon;
use Octicons\Options;
// The shortcut method:
echo Octicon::gear();
// or with options:
echo Octicon::gear([
'classes' => ['bla', 'test-con'],
'ratio' => 8
]);
// The extended method:
$octicon = new Octicon();
$icon = $octicon->icon('gear');
echo 'Icon name: '.$icon->getName(); // gear
echo 'Icon width: '.$icon->getWidth(); // 14
echo 'Icon height: '.$icon->getHeight(); // 16
echo 'Icon ratio: '.$icon->getRatio(); // 1
echo $icon->toSvg();
// and with custom options:
$octicon = new Octicon();
$options = new Options();
// add extra css classes:
$options->addClass('background-color');
$options->addClass(['color-blue', 'extra-class']);
// change the icon size:
$options->setRatio(2);
$icon = $octicon->icon('gear', $options);
echo 'Icon width: '.$icon->getWidth(); // 28
echo 'Icon height: '.$icon->getHeight(); // 32
echo $icon->toSvg();
Twig Extension
A simple twig function is available for those who are using the Twig templating library., (*3)
Display an icon: {{ octicon("gear") }}
Display an icon with extra css classes: {{ octicon("gear", 'background-red') }}
Display an extra large icon: {{ octicon("gear", '', 2) }}
Tests
Run the unit tests with PHPUnit:, (*4)
vendor/bin/phpunit -c phpunit.dist.xml
License
MIT, (*5)