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