44
55use Exception ;
66use Illuminate \Database \Capsule \Manager as Capsule ;
7+ use Ivy \Plugin \Application \Contracts \PluginInterface ;
8+ use Ivy \Plugin \Domain \Entity \Plugin ;
79use Ivy \Plugin \Domain \Exception \PluginException ;
10+ use Ivy \Plugin \Infrastructure \Metadata \PluginInfoLoader ;
811use Ivy \Plugin \Infrastructure \Service \PluginService ;
12+ use Ivy \Plugin \Presentation \Form \PluginInfoForm ;
913use Ivy \Setting \Domain \Entity \Setting ;
1014use Ivy \Template \Application \Asset \AssetPublisher ;
11- use Ivy \Plugin \Domain \Entity \Plugin ;
12- use Ivy \Plugin \Application \Contracts \PluginInterface ;
13- use Ivy \Shared \Core \Language ;
14- use Ivy \Plugin \Presentation \Form \PluginInfoForm ;
15- use Ivy \Plugin \Infrastructure \Metadata \PluginInfoLoader ;
1615
1716class PluginManager
1817{
@@ -27,32 +26,32 @@ private function resolvePluginInterface(): PluginInterface
2726 {
2827 $ class = $ this ->plugin ->interface ;
2928
30- if (!class_exists ($ class )) {
29+ if (! class_exists ($ class )) {
3130 throw new PluginException ("class {$ class } not found " , $ this ->plugin ->name );
3231 }
3332
34- $ instance = new $ class() ;
33+ $ instance = new $ class ;
3534
36- if (!$ instance instanceof PluginInterface) {
35+ if (! $ instance instanceof PluginInterface) {
3736 throw new PluginException ("must implement {$ class }" , $ this ->plugin ->name );
3837 }
3938
4039 return $ instance ;
4140 }
4241
43- public function install ():void
42+ public function install (): void
4443 {
4544 $ this ->plugin ->authorize ('install ' );
4645
4746 $ info = (new PluginInfoLoader )->load ($ this ->plugin ->url );
4847
49- if (!$ info ) {
48+ if (! $ info ) {
5049 throw new PluginException (message: 'contains no info.json ' , plugin: $ this ->plugin ->url );
5150 }
5251
5352 $ result = (new PluginInfoForm )->validate ($ info );
5453
55- if (!$ result ->valid ) {
54+ if (! $ result ->valid ) {
5655 $ errors = [];
5756
5857 foreach ($ result ->errors as $ error ) {
@@ -61,15 +60,15 @@ public function install():void
6160 }
6261 }
6362
64- throw new PluginException (message: 'contains an invalid info.json file: ' . implode (' ' , $ errors ), plugin: $ this ->plugin ->url );
63+ throw new PluginException (message: 'contains an invalid info.json file: ' . implode (' ' , $ errors ), plugin: $ this ->plugin ->url );
6564 }
6665
6766 $ this ->plugin ->fill ($ result ->data );
6867
6968 if (isset ($ info ['dependencies ' ])) {
7069 $ missing = PluginService::getMissingDependencies ($ info ['dependencies ' ]);
71- if (!empty ($ missing )) {
72- throw new PluginException (message: 'is missing dependencies ' . implode (', ' , $ missing ), plugin: $ this ->plugin ->name );
70+ if (! empty ($ missing )) {
71+ throw new PluginException (message: 'is missing dependencies ' . implode (', ' , $ missing ), plugin: $ this ->plugin ->name );
7372 }
7473 }
7574
@@ -91,9 +90,9 @@ public function install():void
9190
9291 new AssetPublisher ()->publishPlugin ($ this ->plugin ->url );
9392
94- if (!empty ($ info ['collection ' ])) {
93+ if (! empty ($ info ['collection ' ])) {
9594
96- $ paths = glob (PluginService::getCollectionDirectory ($ this ->plugin ->url ) . '[a-zA-Z0-9_-]* ' );
95+ $ paths = glob (PluginService::getCollectionDirectory ($ this ->plugin ->url ). '[a-zA-Z0-9_-]* ' );
9796
9897 if ($ paths === false ) {
9998 throw new PluginException (message: 'cannot read plugin collection directory ' , plugin: $ this ->plugin ->name );
@@ -103,20 +102,20 @@ public function install():void
103102
104103 foreach ($ subfolders as $ subfolder ) {
105104 try {
106- $ plugin = new Plugin () ;
105+ $ plugin = new Plugin ;
107106 $ pluginManager = new PluginManager ($ plugin ->fill ([
108- 'url ' => PluginService::getRelativePath ($ subfolder )
107+ 'url ' => PluginService::getRelativePath ($ subfolder ),
109108 ]));
110109 $ pluginManager ->install ();
111110 } catch (PluginException $ e ) {
112- throw new PluginException (message: 'cannot install plugin from its collection because ' . $ e ->getMessage (), plugin: $ this ->plugin ->name , previous: $ e );
111+ throw new PluginException (message: 'cannot install plugin from its collection because ' . $ e ->getMessage (), plugin: $ this ->plugin ->name , previous: $ e );
113112 }
114113 }
115114 }
116115 });
117116 } catch (PluginException $ e ) {
118117 $ this ->resolvePluginInterface ()->uninstall ();
119- throw new PluginException (message: 'installation failed. ' . $ e ->getMessage (), plugin: $ this ->plugin ->name , previous: $ e );
118+ throw new PluginException (message: 'installation failed. ' . $ e ->getMessage (), plugin: $ this ->plugin ->name , previous: $ e );
120119 }
121120 }
122121
@@ -126,15 +125,15 @@ public function uninstall(): void
126125
127126 $ info = (new PluginInfoLoader )->load ($ this ->plugin ->url );
128127
129- if (!$ info ) {
128+ if (! $ info ) {
130129 throw new PluginException (message: 'has no info.json ' , plugin: $ this ->plugin ->url );
131130 }
132131
133132 try {
134133 Capsule::connection ()->transaction (function () use ($ info ) {
135- if (!empty ($ info ['collection ' ])) {
134+ if (! empty ($ info ['collection ' ])) {
136135
137- $ paths = glob (PluginService::getCollectionDirectory ($ this ->plugin ->url ) . '[a-zA-Z0-9_-]* ' );
136+ $ paths = glob (PluginService::getCollectionDirectory ($ this ->plugin ->url ). '[a-zA-Z0-9_-]* ' );
138137
139138 if ($ paths === false ) {
140139 throw new PluginException (message: 'cannot read plugin collection directory ' , plugin: $ this ->plugin ->name );
@@ -150,7 +149,7 @@ public function uninstall(): void
150149 $ pluginManager = new PluginManager ($ plugin );
151150 $ pluginManager ->uninstall ();
152151 } catch (PluginException $ e ) {
153- throw new PluginException (message: 'cannot uninstall plugin from its collection because ' . $ e ->getMessage (), plugin: $ this ->plugin ->name , previous: $ e );
152+ throw new PluginException (message: 'cannot uninstall plugin from its collection because ' . $ e ->getMessage (), plugin: $ this ->plugin ->name , previous: $ e );
154153 }
155154 }
156155 }
@@ -159,7 +158,7 @@ public function uninstall(): void
159158 $ this ->plugin ->delete ();
160159 });
161160 } catch (PluginException $ e ) {
162- throw new PluginException (message: 'cannot uninstall plugin because ' . $ e ->getMessage (), plugin: $ this ->plugin ->name , previous: $ e );
161+ throw new PluginException (message: 'cannot uninstall plugin because ' . $ e ->getMessage (), plugin: $ this ->plugin ->name , previous: $ e );
163162 }
164163
165164 $ this ->resolvePluginInterface ()->uninstall ();
0 commit comments