1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the ZBateson\MailMimeParser project. |
4
|
|
|
* |
5
|
|
|
* @license http://opensource.org/licenses/bsd-license.php BSD |
6
|
|
|
*/ |
7
|
|
|
namespace ZBateson\MailMimeParser\Message\Part; |
8
|
|
|
|
9
|
|
|
use ZBateson\MailMimeParser\Header\HeaderFactory; |
10
|
|
|
use ZBateson\MailMimeParser\Message\PartFilterFactory; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Abstract factory for subclasses of MessagePart. |
14
|
|
|
* |
15
|
|
|
* @author Zaahid Bateson |
16
|
|
|
*/ |
17
|
|
|
abstract class MessagePartFactory |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var PartStreamFilterManagerFactory responsible for creating |
21
|
|
|
* PartStreamFilterManager instances |
22
|
|
|
*/ |
23
|
|
|
protected $partStreamFilterManagerFactory; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Initializes class dependencies. |
27
|
|
|
* |
28
|
|
|
* @param PartStreamFilterManagerFactory $psf |
29
|
|
|
*/ |
30
|
|
|
public function __construct(PartStreamFilterManagerFactory $psf) |
31
|
|
|
{ |
32
|
|
|
$this->partStreamFilterManagerFactory = $psf; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Returns the singleton instance for the class. |
37
|
|
|
* |
38
|
|
|
* @param PartStreamFilterManagerFactory $psf |
39
|
|
|
* @param HeaderFactory $hf |
40
|
|
|
* @param PartFilterFactory $pf |
41
|
|
|
* @return MessagePartFactory |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
public static function getInstance( |
|
|
|
|
44
|
|
|
PartStreamFilterManagerFactory $psf, |
45
|
|
|
HeaderFactory $hf = null, |
46
|
|
|
PartFilterFactory $pf = null |
47
|
|
|
) { |
48
|
|
|
static $instances = []; |
49
|
|
|
$class = get_called_class(); |
50
|
|
|
if (!isset($instances[$class])) { |
51
|
|
|
$instances[$class] = new static($psf); |
52
|
|
|
} |
53
|
|
|
return $instances[$class]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Constructs a new MessagePart object and returns it |
58
|
|
|
* |
59
|
|
|
* @param string $messageObjectId |
60
|
|
|
* @param PartBuilder $partBuilder |
61
|
|
|
* @return \ZBateson\MailMimeParser\Message\Part\MessagePart |
62
|
|
|
*/ |
63
|
|
|
public abstract function newInstance($messageObjectId, PartBuilder $partBuilder); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.