| @@ 146-167 (lines=22) @@ | ||
| 143 | } |
|
| 144 | ||
| 145 | /** {@inheritdoc} */ |
|
| 146 | public function setResources($resources) |
|
| 147 | { |
|
| 148 | $result = []; |
|
| 149 | foreach ((array) $resources as $resource) { |
|
| 150 | if ($resource instanceof ServerResource) { |
|
| 151 | $result[] = $resource; |
|
| 152 | continue; |
|
| 153 | } |
|
| 154 | ||
| 155 | $model = new ServerResource(['scenario' => $this->scenario]); |
|
| 156 | ||
| 157 | if ($model->load($resource, '') && $model->validate()) { |
|
| 158 | $result[] = $model; |
|
| 159 | } else { |
|
| 160 | throw new UnprocessableEntityHttpException('Failed to load resource model: ' . reset($model->getFirstErrors())); |
|
| 161 | } |
|
| 162 | } |
|
| 163 | ||
| 164 | $this->_resources = $result; |
|
| 165 | ||
| 166 | return $this; |
|
| 167 | } |
|
| 168 | ||
| 169 | protected function calculator() |
|
| 170 | { |
|
| @@ 117-138 (lines=22) @@ | ||
| 114 | } |
|
| 115 | ||
| 116 | /** {@inheritdoc} */ |
|
| 117 | public function setResources($resources) |
|
| 118 | { |
|
| 119 | $result = []; |
|
| 120 | foreach ((array) $resources as $resource) { |
|
| 121 | if ($resource instanceof ServerResource) { |
|
| 122 | $result[] = $resource; |
|
| 123 | continue; |
|
| 124 | } |
|
| 125 | ||
| 126 | $model = new ServerResource(['scenario' => $this->scenario]); |
|
| 127 | ||
| 128 | if ($model->load($resource, '') && $model->validate()) { |
|
| 129 | $result[] = $model; |
|
| 130 | } else { |
|
| 131 | throw new UnprocessableEntityHttpException('Failed to load resource model: ' . reset($model->getFirstErrors())); |
|
| 132 | } |
|
| 133 | } |
|
| 134 | ||
| 135 | $this->_resources = $result; |
|
| 136 | ||
| 137 | return $this; |
|
| 138 | } |
|
| 139 | } |
|
| 140 | ||
| @@ 80-101 (lines=22) @@ | ||
| 77 | return $result; |
|
| 78 | } |
|
| 79 | ||
| 80 | public function setResources($resources) |
|
| 81 | { |
|
| 82 | $result = []; |
|
| 83 | foreach ($resources as $resource) { |
|
| 84 | if ($resource instanceof DomainResource) { |
|
| 85 | $result[] = $resource; |
|
| 86 | continue; |
|
| 87 | } |
|
| 88 | ||
| 89 | $model = new DomainResource(['scenario' => $this->scenario]); |
|
| 90 | ||
| 91 | if ($model->load($resource, '') && $model->validate()) { |
|
| 92 | $result[] = $model; |
|
| 93 | } else { |
|
| 94 | throw new UnprocessableEntityHttpException('Failed to load resource model: ' . reset($model->getFirstErrors())); |
|
| 95 | } |
|
| 96 | } |
|
| 97 | ||
| 98 | $this->_resources = $result; |
|
| 99 | ||
| 100 | return $this; |
|
| 101 | } |
|
| 102 | ||
| 103 | public function getZoneResources($zone) |
|
| 104 | { |
|