Skip to content

Commit

Permalink
Issue #132 - make it easier to use oik_autoload
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Jan 30, 2021
1 parent ffdf2ba commit 548dd5c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
24 changes: 14 additions & 10 deletions libs/class-oik-autoload.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php // (C) Copyright Bobbing Wide 2016-2021
<?php
if ( !defined( "CLASS_OIK_AUTOLOAD_INCLUDED" ) ) {
define( "CLASS_OIK_AUTOLOAD_INCLUDED", "1.0.0" );
define( "CLASS_OIK_AUTOLOAD_INCLUDED", "1.1.0" );

/**
* @copyright (C) Copyright Bobbing Wide 2016-2021
* @package oik, oik-libs
*
* Implement autoloading for shared libraries
*
* The autoload function is not supposed to load the classes willy nilly.
Expand Down Expand Up @@ -49,23 +52,26 @@ public static function instance() {
}
return self::$instance;
}

/**
* Constructor for the OIK_autoload class
*/
function __construct() {
$this->autoload_shared_library = false;
spl_autoload_register( array( $this, 'autoload' ) );
}

/**
* Runs / reruns the oik_query_autoload_classes filter.
*/
function query_autoload_classes() {
self::$loads = array();
$loads_more = apply_filters( "oik_query_autoload_classes", self::$loads );
self::$loads = $loads_more;
$this->classes = null;
//self::loads( $loads_more );
spl_autoload_register( array( $this, 'autoload' ) );
}


/**
* Autoload a class if we know how to
/**
* Autoloads a class if we know how to.
*
* The fact that we have gotten here means that the class is not already loaded so we need to load it.
* @TODO We should also know which pre-requisite classes to load. Does spl_autoload_register() handle this?
Expand All @@ -90,8 +96,6 @@ function autoload( $class ) {
$this->load_shared_library_class_file( $class );
}
}



/**
* Determine the file name from the class and path
Expand Down
1 change: 1 addition & 0 deletions libs/oik-autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function oik_autoload( $autoload_shared_library=false ) {
if ( class_exists( "OIK_Autoload" ) ) {
$oik_autoload = OIK_Autoload::instance();
$oik_autoload->set_autoload_shared_library( $autoload_shared_library );
$oik_autoload->query_autoload_classes();
} else {
bw_trace2( "Class OIK_Autoload does not exist", null, false, BW_TRACE_ERROR );
die();
Expand Down

0 comments on commit 548dd5c

Please sign in to comment.