| 1 | <?php |
| 2 | /** |
| 3 | * Delayed loading of deprecated global objects. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | * http://www.gnu.org/copyleft/gpl.html |
| 19 | * |
| 20 | * @file |
| 21 | */ |
| 22 | |
| 23 | namespace MediaWiki\StubObject; |
| 24 | |
| 25 | /** |
| 26 | * Class to allow throwing wfDeprecated warnings |
| 27 | * when people use globals that we do not want them to. |
| 28 | */ |
| 29 | class DeprecatedGlobal extends StubObject { |
| 30 | /** @var string|false */ |
| 31 | protected $version; |
| 32 | |
| 33 | /** |
| 34 | * @param string $name Global name |
| 35 | * @param callable|string $callback Factory function or class name to construct |
| 36 | * @param string|false $version Version global was deprecated in |
| 37 | */ |
| 38 | public function __construct( $name, $callback, $version = false ) { |
| 39 | parent::__construct( $name, $callback ); |
| 40 | $this->version = $version; |
| 41 | } |
| 42 | |
| 43 | // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore |
| 44 | public function _newObject() { |
| 45 | /* |
| 46 | * Put the caller offset for wfDeprecated as 6, as |
| 47 | * that gives the function that uses this object, since: |
| 48 | * |
| 49 | * 1 = this function ( _newObject ) |
| 50 | * 2 = MediaWiki\StubObject\StubObject::_unstub |
| 51 | * 3 = MediaWiki\StubObject\StubObject::_call |
| 52 | * 4 = MediaWiki\StubObject\StubObject::__call |
| 53 | * 5 = MediaWiki\StubObject\DeprecatedGlobal::<method of global called> |
| 54 | * 6 = Actual function using the global. |
| 55 | * (the same applies to _get/__get or _set/__set instead of _call/__call) |
| 56 | * |
| 57 | * Of course its theoretically possible to have other call |
| 58 | * sequences for this method, but that seems to be |
| 59 | * rather unlikely. |
| 60 | */ |
| 61 | wfDeprecated( '$' . $this->global, $this->version, false, 6 ); |
| 62 | return parent::_newObject(); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** @deprecated class alias since 1.40 */ |
| 67 | class_alias( DeprecatedGlobal::class, 'DeprecatedGlobal' ); |