@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | private $siblings = []; |
| 10 | 10 | |
| 11 | 11 | public function __construct(\Maphper\Maphper $mapper, $parentField, $localField, array $criteria = []) { |
| 12 | - if ($criteria) $mapper = $mapper->filter($this->criteira); |
|
| 12 | + if ($criteria) $mapper = $mapper->filter($this->criteira); |
|
| 13 | 13 | $this->mapper = $mapper; |
| 14 | 14 | $this->parentField = $parentField; |
| 15 | 15 | $this->localField = $localField; |
@@ -49,18 +49,18 @@ discard block |
||
| 49 | 49 | //Fetch the results so they're in the cache for the corresponding maphper object |
| 50 | 50 | $results = $this->mapper->filter([$this->localField => $recordsToLoad]); |
| 51 | 51 | |
| 52 | - $this->loadDataIntoSiblings($results); |
|
| 52 | + $this->loadDataIntoSiblings($results); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - private function loadDataIntoSiblings($results) { |
|
| 56 | - $cache = []; |
|
| 55 | + private function loadDataIntoSiblings($results) { |
|
| 56 | + $cache = []; |
|
| 57 | 57 | foreach ($results as $result) { |
| 58 | 58 | $cache[$result->{$this->localField}] = $result; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | foreach ($this->siblings as $sibling) { |
| 62 | - if ($sibling->parentField === $this->parentField && |
|
| 63 | - isset($cache[$sibling->parentObject->{$this->parentField}]))$sibling->data = $cache[$sibling->parentObject->{$this->parentField}]; |
|
| 62 | + if ($sibling->parentField === $this->parentField && |
|
| 63 | + isset($cache[$sibling->parentObject->{$this->parentField}]))$sibling->data = $cache[$sibling->parentObject->{$this->parentField}]; |
|
| 64 | 64 | } |
| 65 | 65 | /* |
| 66 | 66 | foreach ($this->siblings as $sibling) { |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | else $sibling->data = $sibling->mapper->filter([$sibling->localField => $sibling->parentObject->{$this->parentField}])->item(0); |
| 69 | 69 | } |
| 70 | 70 | */ |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | 73 | public function __call($func, array $args = []) { |
| 74 | 74 | if ($this->lazyLoad() == null) return ''; |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | public function __get($name) { |
| 79 | 79 | if ($this->lazyLoad()) return $this->lazyLoad()->$name; |
| 80 | - else return null; |
|
| 80 | + else return null; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | public function __isset($name) { |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | public function overwrite($parentObject, &$data) { |
| 88 | - $this->mapper[] = $data; |
|
| 88 | + $this->mapper[] = $data; |
|
| 89 | 89 | |
| 90 | - if (!isset($parentObject->{$this->parentField}) || $parentObject->{$this->parentField} != $data->{$this->localField}) { |
|
| 90 | + if (!isset($parentObject->{$this->parentField}) || $parentObject->{$this->parentField} != $data->{$this->localField}) { |
|
| 91 | 91 | $parentObject->{$this->parentField} = $data->{$this->localField}; |
| 92 | 92 | //Trigger an update of the parent object |
| 93 | 93 | return true; |
@@ -9,7 +9,9 @@ discard block |
||
| 9 | 9 | private $siblings = []; |
| 10 | 10 | |
| 11 | 11 | public function __construct(\Maphper\Maphper $mapper, $parentField, $localField, array $criteria = []) { |
| 12 | - if ($criteria) $mapper = $mapper->filter($this->criteira); |
|
| 12 | + if ($criteria) { |
|
| 13 | + $mapper = $mapper->filter($this->criteira); |
|
| 14 | + } |
|
| 13 | 15 | $this->mapper = $mapper; |
| 14 | 16 | $this->parentField = $parentField; |
| 15 | 17 | $this->localField = $localField; |
@@ -29,7 +31,9 @@ discard block |
||
| 29 | 31 | private function lazyLoad() { |
| 30 | 32 | if (!isset($this->data)) { |
| 31 | 33 | |
| 32 | - if ($this->parentObject == null) throw new \Exception('Error, no object set'); |
|
| 34 | + if ($this->parentObject == null) { |
|
| 35 | + throw new \Exception('Error, no object set'); |
|
| 36 | + } |
|
| 33 | 37 | |
| 34 | 38 | $this->eagerLoad(); |
| 35 | 39 | |
@@ -41,8 +45,10 @@ discard block |
||
| 41 | 45 | $recordsToLoad = []; |
| 42 | 46 | //Get a list of records by FK to eager load |
| 43 | 47 | foreach ($this->siblings as $sibling) { |
| 44 | - if ($sibling->parentField === $this->parentField) // Ensure that it is only loading records from the same type of relation |
|
| 48 | + if ($sibling->parentField === $this->parentField) { |
|
| 49 | + // Ensure that it is only loading records from the same type of relation |
|
| 45 | 50 | $recordsToLoad[] = $sibling->parentObject->{$sibling->parentField}; |
| 51 | + } |
|
| 46 | 52 | } |
| 47 | 53 | |
| 48 | 54 | $recordsToLoad = array_unique($recordsToLoad); |
@@ -60,7 +66,9 @@ discard block |
||
| 60 | 66 | |
| 61 | 67 | foreach ($this->siblings as $sibling) { |
| 62 | 68 | if ($sibling->parentField === $this->parentField && |
| 63 | - isset($cache[$sibling->parentObject->{$this->parentField}]))$sibling->data = $cache[$sibling->parentObject->{$this->parentField}]; |
|
| 69 | + isset($cache[$sibling->parentObject->{$this->parentField}])) { |
|
| 70 | + $sibling->data = $cache[$sibling->parentObject->{$this->parentField}]; |
|
| 71 | + } |
|
| 64 | 72 | } |
| 65 | 73 | /* |
| 66 | 74 | foreach ($this->siblings as $sibling) { |
@@ -71,13 +79,18 @@ discard block |
||
| 71 | 79 | } |
| 72 | 80 | |
| 73 | 81 | public function __call($func, array $args = []) { |
| 74 | - if ($this->lazyLoad() == null) return ''; |
|
| 82 | + if ($this->lazyLoad() == null) { |
|
| 83 | + return ''; |
|
| 84 | + } |
|
| 75 | 85 | return call_user_func_array([$this->lazyLoad(), $func], $args); |
| 76 | 86 | } |
| 77 | 87 | |
| 78 | 88 | public function __get($name) { |
| 79 | - if ($this->lazyLoad()) return $this->lazyLoad()->$name; |
|
| 80 | - else return null; |
|
| 89 | + if ($this->lazyLoad()) { |
|
| 90 | + return $this->lazyLoad()->$name; |
|
| 91 | + } else { |
|
| 92 | + return null; |
|
| 93 | + } |
|
| 81 | 94 | } |
| 82 | 95 | |
| 83 | 96 | public function __isset($name) { |