承接 xicrow/php-icons 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

xicrow/php-icons

最新稳定版本:1.0.0

Composer 安装命令:

composer require xicrow/php-icons

包简介

Icon management through PHP

README 文档

README

Installation

The recommended way to install is through Composer.

composer require xicrow/php-icons

Usage

Depending on what icons you are using (or want to use), implement the icon class of your choice:

// FontAwesome 4
echo \Xicrow\PhpIcons\FontAwesome4::Icon(\Xicrow\PhpIcons\FontAwesome4::Icon_Thumbs_Up);
<i class="fa fa-thumbs-up"></i>
// FontAwesome 5
echo \Xicrow\PhpIcons\FontAwesome5::Icon(\Xicrow\PhpIcons\FontAwesome5::Icon_Thumbs_Up);
<i class="fas fa-thumbs-up"></i>

For now, we'll just use the BaseIcon class, to show usages.

Basic usage, show an icon:

echo BaseIcon::Icon(ICON_IDENTIFIER);
<span class="ICON_IDENTIFIER"></span>

Apply one or more modifiers (not all icon packs support modifiers):

echo BaseIcon::Icon(ICON_IDENTIFIER, ICON_MODIFIER, ICON_MODIFIER);
<span class="ICON_IDENTIFIER ICON_MODIFIER ICON_MODIFIER"></span>

Modifiers can also be chained from the icon:

echo BaseIcon::Icon(ICON_IDENTIFIER)
    ->modify(ICON_MODIFIER)
    ->modify(ICON_MODIFIER)
;
<span class="ICON_IDENTIFIER ICON_MODIFIER ICON_MODIFIER"></span>

Attributes for the icon can also be set by chaining:

echo BaseIcon::Icon(ICON_IDENTIFIER)
    ->modify(ICON_MODIFIER)
    ->modify(ICON_MODIFIER)
    ->attribute('title', 'Nifty help text')
    ->attribute('style', 'color: blue;')
;
<span class="ICON_IDENTIFIER ICON_MODIFIER ICON_MODIFIER" title="Nifty help text" style="color: blue;"></span>

Untill the icon is rendered (either through the BaseIcon::render() method or other to-string triggers like echo), it is possible to add modifiers and attributes to the icon.

// Made-up constants
$oStatusIcon = BaseIcon::Icon(BaseIcon::Icon_Bullet, BaseIcon::Modifier_Size_X2);
// Looping a resultset
foreach ($arrResults as $oResult) {
    // Clone the status icon, set color from result, and render
    echo (clone $oStatusIcon)->attribute('style', 'color: '.$oResult->strStatusColor.';');
}

Extending

Instead of using the classes in this repository directly, you are encouraged to implement your own extension like so:

class FA extends \Xicrow\PhpIcons\FontAwesome5 {}

echo FA::Icon(FA::Icon_Thumbs_Up, FA::Modifier_Lg);

This will ease your own implementation, since you determine what the class will be called and also makes it easier for you to change provider in the future.

It also makes it easy to implement shortcuts for commonly used icons:

class FA extends \Xicrow\PhpIcons\FontAwesome5 {
    public static function IconCreate(): self
    {
        return static::Icon(static::Icon_Plus_Circle)->attribute('style', 'color: green;');
    }

    public static function IconEdit(): self
    {
        return static::Icon(static::Icon_Pencil)->attribute('style', 'color: blue;');
    }

    public static function IconDelete(): self
    {
        return static::Icon(static::Icon_Trash)->attribute('style', 'color: red;');
    }
}

echo FA::IconCreate();

Supported icon packs

Currently, there are generators and classes for the following icon packs:

  • Bootstrap 3 Glyphicons
  • Devicons
  • FontAwesome 4
  • FontAwesome 5 (free)

Generators are used to create the constants for icons (and modifiers) for each icon pack, these generators will mostly be able to generate constants for every specific version of the icon pack, thereby supporting exactly the version you are using.

Classes are simply the implementation of the specific icon pack, that is using the generated icon (and modifier) constants, and implementing a render method specific for that icon pack.

TODO

License

Copyright © 2022 Jan Ebsen Licensed under the MIT license.

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固