-
Notifications
You must be signed in to change notification settings - Fork 1
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 #16 from zackpyle/Wordpress-Updater
Wordpress updater
- Loading branch information
Showing
10 changed files
with
544 additions
and
14 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,91 @@ | ||
<?php | ||
/** | ||
* Autoloader class | ||
* | ||
* @package BBClassDropdown | ||
* @since 1.0.0 | ||
*/ | ||
|
||
namespace BBClassDropdown\Includes\Updater; | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; // Exit if accessed directly | ||
} | ||
|
||
/** | ||
* Loads classes from the plugin's namespace when requested. | ||
* | ||
* Without an autoloader, we would have to `require` or `include` every class file ourselves. An autoloader takes care | ||
* of this for us. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
class Autoloader { | ||
|
||
/** | ||
* Namespace prefix of all classes this autoloader should handle, trailing slash included. | ||
* | ||
* @since 1.0.0 | ||
* @var string | ||
*/ | ||
const AUTOLOADED_NAMESPACE_PREFIX = 'BBClassDropdown\\'; | ||
|
||
/** | ||
* Loads the class file if it is in the autoloaded namespace. | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @param string $class The class' fully-qualified class name (e.g. \Foo\Bar\Baz). | ||
*/ | ||
public function autoload( $class ) { | ||
if ( $this->is_class_in_autoloaded_namespace( $class ) ) { | ||
$this->load_class( $class ); | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the class' namespace prefix is within the autoloaded namespace. | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @param string $class The class' fully-qualified class name. | ||
* @return bool | ||
*/ | ||
private function is_class_in_autoloaded_namespace( $class ) { | ||
$prefix_length = strlen( self::AUTOLOADED_NAMESPACE_PREFIX ); | ||
|
||
return 0 === strncmp( self::AUTOLOADED_NAMESPACE_PREFIX, $class, $prefix_length ); | ||
} | ||
|
||
/** | ||
* Loads the file containing the class if it exists. | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @param string $class The class' fully-qualified class name. | ||
*/ | ||
private function load_class( $class ) { | ||
$file_path = $this->get_class_file_path( $class ); | ||
|
||
if ( file_exists( $file_path ) ) { | ||
require $file_path; | ||
} | ||
} | ||
|
||
/** | ||
* Converts a fully-qualified class name into a path to the file where the class is defined. | ||
* | ||
* E.g. converts `\BBClassDropdown\Foo\Bar` into `<plugin root directory>/includes/Updater/Foo/Bar.php`. | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @param string $class The class' fully-qualified class name. | ||
* @return string Path to the file where we expect to find the class definition. | ||
*/ | ||
private function get_class_file_path( $class ) { | ||
$relative_class_path = substr( $class, strlen( self::AUTOLOADED_NAMESPACE_PREFIX ) ); | ||
$relative_file_path = str_replace( '\\', '/', $relative_class_path ) . '.php'; | ||
|
||
return dirname( BBCLASSDROPDOWN_FILE ) . '/includes/Updater/' . $relative_file_path; | ||
} | ||
} |
Oops, something went wrong.