Completed
Push — inject-entity-deserializer ( 77729f...6dc1ef )
by Bene
03:15
created

DeserializerFactory::newClaimDeserializer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 3
Metric Value
c 5
b 0
f 3
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\InternalSerialization;
4
5
use Deserializers\Deserializer;
6
use Deserializers\DispatchableDeserializer;
7
use Wikibase\DataModel\DeserializerFactory as CurrentDeserializerFactory;
8
use Wikibase\DataModel\Entity\EntityIdParser;
9
use Wikibase\InternalSerialization\Deserializers\EntityDeserializer;
10
use Wikibase\InternalSerialization\Deserializers\StatementDeserializer;
11
12
/**
13
 * Public interface of the library for constructing deserializers.
14
 * Direct access to deserializers is prohibited, users are only allowed to
15
 * know about this interface. Also note that the return type of the methods
16
 * is "Deserializer". You are also not allowed to know which concrete
17
 * implementation is returned.
18
 *
19
 * The returned deserializers can handle both serializations in the
20
 * legacy internal format and in the new one.
21
 *
22
 * @since 1.0
23
 * @licence GNU GPL v2+
24
 * @author Jeroen De Dauw < [email protected] >
25
 */
26
class DeserializerFactory {
27
28
	/**
29
	 * @var LegacyDeserializerFactory
30
	 */
31
	private $legacyFactory;
32
33
	/**
34
	 * @var CurrentDeserializerFactory
35
	 */
36
	private $currentFactory;
37
38
	public function __construct( Deserializer $dataValueDeserializer, EntityIdParser $idParser ) {
39
		$this->legacyFactory = new LegacyDeserializerFactory( $dataValueDeserializer, $idParser );
40
		$this->currentFactory = new CurrentDeserializerFactory( $dataValueDeserializer, $idParser );
41
	}
42
43
	/**
44
	 * @param DispatchableDeserializer $currentEntityDeserializer
45
	 *
46
	 * @return Deserializer
47
	 */
48
	public function newEntityDeserializer( DispatchableDeserializer $currentEntityDeserializer ) {
49
		return new EntityDeserializer(
50
			$this->legacyFactory->newEntityDeserializer(),
51
			$currentEntityDeserializer
52
		);
53
	}
54
55
	/**
56
	 * @since 1.1
57
	 * @deprecated since 1.4 - use newStatementDeserializer instead
58
	 *
59
	 * @return Deserializer
60
	 */
61
	public function newClaimDeserializer() {
62
		return $this->newStatementDeserializer();
63
	}
64
65
	/**
66
	 * @since 1.4
67
	 *
68
	 * @return Deserializer
69
	 */
70
	public function newStatementDeserializer() {
71
		return new StatementDeserializer(
72
			$this->legacyFactory->newStatementDeserializer(),
73
			$this->currentFactory->newStatementDeserializer()
74
		);
75
	}
76
77
}
78