@@ 75-89 (lines=15) @@ | ||
72 | * |
|
73 | * @throws RepositoryException If this model or the referenced model is not handled by a managed repository. |
|
74 | */ |
|
75 | public function getReference($name) |
|
76 | { |
|
77 | if (!isset($this->_manager)) { |
|
78 | throw new RepositoryException('Model is not handled by a managed repository'); |
|
79 | } |
|
80 | if (array_key_exists($name, $this->_references)) { |
|
81 | $ref = $this->_references[$name]; |
|
82 | $repo = $this->_manager->getByClass($ref['model']); |
|
83 | if (!$repo) { |
|
84 | throw new RepositoryException('Referenced model is not handled by a managed repository'); |
|
85 | } |
|
86 | return ($repo->find($ref['key'], $this->{$ref['attribute']}) ?: null); |
|
87 | } |
|
88 | return null; |
|
89 | } |
|
90 | ||
91 | ||
92 | /** |
@@ 22-36 (lines=15) @@ | ||
19 | * |
|
20 | * @throws RepositoryException If this model or the referenced model is not handled by a managed repository, or the referenced repository is not soft-deletion aware. |
|
21 | */ |
|
22 | public function getReferenceSoft($name) |
|
23 | { |
|
24 | if (!isset($this->_manager)) { |
|
25 | throw new RepositoryException('Model is not handled by a managed repository'); |
|
26 | } |
|
27 | if (array_key_exists($name, $this->_references)) { |
|
28 | $ref = $this->_references[$name]; |
|
29 | $repo = $this->_manager->getByClass($ref['model']); |
|
30 | if (!$repo || !($repo instanceof SoftRepositoryInterface)) { |
|
31 | throw new RepositoryException('Referenced model is not handled by a managed soft-deletion-aware repository'); |
|
32 | } |
|
33 | return ($repo->findSoft($ref['key'], $this->{$ref['attribute']}) ?: null); |
|
34 | } |
|
35 | return null; |
|
36 | } |
|
37 | } |
|
38 |