Completed
Push — master ( bd6cb0...78269a )
by Florian
02:22
created

DocumentAdapter::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Stinger Entity Search package.
5
 *
6
 * (c) Oliver Kotte <[email protected]>
7
 * (c) Florian Meyer <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
namespace StingerSoft\EntitySearchBundle\Model;
13
14
class DocumentAdapter implements Document {
15
16
	/**
17
	 * Stores are fields with their values which should be stored in the index
18
	 *
19
	 * @var array
20
	 */
21
	protected $fields = array();
22
23
	/**
24
	 *
25
	 * @var string
26
	 */
27
	protected $entityClass = null;
28
29
	/**
30
	 *
31
	 * @var mixed
32
	 */
33
	protected $entityId = null;
34
35
	/**
36
	 *
37
	 * @var string
38
	 */
39
	protected $entityType = null;
40
41
	/**
42
	 *
43
	 * @var string
44
	 */
45
	protected $file = null;
46
47
	/**
48
	 *
49
	 * {@inheritdoc}
50
	 *
51
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::addField()
52
	 */
53
	public function addField($fieldname, $value) {
54
		$this->fields[$fieldname] = $value;
55
	}
56
57
	/**
58
	 *
59
	 * {@inheritdoc}
60
	 *
61
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getFields()
62
	 */
63
	public function getFields() {
64
		return $this->fields;
65
	}
66
67
	/**
68
	 *
69
	 * {@inheritdoc}
70
	 *
71
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getFieldValue()
72
	 */
73
	public function getFieldValue($field) {
74
		return isset($this->fields[$field]) ? $this->fields[$field] : null;
75
	}
76
77
	/**
78
	 *
79
	 * {@inheritdoc}
80
	 *
81
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::addMultiValueField()
82
	 */
83
	public function addMultiValueField($field, $value) {
84
		if(!array_key_exists($field, $this->fields)) {
85
			$this->fields[$field] = array(
86
				$value 
87
			);
88
		} else if(!in_array($value, $this->fields[$field])) {
89
			$this->fields[$field][] = $value;
90
		}
91
	}
92
93
	/**
94
	 *
95
	 * {@inheritdoc}
96
	 *
97
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::setEntityClass()
98
	 */
99
	public function setEntityClass($clazz) {
100
		$this->entityClass = $clazz;
101
		if(!$this->entityType) {
102
			$this->entityType = $entityClass;
0 ignored issues
show
Bug introduced by
The variable $entityClass does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
103
		}
104
	}
105
106
	/**
107
	 *
108
	 * {@inheritdoc}
109
	 *
110
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getEntityClass()
111
	 */
112
	public function getEntityClass() {
113
		return $this->entityClass;
114
	}
115
116
	/**
117
	 *
118
	 * {@inheritdoc}
119
	 *
120
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::setEntityId()
121
	 */
122
	public function setEntityId($id) {
123
		$this->entityId = $id;
124
	}
125
126
	/**
127
	 *
128
	 * {@inheritdoc}
129
	 *
130
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getEntityId()
131
	 */
132
	public function getEntityId() {
133
		return $this->entityId;
134
	}
135
136
	/**
137
	 *
138
	 * {@inheritdoc}
139
	 *
140
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::setEntityType()
141
	 */
142
	public function setEntityType($type) {
143
		$this->entityType = $type;
144
	}
145
146
	/**
147
	 *
148
	 * {@inheritdoc}
149
	 *
150
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getEntityType()
151
	 */
152
	public function getEntityType() {
153
		return $this->entityType ? $this->entityType : $this->getEntityClass();
154
	}
155
156
	/**
157
	 *
158
	 * {@inheritdoc}
159
	 *
160
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::setFile()
161
	 */
162
	public function setFile($path) {
163
		$this->file = $path;
164
	}
165
	
166
	/**
167
	 *
168
	 * {@inheritdoc}
169
	 *
170
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getFile()
171
	 */
172
	public function getFile() {
173
		return $this->file;
174
	}
175
176
	/**
177
	 *
178
	 * {@inheritdoc}
179
	 *
180
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::__get()
181
	 */
182
	public function __get($name) {
183
		return $this->getFieldValue($name);
184
	}
185
186
	/**
187
	 *
188
	 * {@inheritdoc}
189
	 *
190
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::__isset()
191
	 */
192
	public function __isset($name) {
193
		return $this->getFieldValue($name) !== null;
194
	}
195
}