Skip to content

Commit f93cfa8

Browse files
authored
Add further documentation and fix bug for missing width and height of icon set (#2)
* configure package * Initial setup to find icons and cache results * Ignore cache directory * Change workflows * Update workflow to install npm dependencies * Test workflow * Icons being found, cached, and tests passing * Pint format code * Clean up and get tests fixed * Blade directive to publish out config * Fix styling * Collection routes * Refactor to increase test coverage * Clean up and fix domain * Install command and cache refactor * Refactor to cache icon info separate from the icon data to lower repeated caches * Format code * Clean up * Tests passing * Unset data right away * Test expanding testing matrix * Only do version 11 and 12 * Update dependencies * Revert to only testing Laravel 11 * Remove declaring carbon version * Okay okay, bring back carbon version * Update dependencies * Clean up and correct types * Documentation and ability to turn off API * Add contributing docs * Update README.md * Clean up email * Clean up and consistency * Greater documentation in read me file and fix when height and width aren't available * Clean up incorrect docs * Fix styling * Update run-tests.yml --------- Co-authored-by: abetwothree <[email protected]>
1 parent 5f6a837 commit f93cfa8

File tree

10 files changed

+72
-33
lines changed

10 files changed

+72
-33
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
- 'phpunit.xml.dist'
99
- 'composer.json'
1010
- 'composer.lock'
11+
- 'package.json'
12+
- 'package-lock.json'
1113

1214
jobs:
1315
test:

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/abetwothree/laravel-iconify-api/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/abetwothree/laravel-iconify-api/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
66
[![Total Downloads](https://img.shields.io/packagist/dt/abetwothree/laravel-iconify-api.svg?style=flat-square)](https://packagist.org/packages/abetwothree/laravel-iconify-api)
77

8-
This is a Laravel package for the [Iconify](https://iconify.design/index.html) icons [on demand API](https://iconify.design/docs/icon-components/). It allows you to easily use on demand icons and use your Laravel applicatioin as the Iconify API.
8+
Make your Laravel Application an API for on demand icons using the [Iconify](https://iconify.design/index.html) icon web components.
9+
10+
This Laravel package creates a few API routes for the [Iconify](https://iconify.design/index.html) icons [on demand API](https://iconify.design/docs/icon-components/). It allows you to easily use on demand icons and use your Laravel applicatioin as the Iconify API.
911

1012
It works similarly to the [Node Iconify API](https://github.com/iconify/api) and is a spiritual successor to their [PHP implementation](https://github.com/iconify/api.php).
1113

1214
On demand icons work great whether you use Livewire, Inertia, or just plain Blade views to render your Laravel application and want to render icons dynamically using a single component.
1315

16+
## Requirements
17+
18+
- PHP 8.4
19+
- Laravel 11.x
20+
1421
## How To Use
1522

1623
Install the package via composer:
@@ -27,6 +34,19 @@ In your core application blade layout file add the following directive in the he
2734

2835
This will configure the [Iconify API](https://iconify.design/docs/api/providers.html#api-config) on demand icons to load the icons from your Laravel application instead of the Iconify API.
2936

37+
By default Icon API routes will work out of the following route path in your Laravel application:
38+
39+
```
40+
/iconify/api
41+
```
42+
43+
The following routes are currently available:
44+
45+
- `/iconify/api/{prefix}.json?icons={icon-prefix}` - Returns icon SVG data for an icon set. Icon prefix can be comma separated for multiple icons.
46+
- `/iconify/api/{prefix}/icons.jsonicons={icon-prefix}` - Same as above.
47+
- `/iconify/api/collections` - Returns a list of icon collections available in your application.
48+
- `/iconify/api/collection?prefix={prefix}` - Returns the information for a specific icon collection.
49+
3050
### How To Display Icons
3151

3252
To displays icons follow the instructions on the [Iconify](https://iconify.design/docs/icon-components/) on demand docs and use any of their component libraries in your Laravel Application.
@@ -47,6 +67,22 @@ This will publish a `iconify-api.php` file in your `config` directory. You can t
4767

4868
For advanced setting details, please see the [config file](config/iconify-api.php).
4969

70+
## Icon Caching
71+
72+
This package uses Laravel's caching system to cache the icon data to make repeated requests for the same icon faster. It caches icon data when it is requested so that it only caches the icons that are actually used in your application.
73+
74+
You can set which cache store to use for this package in your `config/iconify-api.php` file. Otherwise, it will use your default cache store setting.
75+
76+
## Missing Features
77+
78+
The MVP of this package was to provide an API for on demand icons in your Laravel Application. A few API endpoints that currently exist on the Node JS package are missing in this package and will be added in future releases:
79+
80+
- [ ] Return icon data in in JSONP callback format.
81+
- [ ] List icons in a collection.
82+
- [ ] List icons categorized in a collection.
83+
- [ ] Search endpoint for icons.
84+
- [ ] Keywords endpoint for icons.
85+
5086
## Changelog
5187

5288
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
@@ -59,6 +95,14 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
5995

6096
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
6197

98+
## Code Quality
99+
100+
This package uses the following code quality tools:
101+
102+
- PHPStan 2.x at level 10 for static analysis.
103+
- Laravel Pint for consistent code style.
104+
- PHP Pest for testing.
105+
62106
## Credits
63107

64108
- [Abraham Arango](https://github.com/abetwothree)

config/iconify-api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
|
2323
*/
2424

25-
'route_path' => 'iconify-api',
25+
'route_path' => 'iconify',
2626

2727
/*
2828
|--------------------------------------------------------------------------
@@ -63,7 +63,7 @@
6363
|--------------------------------------------------------------------------
6464
| Iconify Icon Providers
6565
|--------------------------------------------------------------------------
66-
| By default, this will package will use your application's url as the provider
66+
| By default, this package will use your Laravel application as the provider
6767
| for all iconify icons you install with NPM. If you would like to use a
6868
| different provider for a specific icon set, you can specify it here.
6969
|

phpstan-baseline.neon

Whitespace-only changes.

phpstan.neon.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
includes:
2-
- phpstan-baseline.neon
3-
41
parameters:
52
level: 10
63
paths:

resources/views/.gitkeep

Whitespace-only changes.

src/IconifyDirective.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class IconifyDirective
99
public function render(): string
1010
{
1111
$url = LaravelIconifyApi::domain().'/'.LaravelIconifyApi::path();
12-
$customProviders = $this->gatherCustomProviders();
12+
13+
/** @var array<string, array{resources: array<int, string>, rotate?: int}> $customProviders */
14+
$customProviders = config()->get('iconify-api.custom_providers', []);
1315

1416
if (empty($customProviders)) {
1517
$customProviders = '';
@@ -34,22 +36,4 @@ public function render(): string
3436
</script>
3537
HTML;
3638
}
37-
38-
/**
39-
* @return array<string, array{resources: array<int, string>, rotate?: int}>
40-
*/
41-
protected function gatherCustomProviders(): array
42-
{
43-
/**
44-
* @var array<string, array{resources: array<int, string>, rotate?: int}> $customProviders
45-
*/
46-
$customProviders = config()->get('iconify-api.custom_providers', []);
47-
$providerList = [];
48-
49-
foreach ($customProviders as $provider => $data) {
50-
$providerList[$provider] = $data;
51-
}
52-
53-
return $providerList;
54-
}
5539
}

src/Icons/Contracts/IconFinder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* lastModified: int,
99
* icons: array<string, array{body: string}>,
1010
* aliases: array<string, array<string,string>>,
11-
* width?: int,
12-
* height?: int,
11+
* width?: int|null,
12+
* height?: int|null,
1313
* }
1414
* @phpstan-type TIconData = array{
1515
* icons: array<string, array{body: string}>,

src/Icons/IconSetInfoFinder.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ public function find(string $set): array
2828
$data = [
2929
'prefix' => $content['prefix'],
3030
'lastModified' => $content['lastModified'],
31-
'width' => $content['width'] ?? 0,
32-
'height' => $content['height'] ?? 0,
3331
];
3432

33+
if (isset($content['width']) && ! empty($content['width'])) {
34+
$data['width'] = $content['width'];
35+
}
36+
37+
if (isset($content['height']) && ! empty($content['height'])) {
38+
$data['height'] = $content['height'];
39+
}
40+
3541
unset($content);
3642

3743
return $data;

tests/Unit/Icons/IconSetInforFinderTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@
99
$info = $iconFinder->find($set);
1010

1111
expect($info)->toBeArray()
12-
->toHaveKeys(['prefix', 'lastModified', 'width', 'height'])
12+
->toHaveKeys(['prefix', 'lastModified'])
1313
->prefix->toBe($set)
14-
->lastModified->toBeInt()
15-
->width->toBeInt()
16-
->height->toBeInt();
14+
->lastModified->toBeInt();
15+
16+
if (isset($info['width'])) {
17+
expect($info['width'])->toBeInt();
18+
}
19+
20+
if (isset($info['height'])) {
21+
expect($info['height'])->toBeInt();
22+
}
1723
})->with([
1824
['mdi'],
1925
['heroicons'],

0 commit comments

Comments
 (0)