MediaWiki  master
DeprecationHelper.php
Go to the documentation of this file.
1 <?php
46 
55  protected $deprecatedPublicProperties = [];
56 
68  protected function deprecatePublicProperty(
69  $property, $version, $class = null, $component = null
70  ) {
71  $this->deprecatedPublicProperties[$property] = [ $version, $class ?: __CLASS__, $component ];
72  }
73 
74  public function __get( $name ) {
75  if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
76  list( $version, $class, $component ) = $this->deprecatedPublicProperties[$name];
77  $qualifiedName = $class . '::$' . $name;
78  wfDeprecated( $qualifiedName, $version, $component, 3 );
79  return $this->$name;
80  }
81 
82  $ownerClass = $this->deprecationHelperGetPropertyOwner( $name );
83  $qualifiedName = ( $ownerClass ?: get_class( $this ) ) . '::$' . $name;
84  if ( $ownerClass ) {
85  // Someone tried to access a normal non-public property. Try to behave like PHP would.
86  trigger_error( "Cannot access non-public property $qualifiedName", E_USER_ERROR );
87  } else {
88  // Non-existing property. Try to behave like PHP would.
89  trigger_error( "Undefined property: $qualifiedName", E_USER_NOTICE );
90  }
91  return null;
92  }
93 
94  public function __set( $name, $value ) {
95  if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
96  list( $version, $class, $component ) = $this->deprecatedPublicProperties[$name];
97  $qualifiedName = $class . '::$' . $name;
98  wfDeprecated( $qualifiedName, $version, $component, 3 );
99  $this->$name = $value;
100  return;
101  }
102 
103  $ownerClass = $this->deprecationHelperGetPropertyOwner( $name );
104  $qualifiedName = ( $ownerClass ?: get_class( $this ) ) . '::$' . $name;
105  if ( $ownerClass ) {
106  // Someone tried to access a normal non-public property. Try to behave like PHP would.
107  trigger_error( "Cannot access non-public property $qualifiedName", E_USER_ERROR );
108  } else {
109  // Non-existing property. Try to behave like PHP would.
110  $this->$name = $value;
111  }
112  }
113 
122  // Returning false is a non-error path and should avoid slow checks like reflection.
123  // Use array cast hack instead.
124  $obfuscatedProps = array_keys( (array)$this );
125  $obfuscatedPropTail = "\0$property";
126  foreach ( $obfuscatedProps as $obfuscatedProp ) {
127  // private props are in the form \0<classname>\0<propname>
128  if ( strpos( $obfuscatedProp, $obfuscatedPropTail, 1 ) !== false ) {
129  $classname = substr( $obfuscatedProp, 1, -strlen( $obfuscatedPropTail ) );
130  if ( $classname === '*' ) {
131  // protected property; we didn't get the name, but we are on an error path
132  // now so it's fine to use reflection
133  return ( new ReflectionProperty( $this, $property ) )->getDeclaringClass()->getName();
134  }
135  return $classname;
136  }
137  }
138  return false;
139  }
140 
141 }
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
$property
__get( $name)
$value
deprecationHelperGetPropertyOwner( $property)
Like property_exists but also check for non-visible private properties and returns which class in the...
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
deprecatePublicProperty( $property, $version, $class=null, $component=null)
Mark a property as deprecated.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
__set( $name, $value)
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271