1: <?php
2:
3: namespace PHPixie\ORM\Relationships\Relationship\Implementation;
4:
5: abstract class Handler
6: {
7: protected $models;
8: protected $planners;
9: protected $plans;
10: protected $steps;
11: protected $loaders;
12: protected $mappers;
13: protected $relationship;
14:
15: public function __construct($models, $planners, $plans, $steps, $loaders, $mappers, $relationship)
16: {
17: $this->models = $models;
18: $this->planners = $planners;
19: $this->plans = $plans;
20: $this->steps = $steps;
21: $this->loaders = $loaders;
22: $this->mappers = $mappers;
23: $this->relationship = $relationship;
24: }
25:
26: protected function getLoadedProperty($model, $propertyName)
27: {
28: if ($model === null)
29: return null;
30:
31: $property = $model->getRelationshipProperty($propertyName, false);
32: if ($property === null || !$property->isLoaded())
33: return null;
34:
35: return $property;
36: }
37:
38: protected function assertModelName($model, $requiredModel)
39: {
40: if ($model->modelName() !== $requiredModel)
41: throw new \PHPixie\ORM\Exception\Relationship("Only '$requiredModel' models can be used for this relationship.");
42: }
43:
44: protected function getPropertyIfLoaded($model, $propertyName)
45: {
46: $property = $model->getRelationshipProperty($propertyName);
47: if ($property === null || !$property->isLoaded())
48: return null;
49: return $property;
50: }
51:
52: protected function isEntityValue($item)
53: {
54: if($item === null) {
55: return true;
56: }
57:
58: return $item instanceof \PHPixie\ORM\Models\Model\Entity;
59: }
60: }