This repository has been archived by the owner on Sep 20, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from wmde/revertautoloadcommit
Revert "Improve autoloading code"
- Loading branch information
Showing
6 changed files
with
95 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/** | ||
* Test class autoloader for the Wikibase Database component. | ||
* | ||
* @since 0.1 | ||
* | ||
* @licence GNU GPL v2+ | ||
* @author Jeroen De Dauw < jeroendedauw@gmail.com > | ||
*/ | ||
|
||
spl_autoload_register( function ( $className ) { | ||
$className = ltrim( $className, '\\' ); | ||
$fileName = ''; | ||
$namespace = ''; | ||
|
||
if ( $lastNsPos = strripos( $className, '\\') ) { | ||
$namespace = substr( $className, 0, $lastNsPos ); | ||
$className = substr( $className, $lastNsPos + 1 ); | ||
$fileName = str_replace( '\\', '/', $namespace ) . '/'; | ||
} | ||
|
||
$fileName .= str_replace( '_', '/', $className ) . '.php'; | ||
|
||
$namespaceSegments = explode( '\\', $namespace ); | ||
|
||
$inTestNamespace = count( $namespaceSegments ) > 2 | ||
&& $namespaceSegments[0] === 'Wikibase' | ||
&& $namespaceSegments[1] === 'Database' | ||
&& $namespaceSegments[2] === 'Tests'; | ||
|
||
if ( $inTestNamespace ) { | ||
$pathParts = explode( '/', $fileName ); | ||
array_shift( $pathParts ); | ||
array_shift( $pathParts ); | ||
array_shift( $pathParts ); | ||
$fileName = implode( '/', $pathParts ); | ||
|
||
require_once __DIR__ . '/phpunit/' . $fileName; | ||
} | ||
} ); |