From 2a1db64b3ab5e0050807f7f9dbcfe29b72809aaa Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Tue, 12 Feb 2019 14:50:15 +0100 Subject: Migrate old style constructors to __construct, temporary transition functions for it_dbi (map, mapgen) and it_user (ad, login_user) --- it_browser.class | 2 +- it_dbi.class | 12 +++++++++--- it_debug.class | 2 +- it_mail.class | 2 +- it_session.class | 2 +- it_syntaxconverter.class | 2 +- it_text.class | 2 +- it_url.class | 6 +++--- it_user.class | 9 +++++++-- it_xml.class | 2 +- test/it_xml.t | 2 +- 11 files changed, 27 insertions(+), 16 deletions(-) diff --git a/it_browser.class b/it_browser.class index cb64755..1154d52 100644 --- a/it_browser.class +++ b/it_browser.class @@ -54,7 +54,7 @@ class it_browser /** * Constructor: Initializes public fields with browser capabilities */ -function it_browser() +function __construct() { $this->UserAgent = $_SERVER['HTTP_USER_AGENT']; /* $this->UserAgent = "Mozilla/4.0 [de] (compatible; MSIE 5.0; Windows 95; .NET CRL 2.0.154)"; */ diff --git a/it_dbi.class b/it_dbi.class index d3dbc11..6f976d5 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -58,7 +58,7 @@ class it_dbi * @param $p optional array(key => value) of configuration data * @param $query Optional initial query to run */ -function it_dbi($p = array(), $query = null) +function __construct($p = array(), $query = null) { # Shortcut: String config means use this table with default values if (!is_array($p)) @@ -100,6 +100,12 @@ function it_dbi($p = array(), $query = null) $GLOBALS['it_dbi'] =& $this; } +# Migration helper function +function it_dbi($p = array(), $query = null) +{ + return self::__construct($p, $query); +} + /** * function Tablename($query) * Constructor. Returns record object from table Tablename. @@ -180,7 +186,7 @@ static function createclass($p) $interface = function_exists("interface_exists") && interface_exists("Iterator", false) ? "implements Iterator" : ""; $code = "class $classname extends it_dbi $interface { - function $classname(/* \$query ... */) + function __construct(/* \$query ... */) { \$args = func_get_args(); \$query = array_shift(\$args); # Preserve type (scalar/array) in single parameter case @@ -188,7 +194,7 @@ static function createclass($p) foreach (\$args as \$arg) \$query = array_merge((array)\$query, (array)\$arg); - \$this->it_dbi(" . var_export($p, true) . ", \$query); + parent::__construct(" . var_export($p, true) . ", \$query); } }"; diff --git a/it_debug.class b/it_debug.class index c508b5e..8dc12c2 100644 --- a/it_debug.class +++ b/it_debug.class @@ -30,7 +30,7 @@ class it_debug * Constructor * @param $level Debug level. All debug() calls with a level <= $level are shown. */ -function it_debug($level=0) +function __construct($level=0) { $this->level = isset($GLOBALS['debug_level']) ? $GLOBALS['debug_level'] : $level; } diff --git a/it_mail.class b/it_mail.class index a407e54..1db36cb 100644 --- a/it_mail.class +++ b/it_mail.class @@ -61,7 +61,7 @@ class it_mail * Note: Headers To, Cc, Bcc can be arrays * @param $headers Array of headers for this email, e.g. From, To and Subject */ -function it_mail($headers = array()) +function __construct($headers = array()) { $this->charset = ini_get('default_charset'); diff --git a/it_session.class b/it_session.class index ec8b64f..f1dc541 100644 --- a/it_session.class +++ b/it_session.class @@ -38,7 +38,7 @@ class it_session var $hascookies; /* Do cookies work? Used by has_cookies() */ /* Constructor */ -function it_session() +function __construct() { $this->cookiename = _IT_SESSION_COOKIE; $this->lifetime = _IT_SESSION_LIFETIME; diff --git a/it_syntaxconverter.class b/it_syntaxconverter.class index 58256c0..bca1fb8 100644 --- a/it_syntaxconverter.class +++ b/it_syntaxconverter.class @@ -37,7 +37,7 @@ class it_syntaxconverter # # Constructor # -function it_syntaxconverter($string, $mode = "old") +function __construct($string, $mode = "old") { if (defined('T_ML_COMMENT')) $this->whitespace[T_ML_COMMENT] = true; # PHP4 diff --git a/it_text.class b/it_text.class index 42753a8..69b2e0e 100644 --- a/it_text.class +++ b/it_text.class @@ -38,7 +38,7 @@ class it_text * @param $p['phpfiles'] text files to load in addition to $p['phpfile'] (Note: $p['phpfile'] defaults to all texts.php files in include path) * @param $p['transmogrifiers'] comma separated functions that may be called by using {foo:bar} (foo will be called with bar as argument) in T() */ -function it_text($p = array()) +function __construct($p = array()) { if (!$p['phpfile']) { diff --git a/it_url.class b/it_url.class index 125f5d2..7b364d2 100644 --- a/it_url.class +++ b/it_url.class @@ -45,7 +45,7 @@ class it_url * Constructor: canonicalize an URL * @param $url URL this object represents */ -function it_url($url = null) +function __construct($url = null) { $this->rawurl = $url; $comp = parse_url($url); @@ -124,7 +124,7 @@ function get($p=null, $timeout=5) { $url = $this; if ($p['url']) - $this->it_url($p['url']); + $this->__construct($p['url']); } else # called statically $url = new it_url($p['url']); @@ -250,7 +250,7 @@ function request($p=array()) { $url = $this; if ($p['url']) - $this->it_url($p['url']); + $this->__construct($p['url']); $url->headers = array(); $p['headers'] = (array)$p['headers'] + self::_default_headers($url, $p); diff --git a/it_user.class b/it_user.class index 914d3e3..2f891ef 100644 --- a/it_user.class +++ b/it_user.class @@ -59,7 +59,7 @@ class it_user extends it_dbi * Constructor * @param $p array(key => value) of configuration data */ -function it_user($p = array()) +function __construct($p = array()) { $this->p = $p + array( 'uid_field' => 'ID', @@ -71,12 +71,17 @@ function it_user($p = array()) ); # Default to uid being primary key, may change later - $this->it_dbi(array('table' => $this->p['table'], 'keyfield' => $this->p['uid_field'])); + parent::__construct(array('table' => $this->p['table'], 'keyfield' => $this->p['uid_field'])); $this->session = new it_session; $this->status = _IT_USER_STATUS_INVALID; } +# Migration helper function +function it_user($p = array()) +{ + return self::__construct($p); +} /** * Post processing, called by ITools after reading a database record diff --git a/it_xml.class b/it_xml.class index 4e838c1..2e687e1 100644 --- a/it_xml.class +++ b/it_xml.class @@ -33,7 +33,7 @@ class it_xml * @return XML object tree or null on failure */ -function it_xml($xmldata = "", $p = array()) +function __construct($xmldata = "", $p = array()) { if ($xmldata) $this->from_xml($xmldata, $p); diff --git a/test/it_xml.t b/test/it_xml.t index f53ceeb..4df340a 100755 --- a/test/it_xml.t +++ b/test/it_xml.t @@ -97,7 +97,7 @@ class my_xml extends it_xml function my_xml($xmldata) { - parent::it_xml($xmldata); + parent::__construct($xmldata); # Code which should be executed in root and only there $this->qux = new it_xml; -- cgit v1.2.3