Maslosoft Manganel API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
<?php
/**
* This software package is licensed under `AGPL, Commercial` license[s].
*
* @package maslosoft/manganel
* @license AGPL, Commercial
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
* @link https://maslosoft.com/manganel/
*/
namespace Maslosoft\Manganel\Annotations;
use Maslosoft\Addendum\Utilities\ClassChecker;
use Maslosoft\Manganel\Meta\ManganelTypeAnnotation;
use UnexpectedValueException;
/**
* Search Type Annotation
*
* Use this annotation to override searched type. This can be used
* to allow search based on hierarchy of models. So that partial
* models could be passed as parameter to query builder and it
* will search for proper type.
*
* Type should be class name, or dot notation name.
*
* Example usage:
* ```
* @SearchType(MyVendror\MyPackage\MyDerivedClass)
* ```
*
* @Target('class')
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class SearchTypeAnnotation extends ManganelTypeAnnotation
{
const Ns = __NAMESPACE__;
/**
* Document type.
* @var string
*/
public $value = null;
public function init()
{
if (empty($this->value))
{
throw new UnexpectedValueException(sprintf('@SearchType annotation requires type name as param, used on model `%s`', $this->getMeta()->type()->name));
}
if (!ClassChecker::exists($this->value))
{
throw new UnexpectedValueException(sprintf('Could not resolve class name for @SearchType annotation used on model `%s`', $this->getMeta()->type()->name));
}
$this->getEntity()->type = $this->value;
}
}
API documentation generated by ApiGen