34
34
use FilesystemIterator ;
35
35
use InvalidArgumentException ;
36
36
use Narrowspark \Automatic \Common \AbstractContainer ;
37
- use Narrowspark \Automatic \Common \Contract \Container as ContainerContract ;
38
37
use Narrowspark \Automatic \Common \Downloader \ParallelDownloader ;
39
38
use Narrowspark \Automatic \Prefetcher \Common \Util ;
40
39
use Narrowspark \Automatic \Prefetcher \Contract \LegacyTagsManager as LegacyTagsManagerContract ;
44
43
use ReflectionMethod ;
45
44
use SplFileInfo ;
46
45
use Symfony \Component \Console \Input \ArgvInput ;
46
+ use Symfony \Component \Console \Input \InputInterface ;
47
47
48
48
class Plugin implements EventSubscriberInterface, PluginInterface
49
49
{
@@ -70,14 +70,6 @@ class Plugin implements EventSubscriberInterface, PluginInterface
70
70
*/
71
71
private static $ activated = true ;
72
72
73
- /**
74
- * Get the Container instance.
75
- */
76
- public function getContainer (): ContainerContract
77
- {
78
- return $ this ->container ;
79
- }
80
-
81
73
/**
82
74
* {@inheritdoc}
83
75
*/
@@ -106,6 +98,14 @@ public function activate(Composer $composer, IOInterface $io): void
106
98
107
99
$ this ->container = new Container ($ composer , $ io );
108
100
101
+ if ($ this ->container ->get (InputInterface::class) === null ) {
102
+ self ::$ activated = false ;
103
+
104
+ $ io ->writeError ('<warning>Narrowspark Automatic Prefetcher has been disabled. No input object found on composer class.</warning> ' );
105
+
106
+ return ;
107
+ }
108
+
109
109
/** @var \Narrowspark\Automatic\Prefetcher\Contract\LegacyTagsManager $tagsManager */
110
110
$ tagsManager = $ this ->container ->get (LegacyTagsManagerContract::class);
111
111
@@ -118,8 +118,6 @@ public function activate(Composer $composer, IOInterface $io): void
118
118
return $ composer ;
119
119
});
120
120
121
- $ this ->container ->get (PrefetcherContract::class)->populateRepoCacheDir ();
122
-
123
121
$ this ->extendComposer (\debug_backtrace (), $ tagsManager );
124
122
}
125
123
@@ -348,9 +346,9 @@ private function getErrorMessage(): ?string
348
346
/**
349
347
* Extend the composer object with some automatic prefetcher settings.
350
348
*
351
- * @param array $backtrace
349
+ * @param array<int|string, mixed> $backtrace
352
350
*/
353
- private function extendComposer ($ backtrace , LegacyTagsManagerContract $ tagsManager ): void
351
+ private function extendComposer (array $ backtrace , LegacyTagsManagerContract $ tagsManager ): void
354
352
{
355
353
foreach ($ backtrace as $ trace ) {
356
354
if (! isset ($ trace ['object ' ]) || ! isset ($ trace ['args ' ][0 ])) {
@@ -388,5 +386,7 @@ private function extendComposer($backtrace, LegacyTagsManagerContract $tagsManag
388
386
389
387
break ;
390
388
}
389
+
390
+ $ this ->container ->get (PrefetcherContract::class)->populateRepoCacheDir ();
391
391
}
392
392
}
0 commit comments