85 if ( !is_array( $flags ) ) {
90 if ( in_array(
'local', $flags ) ) {
91 $this->variableName =
'wgAutoloadLocalClasses';
102 foreach ( $paths as
$path ) {
117 foreach ( $namespaces as $ns =>
$path ) {
118 $ns = rtrim( $ns,
'\\' ) .
'\\';
119 $this->psr4Namespaces[$ns] = rtrim( self::normalizePathSeparator(
$path ),
'/' );
130 foreach ( $this->excludePaths as $dir ) {
131 if ( strpos(
$path, $dir ) === 0 ) {
150 throw new \Exception(
"Invalid path: $inputPath" );
152 $len = strlen( $this->basepath );
153 if ( substr(
$path, 0, $len ) !== $this->basepath ) {
154 throw new \Exception(
"Path is not within basepath: $inputPath" );
156 $shortpath = substr(
$path, $len );
157 $this->overrides[$fqcn] = $shortpath;
169 $len = strlen( $this->basepath );
170 if ( substr( $inputPath, 0, $len ) !== $this->basepath ) {
171 throw new \Exception(
"Path is not within basepath: $inputPath" );
176 $result = $this->collector->getClasses(
177 file_get_contents( $inputPath )
181 $result = array_filter( $result,
function ( $class ) use ( $inputPath ) {
182 $parts = explode(
'\\', $class );
183 for ( $i = count( $parts ) - 1; $i > 0; $i-- ) {
184 $ns = implode(
'\\', array_slice( $parts, 0, $i ) ) .
'\\';
185 if ( isset( $this->psr4Namespaces[$ns] ) ) {
186 $expectedPath = $this->psr4Namespaces[$ns] .
'/'
187 . implode(
'/', array_slice( $parts, $i ) )
189 if ( $inputPath === $expectedPath ) {
199 $shortpath = substr( $inputPath, $len );
200 $this->classes[$shortpath] = $result;
209 $it =
new RecursiveDirectoryIterator(
210 self::normalizePathSeparator( realpath( $dir ) ) );
211 $it =
new RecursiveIteratorIterator( $it );
214 $ext = pathinfo(
$path, PATHINFO_EXTENSION );
216 if (
$ext ===
'php' ||
$ext ===
'inc' ) {
231 $key =
'AutoloadClasses';
233 unset( $json[$key] );
236 foreach ( $this->classes as
$path => $contained ) {
237 foreach ( $contained as $fqcn ) {
239 $json[$key][$fqcn] = substr(
$path, 1 );
242 foreach ( $this->overrides as
$path => $fqcn ) {
244 $json[$key][$fqcn] = substr(
$path, 1 );
248 ksort( $json[$key] );
267 $format =
"%s => __DIR__ . %s,";
268 foreach ( $this->classes as
$path => $contained ) {
269 $exportedPath = var_export(
$path,
true );
270 foreach ( $contained as $fqcn ) {
273 var_export( $fqcn,
true ),
279 foreach ( $this->overrides as $fqcn =>
$path ) {
282 var_export( $fqcn,
true ),
283 var_export(
$path,
true )
292 if ( $this->variableName ===
'wgAutoloadClasses' ) {
303 global \${$this->variableName};
305 \${$this->variableName} {$op} [
320 public function getAutoload( $commandName =
'AutoloadGenerator' ) {
326 if (
$fileinfo[
'type'] === self::FILETYPE_JSON ) {
343 'filename' => $this->basepath .
'/autoload.php',
346 if ( file_exists( $this->basepath .
'/extension.json' ) ) {
348 'filename' => $this->basepath .
'/extension.json',
351 } elseif ( file_exists( $this->basepath .
'/skin.json' ) ) {
353 'filename' => $this->basepath .
'/skin.json',
368 return str_replace(
'\\',
'/',
$path );
381 foreach ( [
'includes',
'languages',
'maintenance',
'mw-config' ] as $dir ) {
382 $this->
readDir( $this->basepath .
'/' . $dir );
384 foreach ( glob( $this->basepath .
'/*.php' ) as
$file ) {