1: <?php
2:
3: namespace PHPixie\ORM\Relationships\Type\OneTo\Property\Entity;
4:
5: abstract class Single extends \PHPixie\ORM\Relationships\Type\OneTo\Property\Entity
6: {
7: public function value()
8: {
9: $value = parent::value();
10:
11: if ($value !== null && $value->isDeleted()) {
12: $this->setValue(null);
13: return null;
14: }
15:
16: return $value;
17: }
18:
19: public function asData($recursive = false)
20: {
21: $value = $this->value();
22: if ($value === null)
23: return null;
24:
25: return $value->asObject($recursive);
26: }
27:
28: public function set($value)
29: {
30: if($value === null) {
31: return $this->remove();
32: }
33:
34: if($value instanceof \PHPixie\ORM\Models\Type\Database\Entity && $value->isDeleted()) {
35: return $this->remove();
36: }
37:
38: $plan = $this->linkPlan($value);
39: $plan->execute();
40: $this->setProperties($value);
41: return $this;
42: }
43:
44: public function remove()
45: {
46: $plan = $this->unlinkPlan();
47: $plan->execute();
48: $this->unsetProperties();
49: return $this;
50: }
51:
52: abstract protected function linkPlan($value);
53: abstract protected function setProperties($value);
54: abstract protected function unlinkPlan();
55: abstract protected function unsetProperties();
56: }
57: