edwinhoksberg / octicons-php
A simple PHP library for displaying the Github Octicons font icons in svg format.
Installs: 2 354
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 6
Open Issues: 2
Requires
- php: >= 7.0
Requires (Dev)
- mockery/mockery: ^1.0
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^6.5
- twig/twig: ^2.10|^3.0
Suggests
- twig/twig: A helper function is available for twig for creating icons easily in twig templates.
This package is auto-updated.
Last update: 2024-10-19 22:55:07 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