diff --git a/autoload.php b/autoload.php index 5d014cd..ad0ccb8 100644 --- a/autoload.php +++ b/autoload.php @@ -1,34 +1,38 @@ . /** * Minimal autoload (without functions) * * This is useful if you like creating frameworks. * * If you love creating bots instead, see the 'autoload-with-laser-cannon.php'. */ /** * Autoload classes on-demand */ spl_autoload_register( function( $name ) { + + // traits have not a dedicated class, so this trick autoloads them + $name = str_replace( 'Trait', '', $name ); + $path = __DIR__ . "/include/class-$name.php"; if( is_file( $path ) ) { require $path; } } ); diff --git "a/include/class-mw\\StaticSite.php" "b/include/class-mw\\StaticSite.php" index 96659f3..c84c150 100644 --- "a/include/class-mw\\StaticSite.php" +++ "b/include/class-mw\\StaticSite.php" @@ -1,67 +1,64 @@ . # MediaWiki namespace mw; -// traits can't be autoloaded, so... -require_once 'class-generic\Singleton.php'; - /** * The behaviours for a static site * * They are declared in a trait on order to be recycled it e.g. in mw\StaticWikibaseSite */ trait StaticSiteTrait { use \generic\Singleton; /** * @override */ protected static function create() { $site = static::createFromAPIURL( static::getApiURL() ); $site->setUID( static::UID ); // Set default namespaces foreach( Ns::defaultCanonicalNames() as $ns_id => $ns ) { $site->setNamespace( new Ns( $ns_id, $ns ) ); } return $site; } /** * To be overloaded. * * @return string */ protected static function getApiURL() { return static::API_URL; } } /** * A static site is a site that must be used statically */ class StaticSite extends Site { use StaticSiteTrait; } diff --git "a/include/class-mw\\StaticWikibaseSite.php" "b/include/class-mw\\StaticWikibaseSite.php" index 57fc65a..fd09544 100644 --- "a/include/class-mw\\StaticWikibaseSite.php" +++ "b/include/class-mw\\StaticWikibaseSite.php" @@ -1,31 +1,28 @@ . # MediaWiki namespace mw; -# traits can't be autoloaded, so... -require_once 'class-mw\StaticSite.php'; - /** * A static MediaWiki site with Wikibase enabled */ class StaticWikibaseSite extends WikibaseSite { use \mw\StaticSiteTrait; }