60trait DeprecationHelper {
71 protected $deprecatedPublicProperties = [];
78 private $dynamicPropertiesAccessDeprecated =
false;
100 $this->deprecatedPublicProperties[$property] = [
133 $this->deprecatedPublicProperties[$property] = [
153 string $class =
null,
154 string $component =
null
156 $this->dynamicPropertiesAccessDeprecated = [ $version, $class ?: __CLASS__, $component ];
163 if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
164 [ $version, $class, $component, $getter ] = $this->deprecatedPublicProperties[$name];
165 $qualifiedName = $class .
'::$' . $name;
166 wfDeprecated( $qualifiedName, $version, $component, 2 );
168 return $this->deprecationHelperCallGetter( $getter );
173 $ownerClass = $this->deprecationHelperGetPropertyOwner( $name );
178 if ( $this->dynamicPropertiesAccessDeprecated ) {
179 [ $version, $class, $component ] = $this->dynamicPropertiesAccessDeprecated;
180 $qualifiedName = $class .
'::$' . $name;
181 wfDeprecated( $qualifiedName, $version, $component, 2 );
188 if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
189 [ $version, $class, $component, $getter ] = $this->deprecatedPublicProperties[$name];
190 $qualifiedName = $class .
'::$' . $name;
191 wfDeprecated( $qualifiedName, $version, $component, 2 );
193 return $this->deprecationHelperCallGetter( $getter );
198 $ownerClass = $this->deprecationHelperGetPropertyOwner( $name );
199 $qualifiedName = ( $ownerClass ?: get_class( $this ) ) .
'::$' . $name;
202 trigger_error(
"Cannot access non-public property $qualifiedName", E_USER_ERROR );
203 } elseif ( property_exists( $this, $name ) ) {
211 trigger_error(
"Undefined property: $qualifiedName", E_USER_NOTICE );
216 public function __set( $name, $value ) {
217 if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
218 [ $version, $class, $component, , $setter ] = $this->deprecatedPublicProperties[$name];
219 $qualifiedName = $class .
'::$' . $name;
220 wfDeprecated( $qualifiedName, $version, $component, 2 );
222 $this->deprecationHelperCallSetter( $setter, $value );
223 } elseif ( property_exists( $this, $name ) ) {
224 $this->$name = $value;
226 trigger_error(
"Cannot access non-public property $qualifiedName", E_USER_ERROR );
231 $ownerClass = $this->deprecationHelperGetPropertyOwner( $name );
232 $qualifiedName = ( $ownerClass ?: get_class( $this ) ) .
'::$' . $name;
235 trigger_error(
"Cannot access non-public property $qualifiedName", E_USER_ERROR );
237 if ( $this->dynamicPropertiesAccessDeprecated ) {
238 [ $version, $class, $component ] = $this->dynamicPropertiesAccessDeprecated;
239 $qualifiedName = $class .
'::$' . $name;
240 wfDeprecated( $qualifiedName, $version, $component, 2 );
243 $this->$name = $value;
254 private function deprecationHelperGetPropertyOwner( $property ) {
257 $obfuscatedProps = array_keys( (array)$this );
258 $obfuscatedPropTail =
"\0$property";
259 foreach ( $obfuscatedProps as $obfuscatedProp ) {
261 if ( strpos( $obfuscatedProp, $obfuscatedPropTail, 1 ) !==
false ) {
262 $classname = substr( $obfuscatedProp, 1, -strlen( $obfuscatedPropTail ) );
263 if ( $classname ===
'*' ) {
266 return (
new ReflectionProperty( $this, $property ) )->getDeclaringClass()->getName();
274 private function deprecationHelperCallGetter( $getter ) {
275 if ( is_string( $getter ) ) {
276 $getter = [ $this, $getter ];
281 private function deprecationHelperCallSetter( $setter, $value ) {
282 if ( is_string( $setter ) ) {
283 $setter = [ $this, $setter ];
deprecatePublicPropertyFallback(string $property, string $version, $getter, $setter=null, $class=null, $component=null)
Mark a removed public property as deprecated and provide fallback getter and setter callables.
deprecatePublicProperty( $property, $version, $class=null, $component=null)
Mark a property as deprecated.
deprecateDynamicPropertiesAccess(string $version, string $class=null, string $component=null)
Emit deprecation warnings when dynamic and unknown properties are accessed.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.