Completed
Push — master ( 94847e...d52f9e )
by mw
02:57
created

PropertyRegistrationHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace SG;
4
5
use SMW\PropertyRegistry;
6
7
define( 'SG_PROP_GLT', 'Glossary-Term' );
8
define( 'SG_PROP_GLD', 'Glossary-Definition' );
9
define( 'SG_PROP_GLL', 'Glossary-Link' );
10
define( 'SG_PROP_GLS', 'Glossary-Style' );
11
12
/**
13
 * @ingroup SemanticGlossary
14
 *
15
 * @license GNU GPL v2+
16
 * @since 1.0
17
 *
18
 * @author mwjames
19
 */
20
class PropertyRegistrationHelper {
21
22
	const SG_TERM = '___glt';
23
	const SG_DEFINITION = '___gld';
24
	const SG_LINK  = '___gll';
25
	const SG_STYLE = '___gls';
26
27
	private $propertyRegistry;
28
29
	/**
30
	 * PropertyRegistry constructor.
31
	 *
32
	 * @param PropertyRegistry $propertyRegistry
33
	 */
34 4
	public function __construct( PropertyRegistry $propertyRegistry ) {
35 4
		$this->propertyRegistry = $propertyRegistry;
36 4
	}
37
38
	/**
39
	 * @since 1.0
40
	 *
41
	 * @return boolean
42
	 */
43 3
	public function registerProperties() {
44
45
		$propertyDefinitions = array(
46 3
			self::SG_TERM => array(
47 3
				'label' => SG_PROP_GLT,
48 3
				'type'  => '_txt',
49 3
				'alias' => wfMessage( 'semanticglossary-prop-glt' )->text()
50
			),
51 3
			self::SG_DEFINITION => array(
52 3
				'label' => SG_PROP_GLD,
53 3
				'type'  => '_txt',
54 3
				'alias' => wfMessage( 'semanticglossary-prop-gld' )->text()
55
			),
56 3
			self::SG_LINK => array(
57 3
				'label' => SG_PROP_GLL,
58 3
				'type'  => '_txt',
59 3
				'alias' => wfMessage( 'semanticglossary-prop-gll' )->text()
60
			),
61 3
			self::SG_STYLE => array(
62 3
				'label' => SG_PROP_GLS,
63 3
				'type'  => '_txt',
64 3
				'alias' => wfMessage( 'semanticglossary-prop-gls' )->text()
65
			)
66
		);
67
68 3
		return $this->registerPropertiesFromList( $propertyDefinitions );
69
	}
70
71
    /**
72
     * @param string[][] $propertyList
73
     * @return bool
74
     */
75 3
    protected function registerPropertiesFromList( array $propertyList ) {
76
77 3
		foreach ( $propertyList as $propertyId => $definition ) {
78
79 3
			$this->propertyRegistry->registerProperty(
80 3
				$propertyId,
81 3
				$definition['type'],
82 3
				$definition['label'],
83 3
				true
84
			);
85
86 3
			$this->propertyRegistry->registerPropertyAlias(
87 3
				$propertyId,
88 3
				$definition['alias']
89
			);
90
		}
91
92 3
		return true;
93
	}
94
95
}
96