From 73740bc10e8c3d032b1759473ce3de3548809a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 2 Mar 2019 14:35:05 +0100 Subject: [PATCH] autoloader for egulias lib needed by swiftmailer --- htdocs/includes/swiftmailer/autoload.php | 13 +++ .../egulias/email-validator/AutoLoader.php | 82 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 htdocs/includes/swiftmailer/autoload.php create mode 100644 htdocs/includes/swiftmailer/egulias/email-validator/AutoLoader.php diff --git a/htdocs/includes/swiftmailer/autoload.php b/htdocs/includes/swiftmailer/autoload.php new file mode 100644 index 00000000000..b796c9cf3e8 --- /dev/null +++ b/htdocs/includes/swiftmailer/autoload.php @@ -0,0 +1,13 @@ +register(); diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/AutoLoader.php b/htdocs/includes/swiftmailer/egulias/email-validator/AutoLoader.php new file mode 100644 index 00000000000..06339e869bf --- /dev/null +++ b/htdocs/includes/swiftmailer/egulias/email-validator/AutoLoader.php @@ -0,0 +1,82 @@ + + */ +class EguliasAutoLoader +{ + /** + * @var string The namespace prefix for this instance. + */ + protected $namespace = ''; + + /** + * @var string The filesystem prefix to use for this instance + */ + protected $path = ''; + + /** + * Build the instance of the autoloader + * + * @param string $namespace The prefixed namespace this instance will load + * @param string $path The filesystem path to the root of the namespace + */ + public function __construct($namespace, $path) + { + $this->namespace = ltrim($namespace, '\\'); + $this->path = rtrim($path, '/\\') . DIRECTORY_SEPARATOR; + } + + /** + * Try to load a class + * + * @param string $class The class name to load + * + * @return boolean If the loading was successful + */ + public function load($class) + { + $class = ltrim($class, '\\'); + if (strpos($class, $this->namespace) === 0) { + $nsparts = explode('\\', $class); + $class = array_pop($nsparts); + $path = $this->path . 'swiftmailer/egulias/email-validator/EmailValidator/'; + $max=count($nsparts); + for ($i=2; $i<$max;$i++) { + $path .= $nsparts[$i].'/'; + } + $nsparts = array(); + $path .= str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; + if (file_exists($path)) { + require $path; + return true; + } + } + + return false; + } + + /** + * Register the autoloader to PHP + * + * @return boolean The status of the registration + */ + public function register() + { + return spl_autoload_register(array($this, 'load')); + } + + /** + * Unregister the autoloader to PHP + * + * @return boolean The status of the unregistration + */ + public function unregister() + { + return spl_autoload_unregister(array($this, 'load')); + } +}