Add an autoloader
authorgggeek <giunta.gaetano@gmail.com>
Sun, 22 Mar 2015 18:52:31 +0000 (18:52 +0000)
committergggeek <giunta.gaetano@gmail.com>
Sun, 22 Mar 2015 18:52:31 +0000 (18:52 +0000)
src/Autoloader.php [new file with mode: 0644]

diff --git a/src/Autoloader.php b/src/Autoloader.php
new file mode 100644 (file)
index 0000000..b03b1cb
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+namespace PhpXmlRpc;
+
+/**
+ * In the unlikely event that you are not using Composer to manage class autoloading, here's an autoloader for this lib.
+ * For usage, see any file in the demo/client directory
+ */
+class Autoloader
+{
+    /**
+     * Registers PhpXmlRpc\Autoloader as an SPL autoloader.
+     *
+     * @param bool $prepend Whether to prepend the autoloader or not.
+     */
+    public static function register($prepend = false)
+    {
+        spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
+    }
+
+    /**
+     * Handles autoloading of classes.
+     *
+     * @param string $class A class name.
+     */
+    public static function autoload($class)
+    {
+        if (0 !== strpos($class, 'PhpXmlRpc\\')) {
+            return;
+        }
+
+        if (is_file($file = __DIR__ . str_replace('PhpXmlRpc\\', '/', $class).'.php')) {
+            require $file;
+        }
+    }
+}
\ No newline at end of file