Commit | Line | Data |
---|---|---|
b522d4f1 | 1 | <?php |
a9229942 | 2 | |
b522d4f1 | 3 | namespace wcf\data; |
a9229942 | 4 | |
7b9ff46b | 5 | use wcf\system\exception\ImplementationException; |
b522d4f1 | 6 | use wcf\system\exception\SystemException; |
157054c9 | 7 | use wcf\system\SingletonFactory; |
b522d4f1 MW |
8 | |
9 | /** | |
406c554a | 10 | * Abstract class for all processible data holder classes. |
a9229942 TD |
11 | * |
12 | * @author Marcel Werk | |
13 | * @copyright 2001-2019 WoltLab GmbH | |
14 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
15 | * @package WoltLabSuite\Core\Data | |
16 | * | |
17 | * @property-read string|null $className name of the PHP class whose object(s) act as processor | |
b522d4f1 | 18 | */ |
a9229942 TD |
19 | class ProcessibleDatabaseObject extends DatabaseObject |
20 | { | |
21 | /** | |
22 | * name of the interface the processor of this database object should implement | |
23 | * @var string | |
24 | */ | |
25 | protected static $processorInterface = ''; | |
26 | ||
27 | /** | |
28 | * processor this database object | |
29 | * @var object | |
30 | */ | |
31 | protected $processor; | |
32 | ||
33 | /** | |
34 | * Returns the processor this database object. | |
35 | * | |
36 | * @return object | |
37 | * @throws SystemException | |
38 | */ | |
39 | public function getProcessor() | |
40 | { | |
41 | if ($this->processor === null) { | |
42 | if ($this->className) { | |
43 | if (!\class_exists($this->className)) { | |
44 | throw new SystemException("Unable to find class '" . $this->className . "'"); | |
45 | } | |
46 | if (!\is_subclass_of($this->className, static::$processorInterface)) { | |
47 | throw new ImplementationException($this->className, static::$processorInterface); | |
48 | } | |
49 | ||
50 | if (\is_subclass_of($this->className, SingletonFactory::class)) { | |
51 | $this->processor = \call_user_func([$this->className, 'getInstance']); | |
52 | } else { | |
53 | if (!\is_subclass_of($this->className, IDatabaseObjectProcessor::class)) { | |
54 | throw new ImplementationException($this->className, IDatabaseObjectProcessor::class); | |
55 | } | |
56 | ||
57 | $this->processor = new $this->className($this); | |
58 | } | |
59 | } | |
60 | } | |
61 | ||
62 | return $this->processor; | |
63 | } | |
b522d4f1 | 64 | } |