inteve/icons

Web应用图标加载器

维护者

详细信息

github.com/inteve/icons

源代码

问题

资助包维护!
其他

v1.1.0 2023-12-19 07:19 UTC

This package is auto-updated.

Last update: 2024-09-19 08:47:05 UTC


README

Build Status Downloads this Month Latest Stable Version License

Web应用图标加载器。

Donate

安装

下载最新包 或使用 Composer

composer require inteve/icons

Inteve\Icons 需要 PHP 7.4.0 或更高版本。

用法

此库是 PHIG's HtmlIcons 接口的实现。

InlineSvgIcons

$icons = new \Inteve\Icons\InlineSvgIcons($iconsDirectory);
echo $icons->get('my-icon'); // finds file "$iconsDirectory/my-icon.svg", prints <svg ...>...</svg>

ImgIcons

$icons = new \Inteve\Icons\ImgIcons($publicUrlPath, $fileExtension, $htmlClass = 'icon');
echo $icons->get('my-icon'); // prints <img src="/path/to/my-icon.ext" class="icon" alt="">
echo $icons->get('my-icon@small'); // prints <img src="/path/to/my-icon.ext" class="icon icon--small" alt="">

InlineStyleIcons

$icons = new \Inteve\Icons\InlineStyleIcons($publicUrlPath, $fileExtension, $htmlClass = 'icon', $tagName = 'i');
echo $icons->get('my-icon'); // prints <i class="icon" style="background-image:url(/path/to/my-icon.ext)"></i>
echo $icons->get('my-icon@small'); // prints <i class="icon icon--small" style="background-image:url(/path/to/my-icon.ext)"></i>

WrappedIcons

$svgIcons = new \Inteve\Icons\InlineSvgIcons($iconsDirectory);
$icons = new \Inteve\Icons\WrappedIcons($svgIcons, $className = 'icon', $tagName = 'i');
echo $icons->get('my-icon'); // prints <i class="icon"><svg ...>...</svg></i>
echo $icons->get('my-icon@small'); // prints <i class="icon icon-small"><svg ...>...</svg></i>

PrefixedIcons

$icons = new \Inteve\Icons\PrefixedIcons(
	icons: [
		'legacy' => new ImgIcons($publicUrlPath, $fileExtension),
		'bootstrap' => new \Inteve\Icons\InlineSvgIcons($bootstrapIconsDirectory),
	],
	defaultIcons: new \Inteve\Icons\InlineSvgIcons($iconsDirectory)
);
echo $icons->get('my-icon'); // prints <svg ...>...</svg>
echo $icons->get('legacy/my-icon'); // prints <img src="/path/to/my-icon.ext" class="icon" alt="">
echo $icons->get('bootstrap/my-icon'); // prints <svg ...>...</svg>

许可证: 新BSD许可证
作者:Jan Pecha,https://www.janpecha.cz/