1 | <?php |
||
2 | /** |
||
3 | * Cycle DataMapper ORM |
||
4 | * |
||
5 | * @license MIT |
||
6 | * @author Anton Titov (Wolfy-J) |
||
7 | */ |
||
8 | declare(strict_types=1); |
||
9 | |||
10 | namespace Cycle\ORM\Relation; |
||
11 | |||
12 | use Cycle\ORM\Command\Branch\Nil; |
||
13 | use Cycle\ORM\Command\CommandInterface; |
||
14 | use Cycle\ORM\Command\ContextCarrierInterface as CC; |
||
15 | use Cycle\ORM\Exception\Relation\NullException; |
||
16 | use Cycle\ORM\Heap\Node; |
||
17 | use Cycle\ORM\Relation\Traits\PromiseOneTrait; |
||
18 | |||
19 | /** |
||
20 | * Provides ability to link to the parent object. Will claim branch up to the parent object and it's relations. To disable |
||
21 | * branch walk-though use RefersTo relation. |
||
22 | */ |
||
23 | class BelongsTo extends AbstractRelation implements DependencyInterface |
||
24 | { |
||
25 | use PromiseOneTrait; |
||
26 | |||
27 | /** |
||
28 | * @inheritdoc |
||
29 | */ |
||
30 | public function queue(CC $parentStore, $parentEntity, Node $parentNode, $related, $original): CommandInterface |
||
31 | { |
||
32 | if (is_null($related)) { |
||
33 | if ($this->isRequired()) { |
||
34 | throw new NullException("Relation {$this} can not be null"); |
||
35 | } |
||
36 | |||
37 | if (!is_null($original)) { |
||
38 | // reset the key |
||
39 | $parentStore->register($this->innerKey, null, true); |
||
40 | } |
||
41 | |||
42 | // nothing to do |
||
43 | return new Nil(); |
||
44 | } |
||
45 | |||
46 | $relStore = $this->orm->queueStore($related); |
||
47 | $relNode = $this->getNode($related); |
||
48 | $this->assertValid($relNode); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
49 | |||
50 | $this->forwardContext($relNode, $this->outerKey, $parentStore, $parentNode, $this->innerKey); |
||
51 | |||
52 | return $relStore; |
||
53 | } |
||
54 | } |
||
55 |