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