Rename class Attribute to PLAAttribute.

As PHP 8 introduces a built-in Attribute class, a name clash occurs
without this commit.

Class names are used by the Visitor class to dynamically build method
names. To avoid having to also rename the target methods, a class name
mapping is introduced for this purpose. This map may be augmented
whenever another similar case occurs.
This commit is contained in:
Patrick Monnerat 2022-01-14 07:29:20 +01:00 committed by Deon George
parent 3a75a32100
commit c90dc06af2
12 changed files with 25 additions and 21 deletions

View File

@ -133,7 +133,7 @@ class AttributeFactory {
return $this->newGidAttribute($name,$values,$server_id,$source); return $this->newGidAttribute($name,$values,$server_id,$source);
} else { } else {
return new Attribute($name,$values,$server_id,$source); return new PLAAttribute($name,$values,$server_id,$source);
} }
} }

View File

@ -12,7 +12,7 @@
* @package phpLDAPadmin * @package phpLDAPadmin
* @subpackage Templates * @subpackage Templates
*/ */
class BinaryAttribute extends Attribute { class BinaryAttribute extends PLAAttribute {
protected $filepaths; protected $filepaths;
protected $filenames; protected $filenames;

View File

@ -12,6 +12,6 @@
* @package phpLDAPadmin * @package phpLDAPadmin
* @subpackage Templates * @subpackage Templates
*/ */
class DateAttribute extends Attribute { class DateAttribute extends PLAAttribute {
} }
?> ?>

View File

@ -12,6 +12,6 @@
* @package phpLDAPadmin * @package phpLDAPadmin
* @subpackage Templates * @subpackage Templates
*/ */
class DnAttribute extends Attribute { class DnAttribute extends PLAAttribute {
} }
?> ?>

View File

@ -12,6 +12,6 @@
* @package phpLDAPadmin * @package phpLDAPadmin
* @subpackage Templates * @subpackage Templates
*/ */
class GidAttribute extends Attribute { class GidAttribute extends PLAAttribute {
} }
?> ?>

View File

@ -12,7 +12,7 @@
* @package phpLDAPadmin * @package phpLDAPadmin
* @subpackage Templates * @subpackage Templates
*/ */
class MultiLineAttribute extends Attribute { class MultiLineAttribute extends PLAAttribute {
protected $rows = 0; protected $rows = 0;
protected $cols = 0; protected $cols = 0;

View File

@ -12,6 +12,6 @@
* @package phpLDAPadmin * @package phpLDAPadmin
* @subpackage Templates * @subpackage Templates
*/ */
class ObjectClassAttribute extends Attribute { class ObjectClassAttribute extends PLAAttribute {
} }
?> ?>

View File

@ -12,7 +12,7 @@
* @package phpLDAPadmin * @package phpLDAPadmin
* @subpackage Templates * @subpackage Templates
*/ */
class Attribute { class PLAAttribute {
# Attribute Name # Attribute Name
public $name; public $name;
# Source of this attribute definition # Source of this attribute definition

View File

@ -12,6 +12,6 @@
* @package phpLDAPadmin * @package phpLDAPadmin
* @subpackage Templates * @subpackage Templates
*/ */
class PasswordAttribute extends Attribute { class PasswordAttribute extends PLAAttribute {
} }
?> ?>

View File

@ -12,7 +12,7 @@
* @package phpLDAPadmin * @package phpLDAPadmin
* @subpackage Templates * @subpackage Templates
*/ */
class SelectionAttribute extends Attribute { class SelectionAttribute extends PLAAttribute {
protected $selection = array(); protected $selection = array();
protected $multiple; protected $multiple;
protected $default; protected $default;

View File

@ -12,7 +12,7 @@
* @package phpLDAPadmin * @package phpLDAPadmin
* @subpackage Templates * @subpackage Templates
*/ */
class ShadowAttribute extends Attribute { class ShadowAttribute extends PLAAttribute {
public $shadow_before_today_attrs = array('shadowLastChange','shadowMin'); public $shadow_before_today_attrs = array('shadowLastChange','shadowMin');
public $shadow_after_today_attrs = array('shadowMax','shadowExpire','shadowWarning','shadowInactive'); public $shadow_after_today_attrs = array('shadowMax','shadowExpire','shadowWarning','shadowInactive');
} }

View File

@ -22,6 +22,15 @@ abstract class Visitor {
protected $server_id; protected $server_id;
public function __call($method,$args) { public function __call($method,$args) {
# This mapping array allows to map effective class names to
# function name suffixes.
# It has been introduced when class Attribute has been renamed
# to PLAAttribute to avoid a name clash with the built-in
# class of PHP 8.
# Entering a class name mapping here allows to rename the
# class without having to rename the methods too.
static $classmap = array('PLAAttribute' => 'Attribute');
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
@ -33,19 +42,14 @@ abstract class Visitor {
$fnct = array_shift($args); $fnct = array_shift($args);
$object = $args[0]; $object = $args[0];
$class = get_class($object);
$call = "$method$fnct$class";
for ($class = get_class($object); $class; $class = get_parent_class($class)) {
$call = isset($classmap[$class])? "$method$fnct$classmap[$class]": "$method$fnct$class";
array_push($methods,$call); array_push($methods,$call);
if (method_exists($this,$call))
while ($class && ! method_exists($this,$call)) { break;
if (defined('DEBUGTMP') && DEBUGTMP) if (defined('DEBUGTMP') && DEBUGTMP)
printf('<font size=-2><i>Class (%s): Method doesnt exist (%s,%s)</i></font><br />',$class,get_class($this),$call); printf('<font size=-2><i>Class (%s): Method doesnt exist (%s,%s)</i></font><br />',$class,get_class($this),$call);
$class = get_parent_class($class);
$call = "$method$fnct$class";
array_push($methods,$call);
} }
if (defined('DEBUGTMP') && DEBUGTMP) if (defined('DEBUGTMP') && DEBUGTMP)