Completed
Push — inject-entity-deserializer ( 77729f )
by Bene
04:12
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\Entity\EntityIdParser;
8
use Wikibase\InternalSerialization\Deserializers\EntityDeserializer;
9
use Wikibase\InternalSerialization\Deserializers\StatementDeserializer;
10
11
/**
12
 * Public interface of the library for constructing deserializers.
13
 * Direct access to deserializers is prohibited, users are only allowed to
14
 * know about this interface. Also note that the return type of the methods
15
 * is "Deserializer". You are also not allowed to know which concrete
16
 * implementation is returned.
17
 *
18
 * The returned deserializers can handle both serializations in the
19
 * legacy internal format and in the new one.
20
 *
21
 * @since 1.0
22
 * @licence GNU GPL v2+
23
 * @author Jeroen De Dauw < [email protected] >
24
 */
25
class DeserializerFactory {
26
27
	/**
28
	 * @var LegacyDeserializerFactory
29
	 */
30
	private $legacyFactory;
31
32
	public function __construct( Deserializer $dataValueDeserializer, EntityIdParser $idParser ) {
33
		$this->legacyFactory = new LegacyDeserializerFactory( $dataValueDeserializer, $idParser );
34
	}
35
36
	/**
37
	 * @param DispatchableDeserializer $currentEntityDeserializer
38
	 *
39
	 * @return Deserializer
40
	 */
41
	public function newEntityDeserializer( DispatchableDeserializer $currentEntityDeserializer ) {
42
		return new EntityDeserializer(
43
			$this->legacyFactory->newEntityDeserializer(),
44
			$currentEntityDeserializer
45
		);
46
	}
47
48
	/**
49
	 * @since 1.4
50
	 *
51
	 * @param DispatchableDeserializer $currentStatementDeserializer
52
	 *
53
	 * @return Deserializer
54
	 */
55
	public function newStatementDeserializer( DispatchableDeserializer $currentStatementDeserializer ) {
56
		return new StatementDeserializer(
57
			$this->legacyFactory->newStatementDeserializer(),
58
			$currentStatementDeserializer
59
		);
60
	}
61
62
}
63