]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/mediawiki/at-ease/src/Functions.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / mediawiki / at-ease / src / Functions.php
1 <?php
2 /**
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  * http://www.gnu.org/copyleft/gpl.html
17  *
18  * @file
19  */
20
21 namespace MediaWiki;
22
23 /**
24  * Reference-counted warning suppression
25  *
26  * @param bool $end
27  */
28 function suppressWarnings( $end = false ) {
29         static $suppressCount = 0;
30         static $originalLevel = false;
31
32         if ( $end ) {
33                 if ( $suppressCount ) {
34                         --$suppressCount;
35                         if ( !$suppressCount ) {
36                                 error_reporting( $originalLevel );
37                         }
38                 }
39         } else {
40                 if ( !$suppressCount ) {
41                         $originalLevel = error_reporting( E_ALL & ~(
42                                         E_WARNING |
43                                         E_NOTICE |
44                                         E_USER_WARNING |
45                                         E_USER_NOTICE |
46                                         E_DEPRECATED |
47                                         E_USER_DEPRECATED |
48                                         E_STRICT
49                                 ) );
50                 }
51                 ++$suppressCount;
52         }
53 }
54
55 /**
56  * Restore error level to previous value
57  */
58 function restoreWarnings() {
59         suppressWarnings( true );
60 }
61
62
63 /**
64  * Call the callback given by the first parameter, suppressing any warnings.
65  *
66  * @param callable $callback
67  * @return mixed
68  */
69 function quietCall( $callback /*, parameters... */ ) {
70         $args = array_slice( func_get_args(), 1 );
71         suppressWarnings();
72         $rv = call_user_func_array( $callback, $args );
73         restoreWarnings();
74         return $rv;
75 }