edwinhoksberg/octicons-php

A simple PHP library for displaying the Github Octicons font icons in svg format.

1.1.0 2020-06-08 09:34 UTC

README

A simple PHP library for displaying the Github Octicons font icons in svg format.

Installation

Installation with composer:

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.

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:

vendor/bin/phpunit -c phpunit.dist.xml

License

MIT