|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file was originally part of the league/commonmark package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Colin O'Dell <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js) |
|
11
|
|
|
* - (c) John MacFarlane |
|
12
|
|
|
* |
|
13
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
14
|
|
|
* file that was distributed with this source code. |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace UnicornFail\Emoji\Environment; |
|
18
|
|
|
|
|
19
|
|
|
use UnicornFail\Emoji\Traits\ExtensibleEnvironmentTrait; |
|
20
|
|
|
use UnicornFail\Emoji\Traits\ListeningEnvironmentTrait; |
|
21
|
|
|
use UnicornFail\Emoji\Traits\RenderableEnvironmentTrait; |
|
22
|
|
|
|
|
23
|
|
|
abstract class AbstractEnvironment implements EnvironmentInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use ExtensibleEnvironmentTrait; |
|
26
|
|
|
use ListeningEnvironmentTrait; |
|
27
|
|
|
use RenderableEnvironmentTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var bool |
|
31
|
|
|
* |
|
32
|
|
|
* @psalm-readonly-allow-private-mutation |
|
33
|
|
|
*/ |
|
34
|
|
|
private $initialized = false; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @throws \RuntimeException |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function assertUninitialized(string $message): void |
|
40
|
|
|
{ |
|
41
|
|
|
if ($this->initialized) { |
|
42
|
|
|
throw new \RuntimeException(\sprintf('%s The Environment has already been initialized.', $message)); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function initialize(): void |
|
47
|
|
|
{ |
|
48
|
|
|
if ($this->initialized) { |
|
49
|
|
|
return; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$this->initializeExtensions(); |
|
53
|
|
|
|
|
54
|
|
|
$this->initialized = true; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
protected function injectEnvironmentAndConfigurationIfNeeded(object $object): void |
|
58
|
|
|
{ |
|
59
|
|
|
if ($object instanceof EnvironmentAwareInterface) { |
|
60
|
|
|
$object->setEnvironment($this); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|