1 | <?php |
||
23 | abstract class AbstractEntityService implements EntityServiceInterface |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $entityClass; |
||
30 | |||
31 | /** |
||
32 | * @var EntityInterface |
||
33 | */ |
||
34 | protected $entity; |
||
35 | |||
36 | /** |
||
37 | * Set FQ entity class name |
||
38 | * |
||
39 | * @param string $className |
||
40 | * |
||
41 | * @throws InvalidEntityClassException If the provided class name does |
||
42 | * not implements the Slick\Orm\EntityInterface interface. |
||
43 | * |
||
44 | * @return $this|self|AbstractEntityService |
||
45 | */ |
||
46 | 14 | public function setEntityClass($className) |
|
47 | { |
||
48 | if ( |
||
49 | 14 | !class_exists($className) || |
|
50 | 14 | !is_subclass_of($className, EntityInterface::class) |
|
51 | 7 | ) { |
|
52 | 2 | throw new InvalidEntityClassException( |
|
53 | 2 | "Class '{$className}' does not implements the " . |
|
54 | 1 | "Slick\Orm\EntityInterface interface." |
|
55 | 1 | ); |
|
56 | } |
||
57 | |||
58 | 12 | $this->entityClass = $className; |
|
59 | 12 | return $this; |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Sets the entity that will be the subject of this service |
||
64 | * |
||
65 | * @param EntityInterface $entity |
||
66 | * |
||
67 | * @return $this|self|AbstractEntityService |
||
68 | */ |
||
69 | 8 | public function setEntity(EntityInterface $entity) |
|
74 | |||
75 | /** |
||
76 | * Get the entity FQ class name |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | 4 | public function getEntityClassName() |
|
87 | |||
88 | /** |
||
89 | * Gets entity class |
||
90 | * |
||
91 | * @return EntityInterface |
||
92 | */ |
||
93 | 4 | public function getEntity() |
|
102 | } |