43 parent::__construct();
45 $this->
addOption(
'extensions',
'Comma separated list of extensions to check',
false,
true );
46 $this->
addOption(
'skins',
'Comma separated list of skins to check',
false,
true );
47 $this->
addOption(
'json',
'Output in JSON' );
48 $this->
addOption(
'dev',
'Check development dependencies too' );
52 $this->checkDev = $this->
hasOption(
'dev' );
53 $extensions = $this->
hasOption(
'extensions' )
54 ? explode(
',', $this->
getOption(
'extensions' ) )
57 ? explode(
',', $this->
getOption(
'skins' ) )
63 $registry = ExtensionRegistry::getInstance();
64 foreach ( $extensions as $extension ) {
65 if ( !$this->checkDev && $registry->isLoaded( $extension ) ) {
67 $this->addToDependencies( $dependencies, [ $extension ], [] );
70 $this->loadThing( $dependencies, $extension, [ $extension ], [] );
73 foreach ( $skins as $skin ) {
74 if ( !$this->checkDev && $registry->isLoaded( $skin ) ) {
76 $this->addToDependencies( $dependencies, [], [ $skin ] );
79 $this->loadThing( $dependencies, $skin, [], [ $skin ] );
83 $this->
output( json_encode( $dependencies ) .
"\n" );
85 $this->
output( $this->formatForHumans( $dependencies ) .
"\n" );
89 private function loadThing( &$dependencies, $name, $extensions, $skins ) {
90 $extDir = $this->
getConfig()->get( MainConfigNames::ExtensionDirectory );
91 $styleDir = $this->
getConfig()->get( MainConfigNames::StyleDirectory );
94 foreach ( $extensions as $extension ) {
95 $path =
"$extDir/$extension/extension.json";
96 if ( file_exists(
$path ) ) {
99 $this->addToDependencies( $dependencies, [ $extension ], [], $name );
102 $this->addToDependencies( $dependencies, [ $extension ], [], $name,
'missing' );
106 foreach ( $skins as $skin ) {
107 $path =
"$styleDir/$skin/skin.json";
108 if ( file_exists(
$path ) ) {
110 $this->addToDependencies( $dependencies, [], [ $skin ], $name );
113 $this->addToDependencies( $dependencies, [], [ $skin ], $name,
'missing' );
123 $registry->setCheckDevRequires( $this->checkDev );
125 $registry->readFromQueue( $queue );
128 if ( $e->incompatibleCore ) {
129 $reason =
'incompatible-core';
130 } elseif ( $e->incompatibleSkins ) {
131 $reason =
'incompatible-skins';
132 } elseif ( $e->incompatibleExtensions ) {
133 $reason =
'incompatible-extensions';
134 } elseif ( $e->missingExtensions || $e->missingSkins ) {
140 array_merge( $extensions, $e->missingExtensions ),
141 array_merge( $skins, $e->missingSkins )
151 $this->addToDependencies( $dependencies, $extensions, $skins, $name, $reason, $e->getMessage() );
154 $this->addToDependencies( $dependencies, $extensions, $skins, $name );
157 private function addToDependencies( &$dependencies, $extensions, $skins,
158 $why =
null, $status =
null, $message =
null
160 $mainRegistry = ExtensionRegistry::getInstance();
161 $iter = [
'extensions' => $extensions,
'skins' => $skins ];
162 foreach ( $iter as $type => $things ) {
163 foreach ( $things as $thing ) {
164 $preStatus = $dependencies[$type][$thing][
'status'] ??
false;
165 if ( $preStatus !==
'loaded' ) {
170 $tStatus = $mainRegistry->isLoaded( $thing ) ?
'loaded' :
'present';
172 $dependencies[$type][$thing][
'status'] = $tStatus;
174 if ( $why !==
null ) {
175 $dependencies[$type][$thing][
'why'][] = $why;
177 $dependencies[$type][$thing][
'why'] = array_unique(
178 $dependencies[$type][$thing][
'why'] );
181 if ( $message !==
null ) {
182 $dependencies[$type][$thing][
'message'] = trim( $message );
189 private function formatForHumans( $dependencies ) {
191 foreach ( $dependencies as $type => $things ) {
192 $text .= ucfirst( $type ) .
"\n" . str_repeat(
'=', strlen( $type ) ) .
"\n";
193 foreach ( $things as $thing => $info ) {
194 $why = $info[
'why'] ?? [];
196 $whyText =
'(because: ' . implode(
',', $why ) .
') ';
200 $msg = isset( $info[
'message'] ) ?
", {$info['message']}" :
'';
202 $text .=
"$thing: {$info['status']}{$msg} $whyText\n";
207 return trim( $text );