|
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; |
|
8
|
|
|
|
|
9
|
|
|
use ZBateson\MailMimeParser\Message\PartHeaderContainer; |
|
10
|
|
|
use ZBateson\MailMimeParser\Message\PartChildrenContainer; |
|
11
|
|
|
use Pimple\Container; |
|
|
|
|
|
|
12
|
|
|
use Pimple\ServiceProviderInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Default Pimple\ServiceProviderInterface defining classes that require |
|
16
|
|
|
* factories or special configuration on initialization. |
|
17
|
|
|
* |
|
18
|
|
|
* @author Zaahid Bateson |
|
19
|
|
|
*/ |
|
20
|
|
|
class DefaultProvider implements ServiceProviderInterface |
|
21
|
|
|
{ |
|
22
|
|
|
public function register(Container $pimple) |
|
23
|
|
|
{ |
|
24
|
|
|
$pimple['\ZBateson\MailMimeParser\Message\PartStreamContainer'] = $pimple->factory(function() use ($pimple) { |
|
|
|
|
|
|
25
|
|
|
$factory = $pimple['\ZBateson\MailMimeParser\Message\Factory\PartStreamContainerFactory']; |
|
26
|
|
|
return $factory->newInstance(); |
|
27
|
|
|
}); |
|
28
|
|
|
$pimple['\ZBateson\MailMimeParser\Message\PartHeaderContainer'] = $pimple->factory(function() use ($pimple) { |
|
|
|
|
|
|
29
|
|
|
return new PartHeaderContainer($pimple['\ZBateson\MailMimeParser\Header\HeaderFactory']); |
|
30
|
|
|
}); |
|
31
|
|
|
$pimple['\ZBateson\MailMimeParser\Message\PartChildrenContainer'] = $pimple->factory(function() use ($pimple) { |
|
|
|
|
|
|
32
|
|
|
return new PartChildrenContainer(); |
|
33
|
|
|
}); |
|
34
|
|
|
|
|
35
|
|
|
// This might need to move somewhere else. 'extend' doesn't work because BaseParser |
|
36
|
|
|
// is a dependency of the other parsers, and using extend causes it to be called |
|
37
|
|
|
// recursively when trying to create an instance of a parser and BaseParser |
|
38
|
|
|
// is not yet registered on Pimple\Container |
|
39
|
|
|
$baseParser = $pimple['\ZBateson\MailMimeParser\Parser\BaseParser']; |
|
40
|
|
|
$baseParser->addContentParser($pimple['\ZBateson\MailMimeParser\Parser\MimeContentParser']); |
|
41
|
|
|
$baseParser->addContentParser($pimple['\ZBateson\MailMimeParser\Parser\NonMimeParser']); |
|
42
|
|
|
$baseParser->addChildParser($pimple['\ZBateson\MailMimeParser\Parser\MultipartChildrenParser']); |
|
43
|
|
|
$baseParser->addChildParser($pimple['\ZBateson\MailMimeParser\Parser\NonMimeParser']); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: