Fix hook situation for Skin::doEditSectionLink
[mediawiki.git] / includes / debug / logger / Factory.php
blob2660b92adf8edf36d12d992d3db624c1605bfd83
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.
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.
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
18 * @file
22 /**
23 * PSR-3 logger instance factory.
25 * Creation of \Psr\Log\LoggerInterface instances is managed via the
26 * MWLoggerFactory::getInstance() static method which in turn delegates to the
27 * currently registered service provider.
29 * A service provider is any class implementing the MWLoggerSpi interface.
30 * There are two possible methods of registering a service provider. The
31 * MWLoggerFactory::registerProvider() static method can be called at any time
32 * to change the service provider. If MWLoggerFactory::getInstance() is called
33 * before any service provider has been registered, it will attempt to use the
34 * $wgMWLoggerDefaultSpi global to bootstrap MWLoggerSpi registration.
35 * $wgMWLoggerDefaultSpi is expected to be an array usable by
36 * ObjectFactory::getObjectFromSpec() to create a class.
38 * @see MWLoggerSpi
39 * @since 1.25
40 * @author Bryan Davis <bd808@wikimedia.org>
41 * @copyright © 2014 Bryan Davis and Wikimedia Foundation.
43 class MWLoggerFactory {
45 /**
46 * Service provider.
47 * @var MWLoggerSpi $spi
49 private static $spi;
52 /**
53 * Register a service provider to create new \Psr\Log\LoggerInterface
54 * instances.
56 * @param MWLoggerSpi $provider Provider to register
58 public static function registerProvider( MWLoggerSpi $provider ) {
59 self::$spi = $provider;
63 /**
64 * Get the registered service provider.
66 * If called before any service provider has been registered, it will
67 * attempt to use the $wgMWLoggerDefaultSpi global to bootstrap
68 * MWLoggerSpi registration. $wgMWLoggerDefaultSpi is expected to be an
69 * array usable by ObjectFactory::getObjectFromSpec() to create a class.
71 * @return MWLoggerSpi
72 * @see registerProvider()
73 * @see ObjectFactory::getObjectFromSpec()
75 public static function getProvider() {
76 if ( self::$spi === null ) {
77 global $wgMWLoggerDefaultSpi;
78 $provider = ObjectFactory::getObjectFromSpec(
79 $wgMWLoggerDefaultSpi
81 self::registerProvider( $provider );
83 return self::$spi;
87 /**
88 * Get a named logger instance from the currently configured logger factory.
90 * @param string $channel Logger channel (name)
91 * @return \Psr\Log\LoggerInterface
93 public static function getInstance( $channel ) {
94 if ( !interface_exists( '\Psr\Log\LoggerInterface' ) ) {
95 $message = <<<TXT
96 MediaWiki requires the <a href="https://github.com/php-fig/log">PSR-3 logging library</a> to be present. This library is not embedded directly in MediaWiki's git repository and must be installed separately by the end user.
98 Please see <a href="https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries">mediawiki.org</a> for help on installing the required components.
99 TXT;
100 echo $message;
101 trigger_error( $message, E_USER_ERROR );
102 die( 1 );
105 return self::getProvider()->getLogger( $channel );
110 * Construction of utility class is not allowed.
112 private function __construct() {
113 // no-op