forked from Ympact/flux-icons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mdi.php
53 lines (49 loc) · 1.62 KB
/
Mdi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Ympact\FluxIcons\Services\Vendors;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class Mdi
{
/**
*
* @param string $file
* @param array|null $icons
* @return boolean
*/
public static function outlineFilter($file, &$icons): bool
{
if($icons === null){
$icons = [];
}
// if the icon name ends with -outline it is an outline icon
$filename = pathinfo($file, PATHINFO_FILENAME);
if (Str::contains($filename, '-outline')) {
return true;
}
// if there is an -outline variant of the current icon, then the icon is solid and we return false
// insert -outline before .svg extension to $file and check if this file exists
if(File::exists(Str::of($file)->before('.svg') . '-outline.svg')){
// if there is an outline variant of the icon, in case $icons is passed, we add the icon to the icons array and remove $filename from it
if(in_array( $filename, $icons)){
$key = array_search($filename, $icons);
unset($icons[$key]);
$icons[] = $filename.'-outline';
}
return false;
};
return true;
}
/**
*
* @param $size size of the resource icon
* @return boolean
*/
public static function solidFilter($file): bool
{
$filename = pathinfo($file, PATHINFO_FILENAME);
if (Str::contains($filename,'-outline')) {
return false;
}
return File::exists(Str::of($file)->before('.svg') . '-outline.svg') ? true : false;
}
}