|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* Copyright (C) |
|
6
|
|
|
* Nathan Boiron <[email protected]> |
|
7
|
|
|
* Romain Canon <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* This file is part of the TYPO3 NotiZ project. |
|
10
|
|
|
* It is free software; you can redistribute it and/or modify it |
|
11
|
|
|
* under the terms of the GNU General Public License, either |
|
12
|
|
|
* version 3 of the License, or any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* For the full copyright and license information, see: |
|
15
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace CuyZ\Notiz\Core\Notification\Processor; |
|
19
|
|
|
|
|
20
|
|
|
use CuyZ\Notiz\Core\Exception\ClassNotFoundException; |
|
21
|
|
|
use CuyZ\Notiz\Core\Exception\InvalidClassException; |
|
22
|
|
|
use CuyZ\Notiz\Core\Notification\Notification; |
|
23
|
|
|
use CuyZ\Notiz\Service\Traits\ExtendedSelfInstantiateTrait; |
|
24
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
|
25
|
|
|
use TYPO3\CMS\Extbase\Object\Container\Container; |
|
|
|
|
|
|
26
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
class NotificationProcessorFactory implements SingletonInterface |
|
29
|
|
|
{ |
|
30
|
|
|
use ExtendedSelfInstantiateTrait; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var NotificationProcessor[] |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $processors = []; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var ObjectManager |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $objectManager; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var Container |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $objectContainer; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param ObjectManager $objectManager |
|
49
|
|
|
* @param Container $objectContainer |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct(ObjectManager $objectManager, Container $objectContainer) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->objectManager = $objectManager; |
|
54
|
|
|
$this->objectContainer = $objectContainer; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param Notification $notification |
|
59
|
|
|
* @return NotificationProcessor |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getFromNotification(Notification $notification): NotificationProcessor |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->getFromNotificationClassName(get_class($notification)); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $className |
|
68
|
|
|
* @return NotificationProcessor |
|
69
|
|
|
* |
|
70
|
|
|
* @throws ClassNotFoundException |
|
71
|
|
|
* @throws InvalidClassException |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getFromNotificationClassName(string $className): NotificationProcessor |
|
74
|
|
|
{ |
|
75
|
|
|
$className = $this->objectContainer->getImplementationClassName($className); |
|
76
|
|
|
|
|
77
|
|
|
if (false === isset($this->processors[$className])) { |
|
78
|
|
|
if (!class_exists($className)) { |
|
79
|
|
|
throw ClassNotFoundException::notificationClassNotFound($className); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if (!in_array(Notification::class, class_implements($className))) { |
|
83
|
|
|
throw InvalidClassException::notificationMissingInterface($className); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$processorClassName = $this->getProcessorClassNameFromNotificationClassName($className); |
|
87
|
|
|
|
|
88
|
|
|
$this->processors[$className] = $this->objectManager->get($processorClassName, $className); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return $this->processors[$className]; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param string $notificationClassName |
|
96
|
|
|
* @return string |
|
97
|
|
|
* |
|
98
|
|
|
* @throws ClassNotFoundException |
|
99
|
|
|
* @throws InvalidClassException |
|
100
|
|
|
*/ |
|
101
|
|
|
protected function getProcessorClassNameFromNotificationClassName(string $notificationClassName): string |
|
102
|
|
|
{ |
|
103
|
|
|
/** @var Notification $notificationClassName */ |
|
104
|
|
|
$processorClassName = $notificationClassName::getProcessorClassName(); |
|
105
|
|
|
|
|
106
|
|
|
if (!class_exists($processorClassName)) { |
|
107
|
|
|
throw ClassNotFoundException::notificationProcessorClassNotFound($notificationClassName, $processorClassName); |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
if (!in_array(NotificationProcessor::class, class_parents($processorClassName))) { |
|
111
|
|
|
throw InvalidClassException::notificationProcessorWrongParent($notificationClassName, $processorClassName); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return $processorClassName; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths