PHP code example of apsonex / font

1. Go to this page and download the library: Download apsonex/font library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

apsonex / font example snippets


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);

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

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...
}

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