22
33namespace Aerni \FontAwesome ;
44
5- use Illuminate \Support \Str ;
65use Illuminate \Support \Collection ;
7- use Illuminate \Support \Facades \Http ;
86use Illuminate \Support \Facades \Cache ;
7+ use Illuminate \Support \Facades \Http ;
8+ use Illuminate \Support \Str ;
99
1010class FontAwesome
1111{
@@ -25,9 +25,9 @@ public function all(): Collection
2525 return $ this ->icons ()->flatten (1 )->sortBy ('id ' )->values ();
2626 }
2727
28- public function get (string | array $ style ): Collection
28+ public function icon (string $ icon ): ? array
2929 {
30- return $ this ->icons ()->only ( $ style )-> flatten ( 1 )-> sortBy ( ' id ' )-> values ( );
30+ return $ this ->all ()->firstWhere ( ' class ' , $ icon );
3131 }
3232
3333 public function styles (): Collection
@@ -44,7 +44,7 @@ public function kit(string $token = null): Collection
4444 return Cache::rememberForever ("font_awesome::kit:: {$ this ->kitToken }" , function () {
4545 $ response = Http::withToken ($ this ->authToken ())
4646 ->post ('https://api.fontawesome.com ' , [
47- 'query ' => $ this ->kitQuery ()
47+ 'query ' => $ this ->kitQuery (),
4848 ])->json ()['data ' ]['me ' ]['kit ' ];
4949
5050 return collect ([
@@ -61,20 +61,20 @@ protected function icons(): Collection
6161 {
6262 return Cache::rememberForever ('font_awesome::icons ' , function () {
6363 $ response = Http::post ('https://api.fontawesome.com ' , [
64- 'query ' => $ this ->iconsQuery ()
65- ])->json ()['data ' ]['release ' ]['icons ' ];
64+ 'query ' => $ this ->iconsQuery (),
65+ ])->json ()['data ' ]['release ' ]['icons ' ];
6666
6767 $ icons = collect ($ response )->flatMap (function ($ icon ) {
6868 // The styles available for the license type of the kit.
6969 $ styles = $ icon ['membership ' ][$ this ->kit ()->get ('license ' )];
7070
7171 return collect ($ styles )->map (function ($ style ) use ($ icon ) {
7272 return [
73- 'style ' => $ style ,
74- 'id ' => "{$ icon ['id ' ]}- {$ style }" ,
75- 'label ' => $ icon ['label ' ] . " ( $ style) " ,
76- 'class ' => $ this ->iconClass ($ icon ['id ' ], $ style )
77- ];
73+ 'style ' => $ style ,
74+ 'id ' => "{$ icon ['id ' ]}- {$ style }" ,
75+ 'label ' => $ icon ['label ' ]. " ( $ style) " ,
76+ 'class ' => $ this ->iconClass ($ icon ['id ' ], $ style ),
77+ ];
7878 })->toArray ();
7979 })->groupBy ('style ' );
8080
@@ -92,7 +92,7 @@ protected function uploadedIcons(): Collection
9292 return [
9393 'style ' => 'uploaded ' ,
9494 'id ' => "{$ icon ['name ' ]}-uploaded " ,
95- 'label ' => Str::title ($ icon ['name ' ]) . " (uploaded)" ,
95+ 'label ' => Str::title ($ icon ['name ' ]). ' (uploaded)' ,
9696 'class ' => "fak fa- {$ icon ['name ' ]}" ,
9797 ];
9898 })->sortBy ('id ' );
@@ -101,7 +101,7 @@ protected function uploadedIcons(): Collection
101101 protected function iconClass (string $ icon , string $ style ): string
102102 {
103103 return Str::startsWith ($ this ->kit ()->get ('version ' ), '5 ' )
104- ? 'fa ' . substr ($ style , 0 , 1 ) . ' fa- ' . $ icon
104+ ? 'fa ' . substr ($ style , 0 , 1 ). ' fa- ' . $ icon
105105 : "fa- $ style fa- $ icon " ;
106106 }
107107
@@ -124,11 +124,11 @@ protected function iconsQuery(): string
124124 {
125125 return
126126 'query {
127- release (version: ' . '" ' . $ this ->kit ()->get ('version ' ) . '" ' . ') {
127+ release (version: '. '" ' . $ this ->kit ()->get ('version ' ). '" ' . ') {
128128 icons {
129129 label
130130 id
131- membership { ' . $ this ->kit ()->get ('license ' ) . '}
131+ membership { '. $ this ->kit ()->get ('license ' ). '}
132132 }
133133 }
134134 } ' ;
@@ -139,11 +139,11 @@ protected function kitQuery(): string
139139 return
140140 'query {
141141 me {
142- kit (token: ' . '" ' . $ this ->kitToken . '" ' . ') {
142+ kit (token: '. '" ' . $ this ->kitToken . '" ' . ') {
143143 token
144144 licenseSelected
145145 version
146- iconUploads { ' . " name " . '}
146+ iconUploads { '. ' name ' . '}
147147 }
148148 }
149149 } ' ;
0 commit comments