cookie-law-info
Last commit date
languages
2 years ago
legacy
2 years ago
lite
2 years ago
public
2 years ago
class-autoloader.php
2 years ago
cookie-law-info.php
2 years ago
license.txt
2 years ago
readme.txt
2 years ago
uninstall.php
2 years ago
wpml-config.xml
2 years ago
class-autoloader.php
51 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Custom autoloader |
| 4 | * |
| 5 | * @package CookieYes |
| 6 | */ |
| 7 | |
| 8 | namespace CookieYes\Lite; |
| 9 | |
| 10 | /** |
| 11 | * Custom class autoloader class |
| 12 | */ |
| 13 | class Autoloader { |
| 14 | |
| 15 | /** |
| 16 | * Autoloader function |
| 17 | * |
| 18 | * @return void |
| 19 | */ |
| 20 | public function register() { |
| 21 | spl_autoload_register( array( __CLASS__, 'load_class' ) ); |
| 22 | } |
| 23 | /** |
| 24 | * Custom Class Loader For Boiler Plate |
| 25 | * |
| 26 | * @param string $class_name Class names. |
| 27 | * @return void |
| 28 | */ |
| 29 | public static function load_class( $class_name ) { |
| 30 | if ( false === strpos( $class_name, 'CookieYes' ) ) { |
| 31 | return; |
| 32 | } |
| 33 | $file_parts = explode( '\\', $class_name ); |
| 34 | $namespace = ''; |
| 35 | for ( $i = count( $file_parts ) - 1; $i > 0; $i-- ) { |
| 36 | |
| 37 | $current = strtolower( $file_parts[ $i ] ); |
| 38 | $current = str_ireplace( '_', '-', $current ); |
| 39 | if ( count( $file_parts ) - 1 === $i ) { |
| 40 | $file_name = "class-$current.php"; |
| 41 | } else { |
| 42 | $namespace = '/' . $current . $namespace; |
| 43 | } |
| 44 | } |
| 45 | $filepath = dirname( __FILE__ ) . $namespace . '/' . $file_name; |
| 46 | if ( file_exists( $filepath ) ) { |
| 47 | require $filepath; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 |