Completed
Push — master ( afa4f8...42f6c3 )
by Peter
22:39
created

SearchTypeAnnotation::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Manganel\Annotations;
10
11
use Maslosoft\Manganel\Meta\ManganelTypeAnnotation;
12
use UnexpectedValueException;
13
14
/**
15
 * Search Type Annotation
16
 *
17
 * Use this annotation to override searched type. This can be used
18
 * to allow search based on hierarchy of models. So that partial
19
 * models could be passed as parameter to query builder and it
20
 * will search for proper type.
21
 *
22
 * Type should be class name, or dot notation name.
23
 *
24
 * Example usage:
25
 * ```
26
 * @SearchType(MyVendror\MyPackage\MyDerivedClass)
27
 * ```
28
 *
29
 * @Target('class')
30
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
31
 */
32
class SearchTypeAnnotation extends ManganelTypeAnnotation
33
{
34
35
	const Ns = __NAMESPACE__;
36
37
	/**
38
	 * Document type.
39
	 * @var string
40
	 */
41
	public $value = null;
42
43
	public function init()
44
	{
45
		if (empty($this->value))
46
		{
47
			throw new UnexpectedValueException(sprintf('@SearchType annotation requires type name as param, used on model `%s`', $this->getMeta()->type()->name));
48
		}
49
		$this->getEntity()->type = $this->value;
50
	}
51
52
}
53