29 parent::__construct();
31 $this->
addOption(
'extensions',
'Comma separated list of extensions to check',
false,
true );
32 $this->
addOption(
'skins',
'Comma separated list of skins to check',
false,
true );
33 $this->
addOption(
'json',
'Output in JSON' );
34 $this->
addOption(
'dev',
'Check development dependencies too' );
38 $this->checkDev = $this->
hasOption(
'dev' );
39 $extensions = $this->
hasOption(
'extensions' )
40 ? explode(
',', $this->
getOption(
'extensions' ) )
43 ? explode(
',', $this->
getOption(
'skins' ) )
49 $registry = ExtensionRegistry::getInstance();
50 foreach ( $extensions as $extension ) {
51 if ( !$this->checkDev && $registry->isLoaded( $extension ) ) {
53 $this->addToDependencies( $dependencies, [ $extension ], [] );
56 $this->loadThing( $dependencies, $extension, [ $extension ], [] );
59 foreach ( $skins as $skin ) {
60 if ( !$this->checkDev && $registry->isLoaded( $skin ) ) {
62 $this->addToDependencies( $dependencies, [], [ $skin ] );
65 $this->loadThing( $dependencies, $skin, [], [ $skin ] );
69 $this->
output( json_encode( $dependencies ) .
"\n" );
71 $this->
output( $this->formatForHumans( $dependencies ) .
"\n" );
75 private function loadThing( array &$dependencies,
string $name, array $extensions, array $skins ) {
76 $extDir = $this->
getConfig()->get( MainConfigNames::ExtensionDirectory );
77 $styleDir = $this->
getConfig()->get( MainConfigNames::StyleDirectory );
80 foreach ( $extensions as $extension ) {
81 $path =
"$extDir/$extension/extension.json";
82 if ( file_exists(
$path ) ) {
85 $this->addToDependencies( $dependencies, [ $extension ], [], $name );
88 $this->addToDependencies( $dependencies, [ $extension ], [], $name,
'missing' );
92 foreach ( $skins as $skin ) {
93 $path =
"$styleDir/$skin/skin.json";
94 if ( file_exists(
$path ) ) {
96 $this->addToDependencies( $dependencies, [], [ $skin ], $name );
99 $this->addToDependencies( $dependencies, [], [ $skin ], $name,
'missing' );
109 $registry->setCheckDevRequires( $this->checkDev );
111 $registry->readFromQueue( $queue );
114 if ( $e->incompatibleCore ) {
115 $reason =
'incompatible-core';
116 } elseif ( $e->incompatibleSkins ) {
117 $reason =
'incompatible-skins';
118 } elseif ( $e->incompatibleExtensions ) {
119 $reason =
'incompatible-extensions';
120 } elseif ( $e->missingExtensions || $e->missingSkins ) {
126 array_merge( $extensions, $e->missingExtensions ),
127 array_merge( $skins, $e->missingSkins )
137 $this->addToDependencies( $dependencies, $extensions, $skins, $name, $reason, $e->getMessage() );
140 $this->addToDependencies( $dependencies, $extensions, $skins, $name );
143 private function addToDependencies( array &$dependencies, array $extensions, array $skins,
144 ?
string $why =
null, ?
string $status =
null, ?
string $message =
null
146 $mainRegistry = ExtensionRegistry::getInstance();
147 $iter = [
'extensions' => $extensions,
'skins' => $skins ];
148 foreach ( $iter as $type => $things ) {
149 foreach ( $things as $thing ) {
150 $preStatus = $dependencies[$type][$thing][
'status'] ??
false;
151 if ( $preStatus !==
'loaded' ) {
156 $tStatus = $mainRegistry->isLoaded( $thing ) ?
'loaded' :
'present';
158 $dependencies[$type][$thing][
'status'] = $tStatus;
160 if ( $why !==
null ) {
161 $dependencies[$type][$thing][
'why'][] = $why;
163 $dependencies[$type][$thing][
'why'] = array_unique(
164 $dependencies[$type][$thing][
'why'] );
167 if ( $message !==
null ) {
168 $dependencies[$type][$thing][
'message'] = trim( $message );
175 private function formatForHumans( array $dependencies ): string {
177 foreach ( $dependencies as $type => $things ) {
178 $text .= ucfirst( $type ) .
"\n" . str_repeat(
'=', strlen( $type ) ) .
"\n";
179 foreach ( $things as $thing => $info ) {
180 $why = $info[
'why'] ?? [];
182 $whyText =
'(because: ' . implode(
',', $why ) .
') ';
186 $msg = isset( $info[
'message'] ) ?
", {$info['message']}" :
'';
188 $text .=
"$thing: {$info['status']}{$msg} $whyText\n";
193 return trim( $text );