use Maslosoft\Manganel\Meta\ManganelTypeAnnotation;
17
use UnexpectedValueException;
18
19
/**
20
* Search Type Annotation
21
*
22
* Use this annotation to override searched type. This can be used
23
* to allow search based on hierarchy of models. So that partial
24
* models could be passed as parameter to query builder and it
25
* will search for proper type.
26
*
27
* Type should be class name, or dot notation name.
28
*
29
* Example usage:
30
* ```
31
* @SearchType(MyVendror\MyPackage\MyDerivedClass)
32
* ```
33
*
34
* @Target('class')
35
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
36
*/
37
class SearchTypeAnnotation extends ManganelTypeAnnotation
38
{
39
40
const Ns = __NAMESPACE__;
41
42
/**
43
* Document type.
44
* @var string
45
*/
46
public $value = null;
47
48
1
public function init()
49
{
50
1
if (empty($this->value))
51
{
52
throw new UnexpectedValueException(sprintf('@SearchType annotation requires type name as param, used on model `%s`', $this->getMeta()->type()->name));
53
}
54
1
if (!ClassChecker::exists($this->value))
55
{
56
throw new UnexpectedValueException(sprintf('Could not resolve class name for @SearchType annotation used on model `%s`', $this->getMeta()->type()->name));