From 7763d0eec57ad56dc96fdb734b286a57227f1712 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Fri, 6 Jun 2008 06:00:21 +0000 Subject: [PATCH] Add autoload support for simpleSAMLphp. This patch adds a autoloader file (lib/_autoload.php), and changes www/_include.php to load this file. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@608 44740490-163a-0410-bde0-09ae8108e29a --- lib/_autoload.php | 39 +++++++++++++++++++++++++++++++++++++++ www/_include.php | 4 ++++ 2 files changed, 43 insertions(+) create mode 100644 lib/_autoload.php diff --git a/lib/_autoload.php b/lib/_autoload.php new file mode 100644 index 000000000..b05ee4569 --- /dev/null +++ b/lib/_autoload.php @@ -0,0 +1,39 @@ +<?php + +/** + * This file implements a autoloader for simpleSAMLphp. This autoloader + * will search for files under the simpleSAMLphp directory. + * + * @author Olav Morken, UNINETT AS. + * @package simpleSAMLphp + * @version $Id$ + */ + + +/** + * Autoload function for simpleSAMLphp. + * + * It will autoload all classes stored in the lib-directory. + * + * @param $className The name of the class. + */ +function SimpleSAML_autoload($className) { + + $libDir = dirname(__FILE__) . '/'; + + /* Special handling for xmlseclibs.php. */ + if(in_array($className, array('XMLSecurityKey', 'XMLSecurityDSig', 'XMLSecEnc'), TRUE)) { + require_once($libDir . 'xmlseclibs.php'); + return; + } + + $file = $libDir . str_replace('_', '/', $className) . '.php'; + if(file_exists($file)) { + require_once($file); + } +} + +/* Register autload function for simpleSAMLphp. */ +spl_autoload_register('SimpleSAML_autoload'); + +?> \ No newline at end of file diff --git a/www/_include.php b/www/_include.php index b804e3f26..4fc9c697f 100644 --- a/www/_include.php +++ b/www/_include.php @@ -18,6 +18,10 @@ if(get_magic_quotes_gpc()) { } } + +/* Initialize the autoloader. */ +require_once(dirname(dirname(__FILE__)) . '/lib/_autoload.php'); + $path_extra = dirname(dirname(__FILE__)) . '/lib'; -- GitLab