Merge pull request #3462 from SoftCreatR/patch-14
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / ProcessibleDatabaseObject.class.php
1 <?php
2 namespace wcf\data;
3 use wcf\system\exception\ImplementationException;
4 use wcf\system\exception\SystemException;
5 use wcf\system\SingletonFactory;
6
7 /**
8 * Abstract class for all processible data holder classes.
9 *
10 * @author Marcel Werk
11 * @copyright 2001-2018 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\Data
14 *
15 * @property-read string|null $className name of the PHP class whose object(s) act as processor
16 */
17 class ProcessibleDatabaseObject extends DatabaseObject {
18 /**
19 * name of the interface the processor of this database object should implement
20 * @var string
21 */
22 protected static $processorInterface = '';
23
24 /**
25 * processor this database object
26 * @var object
27 */
28 protected $processor = null;
29
30 /**
31 * Returns the processor this database object.
32 *
33 * @return object
34 * @throws SystemException
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 }
42 if (!is_subclass_of($this->className, static::$processorInterface)) {
43 throw new ImplementationException($this->className, static::$processorInterface);
44 }
45
46 if (is_subclass_of($this->className, SingletonFactory::class)) {
47 $this->processor = call_user_func([$this->className, 'getInstance']);
48 }
49 else {
50 if (!is_subclass_of($this->className, IDatabaseObjectProcessor::class)) {
51 throw new ImplementationException($this->className, IDatabaseObjectProcessor::class);
52 }
53
54 $this->processor = new $this->className($this);
55 }
56 }
57 }
58
59 return $this->processor;
60 }
61 }