定制 apsonex/font 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

apsonex/font

最新稳定版本:v1.0.4

Composer 安装命令:

composer require apsonex/font

包简介

Font

README 文档

README

A simple PHP package to manage and search fonts from multiple providers. Currently supports the Bunny Fonts provider with an easy way to list, search, and filter fonts.

Features

  • List fonts with pagination
  • Search fonts by keyword
  • Find fonts by key(s), family(ies), and type
  • Extensible with multiple font providers

Installation

composer require apsonex/font-manager

Usage

use Apsonex\Font\Font;

// Instantiate the font manager
$fontManager = Font::make();

// Select Bunny provider
$fontManager->bunny();

// List fonts (paginated)
$response = $fontManager->list(limit: 20, page: 1);
foreach ($response->fonts as $font) {
    echo $font->family . PHP_EOL;
}

// Search fonts by keyword
$searchResponse = $fontManager->search('abo', limit: 20, page: 1);

// Find font by a single key
$font = $fontManager->findByKey('abel');

// Find fonts by multiple keys
$response = $fontManager->findByKeys(['abel', 'abeezee'], limit: 10);

// Find fonts by family
$response = $fontManager->findByFamily('Abel', limit: 10);

// Find fonts by multiple families
$response = $fontManager->findByFamilies(['Abel', 'Aboreto'], limit: 10);

// Find fonts by type (e.g., 'sans-serif')
// Use limit -1 to fetch all matches
$response = $fontManager->findByType('sans-serif', limit: -1);

API Reference

Font Manager (Apsonex\Font\Font)

  • make(): static — Create a new instance
  • bunny(): static — Use Bunny font provider
  • useProvider(FontProviderInterface $provider): static — Use a custom font provider
  • list(int $limit = 20, int $page = 1): FontResponse — List fonts paginated
  • search(string $keyword, int $limit = 20, int $page = 1): FontResponse — Search fonts by keyword
  • findByKey(string $key): ?FontDTO — Find a single font by key
  • findByKeys(array $keys, int $limit = 20): FontResponse — Find fonts by keys
  • findByFamily(string $family, int $limit = 20): FontResponse — Find fonts by family
  • findByFamilies(array $families, int $limit = 20): FontResponse — Find fonts by families
  • findByType(string $type, int $limit = -1): FontResponse — Find fonts by category/type

FontDTO (Apsonex\Font\FontDTO)

  • Represents a single font object with these properties:
  • key (string): Unique font key
  • provider (string): Provider name
  • category (string): Font category (e.g., sans-serif)
  • family (string): Font family name
  • urlString (string): CSS font string identifier

The FontDTO class represents a single font item with key metadata used across the package.

Property Type Description Example
key string Unique identifier for the font "abeezee"
provider string The font provider source "bunny"
category string Font category/type (e.g., serif, sans-serif) "sans-serif"
family string The font family name "ABeeZee"
urlString string A URL-friendly CSS font string used for loading "abeezee:400,400i"
use Apsonex\Font\FontDTO;

// Creating a FontDTO object (usually returned from provider methods)
$font = new FontDTO(
    key: 'abeezee',
    provider: 'bunny',
    category: 'sans-serif',
    family: 'ABeeZee',
    urlString: 'abeezee:400,400i'
);

// Accessing properties
echo "Font Key: " . $font->key . PHP_EOL;             // Output: abeezee
echo "Provider: " . $font->provider . PHP_EOL;        // Output: bunny
echo "Category: " . $font->category . PHP_EOL;        // Output: sans-serif
echo "Family: " . $font->family . PHP_EOL;            // Output: ABeeZee
echo "CSS URL String: " . $font->urlString . PHP_EOL; // Output: abeezee:400,400i

FontResponse (Apsonex\Font\FontResponse)

  • Paginated font response containing:
  • fonts (array of FontDTO)
  • total (int) — total matched fonts
  • limit (int) — items per page
  • page (int) — current page number

Testing

This package uses Pest PHP for testing.

./vendor/bin/pest

Extending with other Providers

You can implement your own provider by creating a class that implements:

use Apsonex\Font\Contracts\FontProviderInterface;

class YourProvider implements FontProviderInterface
{
    public function list(int $limit, int $page): FontResponse { /*...*/ }
    public function search(string $keyword, int $limit, int $page): FontResponse { /*...*/ }
    public function findByKey(string $key): ?FontDTO { /*...*/ }
    // Implement other methods from interface...
}

Then register it:

    $fontManager->useProvider(new YourProvider());

License

MIT License © Apsonex Inc

Contributing

Feel free to open issues and pull requests!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-26