Skip to content

Commit 67f706d

Browse files
authored
Allow a single object type handler to serve multiple types (#6453)
* Allow a single object type handler to serve multiple types * Implicitly forward the calls to the legacy API This simplifies the code by avoiding the nullable parameter that would otherwise stuck around forever.
1 parent b3afaa3 commit 67f706d

3 files changed

Lines changed: 36 additions & 14 deletions

File tree

wcfsetup/install/files/lib/acp/form/LabelGroupAddForm.class.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,13 @@ public function readData()
129129
// get label object type handlers
130130
$objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.label.objectType');
131131
foreach ($objectTypes as $objectType) {
132-
$this->labelObjectTypes[$objectType->objectTypeID] = $objectType->getProcessor();
133-
$this->labelObjectTypes[$objectType->objectTypeID]->setObjectTypeID($objectType->objectTypeID);
134-
}
132+
$handler = $objectType->getProcessor();
133+
\assert($handler instanceof ILabelObjectTypeHandler);
134+
135+
$container = $handler->getContainerForObjectType($objectType);
135136

136-
foreach ($this->labelObjectTypes as $objectTypeID => $labelObjectType) {
137-
$this->labelObjectTypeContainers[$objectTypeID] = $labelObjectType->getContainer();
137+
$this->labelObjectTypes[$objectType->objectTypeID] = $handler;
138+
$this->labelObjectTypeContainers[$objectType->objectTypeID] = $container;
138139
}
139140

140141
parent::readData();

wcfsetup/install/files/lib/system/label/object/type/AbstractLabelObjectTypeHandler.class.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace wcf\system\label\object\type;
44

5+
use wcf\data\object\type\ObjectType;
56
use wcf\system\SingletonFactory;
67

78
/**
@@ -16,36 +17,41 @@ abstract class AbstractLabelObjectTypeHandler extends SingletonFactory implement
1617
/**
1718
* label object type container
1819
* @var LabelObjectTypeContainer
20+
* @deprecated 6.2 Use `getContainerForObjectType()` instead.
1921
*/
2022
public $container;
2123

2224
/**
2325
* object type id
2426
* @var int
27+
* @deprecated 6.2 Use `getContainerForObjectType()` instead.
2528
*/
2629
public $objectTypeID = 0;
2730

28-
/**
29-
* @inheritDoc
30-
*/
31+
#[\Override]
3132
public function setObjectTypeID($objectTypeID)
3233
{
3334
$this->objectTypeID = $objectTypeID;
3435
}
3536

36-
/**
37-
* @inheritDoc
38-
*/
37+
#[\Override]
3938
public function getObjectTypeID()
4039
{
4140
return $this->objectTypeID;
4241
}
4342

44-
/**
45-
* @inheritDoc
46-
*/
43+
#[\Override]
4744
public function getContainer()
4845
{
4946
return $this->container;
5047
}
48+
49+
#[\Override]
50+
public function getContainerForObjectType(ObjectType $objectType): LabelObjectTypeContainer
51+
{
52+
// This exists for backwards-compatibility only; Implementations are
53+
// expected to implement this method themselves.
54+
$this->setObjectTypeID($objectType->objectTypeID);
55+
return $this->getContainer();
56+
}
5157
}

wcfsetup/install/files/lib/system/label/object/type/ILabelObjectTypeHandler.class.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace wcf\system\label\object\type;
44

5+
use wcf\data\object\type\ObjectType;
6+
57
/**
68
* Every label object type handler has to implement this interface.
79
*
@@ -11,25 +13,38 @@
1113
*/
1214
interface ILabelObjectTypeHandler
1315
{
16+
/**
17+
* Provides a container object that groups all objects that can be assigned
18+
* a label group.
19+
*
20+
* Implementations must not rely on any state provided by `getObjectTypeID()`.
21+
*
22+
* @since 6.2
23+
*/
24+
public function getContainerForObjectType(ObjectType $objectType): LabelObjectTypeContainer;
25+
1426
/**
1527
* Sets object type id.
1628
*
1729
* @param int $objectTypeID
1830
* @return void
31+
* @deprecated 6.2 Use `getContainerForObjectType()` instead.
1932
*/
2033
public function setObjectTypeID($objectTypeID);
2134

2235
/**
2336
* Returns object type id.
2437
*
2538
* @return int
39+
* @deprecated 6.2 Use `getContainerForObjectType()` instead.
2640
*/
2741
public function getObjectTypeID();
2842

2943
/**
3044
* Returns a label object type container.
3145
*
3246
* @return LabelObjectTypeContainer
47+
* @deprecated 6.2 Use `getContainerForObjectType()` instead.
3348
*/
3449
public function getContainer();
3550

0 commit comments

Comments
 (0)