From: konrad Date: Tue, 25 May 2010 17:56:33 +0000 (+0000) Subject: change to SPL autoloader X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=88ddbe696d7ee798d735304c07c4abd6c902d31c;p=konrad%2Fpack.git change to SPL autoloader git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@475 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/phpbase/autoload.php b/phpbase/autoload.php index 3498aee..9717817 100644 --- a/phpbase/autoload.php +++ b/phpbase/autoload.php @@ -9,25 +9,41 @@ // +---------------------------------------------------------------------- // +/**registers a class to be loaded automatically*/ +function wob_autoclass($cname,$fname) +{ + global $WOB_AUTOCLASSREG; + if(is_string($cname) && is_string($fname)){ + $WOB_AUTOCLASSREG[$cname]=$fname; + return true; + }else + return false; +} + $d=dirname(__FILE__); -$AUTOCLASS["DbEngine"]=$d.'/db.php'; -$AUTOCLASS["MysqlEngine"]=$d.'/db_mysql.php'; -$AUTOCLASS["PGsqlEngine"]=$d.'/db_pgsql.php'; -$AUTOCLASS["WobTable"]= $d."/table.php"; -$AUTOCLASS["WobSchemaBase"]=$d."/schema.php"; -$AUTOCLASS["WobTransactionBase"]=$d."/transaction.php"; -$AUTOCLASS["WobXmlException"]=$d."/exception.php"; -$AUTOCLASS["WobTransactionError"]=$d."/exception.php"; -$AUTOCLASS["WObject"]=$d."/object.php"; +wob_autoclass("DbEngine",$d.'/db.php'); +wob_autoclass("MysqlEngine",$d.'/db_mysql.php'); +wob_autoclass("PGsqlEngine",$d.'/db_pgsql.php'); +wob_autoclass("WobTable", $d."/table.php"); +wob_autoclass("WobSchemaBase",$d."/schema.php"); +wob_autoclass("WobTransactionBase",$d."/transaction.php"); +wob_autoclass("WobXmlException",$d."/exception.php"); +wob_autoclass("WobTransactionError",$d."/exception.php"); +wob_autoclass("WObject",$d."/object.php"); //load the linguist dummies, since we use them quite often include_once($d."/tr.php"); unset($d); -function __autoload($cname) +function wob_autoload($cname) { - global $AUTOCLASS; - if(isset($AUTOCLASS[$cname])) - require_once $AUTOCLASS[$cname]; + global $WOB_AUTOCLASSREG; + if(isset($WOB_AUTOCLASSREG[$cname])){ + require_once $WOB_AUTOCLASSREG[$cname]; + return true; + }else{ + return false; + } } +spl_autoload_register('wob_autoload'); ?> diff --git a/phpbase/tr.php b/phpbase/tr.php index 92dbaf7..d102eb8 100644 --- a/phpbase/tr.php +++ b/phpbase/tr.php @@ -5,7 +5,7 @@ // Description: dummy implementation for Qt's tr and transalate to make the PHP code // compatible with linguist // -// Author: Konrad Rosenbaum , (C) 2008 +// Author: Konrad Rosenbaum , (C) 2008-2010 // // Copyright: See README/COPYING files that come with this distribution // diff --git a/woc/phpout.cpp b/woc/phpout.cpp index 9916e33..7350efd 100644 --- a/woc/phpout.cpp +++ b/woc/phpout.cpp @@ -304,7 +304,7 @@ void WocPHPServerOut::newTable(const WocTable&tbl) void WocPHPServerOut::addLoad(QString cn,QString fn) { - QString ld="$AUTOCLASS[\""+cn+"\"]=$d.\"/"+fn+m_fileext+"\";\n"; + QString ld="wob_autoclass(\""+cn+"\",$d.\"/"+fn+m_fileext+"\");\n"; m_loader.write(ld.toAscii()); }