enflow/laravel-svg 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

enflow/laravel-svg

Composer 安装命令:

composer require enflow/laravel-svg

包简介

Using SVGs with easy

README 文档

README

Latest Version on Packagist GitHub Workflow Status Total Downloads

The enflow/laravel-svg package provides a easy way include SVGs in your templates.

Installation

You can install the package via composer:

composer require enflow/laravel-svg

Usage

You may use the svg helper in your templates

{{ svg('clock') }}

// Adding a class
{{ svg('clock')->class('mr-2') }}

// Adding an extra attribute
{{ svg('clock')->class('mr-2')->id('clock-icon') }}

// Specify the pack
{{ svg('clock')->pack('fas') }}

Config

You may publish the config to set the packs that you are using:

Pushing the config file:

php artisan vendor:publish --provider="Enflow\Svg\SvgServiceProvider"

Packs

You may specify multiple packs that are used in your application. By default, only the resources/img/svgs pack is included, but you may specify additional icon sets like Font Awesome in your config. When the pack isn't specified when including the SVG, the first one that can be found in the order defined in your config will be used. You may overrule this behavior by calling the pack method on the Enflow\Svg\Svg class that's returned by the SVG helper.

<?php

return [
    'packs' => [
        'custom' => resource_path('img/svgs/'),
        'fas' => [
            'path' => base_path('vendor/fortawesome/font-awesome/svgs/solid/'),
            'auto_size_on_viewbox' => true,
        ],
        'fal' => [
            'path' => base_path('vendor/fortawesome/font-awesome/svgs/light/'),
            'auto_size_on_viewbox' => true,
        ],
    ],
];

Examples

Font Awesome 5 Free

Installing

composer require fortawesome/font-awesome

Reference: https://github.com/FortAwesome/Font-Awesome

Config
<?php

return [
    'packs' => [
        'custom' => resource_path('img/svgs/'),
        'fas' => [
            'path' => base_path('vendor/fortawesome/font-awesome/svgs/solid/'),
            'auto_size_on_viewbox' => true,
        ],
    ],
];

Font Awesome 5 Pro

Installing

yarn add @fortawesome/fontawesome-pro

Font Awesome 5 doesn't provide a composer package. We'll install it through our npm/yarn pipeline and use that path instead

Reference: https://fontawesome.com/how-to-use/on-the-web/setup/using-package-managers

Config
<?php

return [
    'packs' => [
        'custom' => resource_path('img/svgs/'),
        'fas' => [
            'path' => base_path('node_modules/@fortawesome/fontawesome-pro/svgs/solid/'),
            'auto_size_on_viewbox' => true,
        ],
    ],
];

Middleware

This package includes the Enflow\Svg\Middleware\InjectSvgSpritesheet middleware which is automatically registered and added to your web group.

This will add the SVG spritesheet to the top of your templates, where all unique SVGs are added. The SVGs rendered in your templates will reference this spritesheet. The reason for this is that in a loop, the SVG only is once in the body, instead of repeating it per row.

You may disable the automatic injection by setting the register_middleware_automatically to false:

config/svg.php
<?php

return [
    'register_middleware_automatically' => false
];

Using with other middleware

When using enflow/laravel-svg in combination with another middleware that must always be executed after the SVGs are injected in the response, you may use the $middlewarePriority logic on the Laravel router to ensure it's always run after.

The order in this array is counterintuitive: at first must the CacheResponse middleware be specified, and then the SVG injection middleware. This is due to the way middleware responses are build. This ensures that first the SVGs are injected, and that complete response is cached.

Example for usage with spatie/laravel-responsecache

app/Http/Kernel.php
protected $middlewarePriority = [
    ...
    \Spatie\ResponseCache\Middlewares\CacheResponse::class,
    \Enflow\Svg\Middleware\InjectSvgSpritesheet::class,
];

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email michel@enflow.nl instead of using the issue tracker.

Credits

Special thanks

  • github.com/jerodev/laravel-font-awesome for the idea
  • github.com/adamwathan/blade-svg for the research
  • github.com/spatie for the GitHub actions test workflow

About Enflow

Enflow is a digital creative agency based in Alphen aan den Rijn, Netherlands. We specialize in developing web applications, mobile applications and websites. You can find more info on our website.

License

The MIT License (MIT). Please see License File for more information.

enflow/laravel-svg 适用场景与选型建议

enflow/laravel-svg 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 62.18k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2020 年 03 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 enflow/laravel-svg 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 enflow/laravel-svg 我们能提供哪些服务?
定制开发 / 二次开发

基于 enflow/laravel-svg 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-22