Created
September 17, 2016 12:18
-
-
Save derpixler/fa9b586f9af602e88ed6ec29fc15611d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php # -*- coding: utf-8 -*- | |
namespace [PLUGIN]\Addons; | |
class Loader { | |
/** | |
* @var array | |
*/ | |
const ADDONSPATH = '/../Addons/'; | |
public $addons; | |
public function __construct() { | |
$this->load_addons( | |
$this->glob_recursive( dirname( __FILE__ ) . self::ADDONSPATH . "*.php" ) | |
); | |
} | |
private function load_addons( $addons ){ | |
if( empty( $addons ) ){ | |
return false; | |
} | |
$this->addons = new \stdClass(); | |
foreach( $addons as $addon ){ | |
if( __NAMESPACE__ . '\\' . basename( $addon ) != __CLASS__ . '.php' ){ | |
$addon = pathinfo( $addon ); | |
$addonname = $addon[ 'filename' ]; | |
$this->addons->$addonname = new \stdClass(); | |
$this->addons->$addonname->file = $addon[ 'basename' ]; | |
$this->addons->$addonname->namespace = __NAMESPACE__ . '\\' . basename( $addon[ 'dirname' ] ) . '\\'; | |
$class = $this->addons->$addonname->namespace . $addonname; | |
$this->addons->$addonname->data = new $class( $this->addons->$addonname ); | |
} | |
} | |
die(); | |
} | |
private function glob_recursive( $pattern, $flags = 0) { | |
$files = glob($pattern, $flags); | |
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { | |
$files = array_merge( $files, $this->glob_recursive( $dir . '/' . basename( $pattern ) , $flags) ); | |
} | |
return $files; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment