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