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 * @since 1.41
37 */
38class EmailUserFactory {
39    private ServiceOptions $options;
40
41    private HookContainer $hookContainer;
42
43    private UserOptionsLookup $userOptionsLookup;
44
45    private CentralIdLookup $centralIdLookup;
46
47    private UserFactory $userFactory;
48
49    private IEmailer $emailer;
50
51    private IMessageFormatterFactory $messageFormatterFactory;
52
53    private ITextFormatter $contLangMsgFormatter;
54
55    /**
56     * @param ServiceOptions $options
57     * @param HookContainer $hookContainer
58     * @param UserOptionsLookup $userOptionsLookup
59     * @param CentralIdLookup $centralIdLookup
60     * @param UserFactory $userFactory
61     * @param IEmailer $emailer
62     * @param IMessageFormatterFactory $messageFormatterFactory
63     * @param ITextFormatter $contLangMsgFormatter
64     */
65    public function __construct(
66        ServiceOptions $options,
67        HookContainer $hookContainer,
68        UserOptionsLookup $userOptionsLookup,
69        CentralIdLookup $centralIdLookup,
70        UserFactory $userFactory,
71        IEmailer $emailer,
72        IMessageFormatterFactory $messageFormatterFactory,
73        ITextFormatter $contLangMsgFormatter
74    ) {
75        $options->assertRequiredOptions( EmailUser::CONSTRUCTOR_OPTIONS );
76        $this->options = $options;
77        $this->hookContainer = $hookContainer;
78        $this->userOptionsLookup = $userOptionsLookup;
79        $this->centralIdLookup = $centralIdLookup;
80        $this->userFactory = $userFactory;
81        $this->emailer = $emailer;
82        $this->messageFormatterFactory = $messageFormatterFactory;
83        $this->contLangMsgFormatter = $contLangMsgFormatter;
84    }
85
86    /**
87     * @param Authority $sender
88     * @return EmailUser
89     */
90    public function newEmailUser( Authority $sender ): EmailUser {
91        return new EmailUser(
92            $this->options,
93            $this->hookContainer,
94            $this->userOptionsLookup,
95            $this->centralIdLookup,
96            $this->userFactory,
97            $this->emailer,
98            $this->messageFormatterFactory,
99            $this->contLangMsgFormatter,
100            $sender
101        );
102    }
103
104    /**
105     * @internal Temporary BC method for SpecialEmailUser
106     * @param Authority $sender
107     * @param Config|null $config
108     * @return EmailUser
109     */
110    public function newEmailUserBC( Authority $sender, Config $config = null ): EmailUser {
111        $options = $config ? new ServiceOptions( EmailUser::CONSTRUCTOR_OPTIONS, $config ) : $this->options;
112        return new EmailUser(
113            $options,
114            $this->hookContainer,
115            $this->userOptionsLookup,
116            $this->centralIdLookup,
117            $this->userFactory,
118            $this->emailer,
119            $this->messageFormatterFactory,
120            $this->contLangMsgFormatter,
121            $sender
122        );
123    }
124}