summaryrefslogtreecommitdiffstats
path: root/vendor/wikimedia/less.php/lib/Less/Autoloader.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:30:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:30:08 +0000
commit4ce65d59ca91871cfd126497158200a818720bce (patch)
treee277def01fc7eba7dbc21c4a4ae5576e8aa2cf1f /vendor/wikimedia/less.php/lib/Less/Autoloader.php
parentInitial commit. (diff)
downloadicinga-php-library-upstream/0.13.1.tar.xz
icinga-php-library-upstream/0.13.1.zip
Adding upstream version 0.13.1.upstream/0.13.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/wikimedia/less.php/lib/Less/Autoloader.php')
-rw-r--r--vendor/wikimedia/less.php/lib/Less/Autoloader.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/vendor/wikimedia/less.php/lib/Less/Autoloader.php b/vendor/wikimedia/less.php/lib/Less/Autoloader.php
new file mode 100644
index 0000000..a4f7a4a
--- /dev/null
+++ b/vendor/wikimedia/less.php/lib/Less/Autoloader.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * Autoloader
+ */
+class Less_Autoloader {
+
+ /** @var bool */
+ protected static $registered = false;
+
+ /**
+ * Register the autoloader in the SPL autoloader
+ *
+ * @return void
+ * @throws Exception If there was an error in registration
+ */
+ public static function register() {
+ if ( self::$registered ) {
+ return;
+ }
+
+ if ( !spl_autoload_register( [ 'Less_Autoloader', 'loadClass' ] ) ) {
+ throw new Exception( 'Unable to register Less_Autoloader::loadClass as an autoloading method.' );
+ }
+
+ self::$registered = true;
+ }
+
+ /**
+ * Unregister the autoloader
+ *
+ * @return void
+ */
+ public static function unregister() {
+ spl_autoload_unregister( [ 'Less_Autoloader', 'loadClass' ] );
+ self::$registered = false;
+ }
+
+ /**
+ * Load the class
+ *
+ * @param string $className The class to load
+ */
+ public static function loadClass( $className ) {
+ // handle only package classes
+ if ( strpos( $className, 'Less_' ) !== 0 ) {
+ return;
+ }
+
+ $className = substr( $className, 5 );
+ $fileName = __DIR__ . DIRECTORY_SEPARATOR . str_replace( '_', DIRECTORY_SEPARATOR, $className ) . '.php';
+
+ require $fileName;
+ return true;
+ }
+
+}