Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
EmailUserFactory
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 newEmailUser
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
 newEmailUserBC
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
6
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
21namespace MediaWiki\Mail;
22
23use MediaWiki\Config\Config;
24use MediaWiki\Config\ServiceOptions;
25use MediaWiki\HookContainer\HookContainer;
26use MediaWiki\Permissions\Authority;
27use MediaWiki\User\CentralId\CentralIdLookup;
28use MediaWiki\User\Options\UserOptionsLookup;
29use MediaWiki\User\UserFactory;
30use Wikimedia\Message\IMessageFormatterFactory;
31use Wikimedia\Message\ITextFormatter;
32
33/**
34 * Factory for EmailUser objects.
35 *
36 * Obtain via ServiceWiring.
37 *
38 * @since 1.41
39 * @ingroup Mail
40 */
41class EmailUserFactory {
42    private ServiceOptions $options;
43    private HookContainer $hookContainer;
44    private UserOptionsLookup $userOptionsLookup;
45    private CentralIdLookup $centralIdLookup;
46    private UserFactory $userFactory;
47    private IEmailer $emailer;
48    private IMessageFormatterFactory $messageFormatterFactory;
49    private ITextFormatter $contLangMsgFormatter;
50
51    /**
52     * @internal For use by ServiceWiring only.
53     *
54     * @param ServiceOptions $options
55     * @param HookContainer $hookContainer
56     * @param UserOptionsLookup $userOptionsLookup
57     * @param CentralIdLookup $centralIdLookup
58     * @param UserFactory $userFactory
59     * @param IEmailer $emailer
60     * @param IMessageFormatterFactory $messageFormatterFactory
61     * @param ITextFormatter $contLangMsgFormatter
62     */
63    public function __construct(
64        ServiceOptions $options,
65        HookContainer $hookContainer,
66        UserOptionsLookup $userOptionsLookup,
67        CentralIdLookup $centralIdLookup,
68        UserFactory $userFactory,
69        IEmailer $emailer,
70        IMessageFormatterFactory $messageFormatterFactory,
71        ITextFormatter $contLangMsgFormatter
72    ) {
73        $options->assertRequiredOptions( EmailUser::CONSTRUCTOR_OPTIONS );
74        $this->options = $options;
75        $this->hookContainer = $hookContainer;
76        $this->userOptionsLookup = $userOptionsLookup;
77        $this->centralIdLookup = $centralIdLookup;
78        $this->userFactory = $userFactory;
79        $this->emailer = $emailer;
80        $this->messageFormatterFactory = $messageFormatterFactory;
81        $this->contLangMsgFormatter = $contLangMsgFormatter;
82    }
83
84    /**
85     * @param Authority $sender
86     * @return EmailUser
87     */
88    public function newEmailUser( Authority $sender ): EmailUser {
89        return new EmailUser(
90            $this->options,
91            $this->hookContainer,
92            $this->userOptionsLookup,
93            $this->centralIdLookup,
94            $this->userFactory,
95            $this->emailer,
96            $this->messageFormatterFactory,
97            $this->contLangMsgFormatter,
98            $sender
99        );
100    }
101
102    /**
103     * @internal Temporary BC method for SpecialEmailUser
104     * @param Authority $sender
105     * @param Config|null $config
106     * @return EmailUser
107     */
108    public function newEmailUserBC( Authority $sender, Config $config = null ): EmailUser {
109        $options = $config ? new ServiceOptions( EmailUser::CONSTRUCTOR_OPTIONS, $config ) : $this->options;
110        return new EmailUser(
111            $options,
112            $this->hookContainer,
113            $this->userOptionsLookup,
114            $this->centralIdLookup,
115            $this->userFactory,
116            $this->emailer,
117            $this->messageFormatterFactory,
118            $this->contLangMsgFormatter,
119            $sender
120        );
121    }
122}