MediaWiki REL1_39
|
Trait for issuing warnings on deprecated access. More...
Go to the source code of this file.
Functions | |
__get ( $name) | |
__isset ( $name) | |
__set ( $name, $value) | |
deprecateDynamicPropertiesAccess (string $version, string $class=null, string $component=null) | |
Emit deprecation warnings when dynamic and unknown properties are accessed. | |
deprecatePublicProperty ( $property, $version, $class=null, $component=null) | |
Mark a property as deprecated. | |
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. | |
Variables | |
trait | DeprecationHelper |
Use this trait in classes which have properties for which public access is deprecated or implementation has been moved to another class. | |
Trait for issuing warnings on deprecated access.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. http://www.gnu.org/copyleft/gpl.html
Definition in file DeprecationHelper.php.
__get | ( | $name | ) |
Definition at line 187 of file DeprecationHelper.php.
References wfDeprecated().
__isset | ( | $name | ) |
Definition at line 159 of file DeprecationHelper.php.
References wfDeprecated().
__set | ( | $name, | |
$value ) |
Definition at line 216 of file DeprecationHelper.php.
References wfDeprecated().
|
protected |
Emit deprecation warnings when dynamic and unknown properties are accessed.
string | $version | MediaWiki version where the property became deprecated. |
string | null | $class | The class which has the deprecated property. |
string | null | $component |
Definition at line 151 of file DeprecationHelper.php.
|
protected |
Mark a property as deprecated.
Only use this for properties that used to be public and only call it in the constructor.
string | $property | The name of the property. |
string | $version | MediaWiki version where the property became deprecated. |
string | null | $class | The class which has the deprecated property. This can usually be guessed, but PHP can get confused when both the parent class and the subclass use the trait, so it should be specified in classes meant for subclassing. |
string | null | $component |
Definition at line 94 of file DeprecationHelper.php.
Referenced by DifferenceEngine\__construct(), LanguageConverter\__construct(), MediaWiki\Block\AbstractBlock\__construct(), MediaWiki\Block\DatabaseBlock\__construct(), EditPage\__construct(), WikiRevision\__construct(), MediaWiki\Deferred\LinksUpdate\LinksUpdate\__construct(), and Parser\__construct().
|
protected |
Mark a removed public property as deprecated and provide fallback getter and setter callables.
Only use this for properties that used to be public and only call it in the constructor.
string | $property | The name of the property. |
string | $version | MediaWiki version where the property became deprecated. |
callable | string | $getter | A user provided getter that implements a get logic for the property. If a string is given, it is called as a method on $this. |
callable | string | null | $setter | A user provided setter that implements a set logic for the property. If a string is given, it is called as a method on $this. |
string | null | $class | The class which has the deprecated property. |
string | null | $component |
Definition at line 125 of file DeprecationHelper.php.
Referenced by LanguageConverter\__construct(), RecentChange\__construct(), RevisionListBase\__construct(), CategoryViewer\__construct(), MediaWiki\Deferred\LinksUpdate\LinksUpdate\__construct(), and Parser\__construct().
trait DeprecationHelper |
Use this trait in classes which have properties for which public access is deprecated or implementation has been moved to another class.
Set the list of properties in $deprecatedPublicProperties and make the properties non-public. The trait will preserve public access but issue deprecation warnings when it is needed.
Example usage: class Foo { use DeprecationHelper; protected $bar; public function construct() { $this->deprecatePublicProperty( 'bar', '1.21', __CLASS ); $this->deprecatePublicPropertyFallback( 'movedValue', '1.35', function () { return MediaWikiServices()::getInstance() ->getNewImplementationService()->getValue(); }, function ( $value ) { MediaWikiServices()::getInstance() ->getNewImplementationService()->setValue( $value ); } ); } }
$foo = new Foo; $foo->bar; // works but logs a warning $foo->movedValue = 10; // works but logs a warning $movedValue = $foo->movedValue; // also works
Cannot be used with classes that have their own __get/__set methods.
Definition at line 60 of file DeprecationHelper.php.