| @@ 531-548 (lines=18) @@ | ||
| 528 | * @return ArrayAccess|DescribableInterface|mixed |
|
| 529 | * @throws UnexpectedValueException If the structure is invalid. |
|
| 530 | */ |
|
| 531 | public function toModel($model = null) |
|
| 532 | { |
|
| 533 | if ($model) { |
|
| 534 | $structure = $this->structureModelFactory()->create($model); |
|
| 535 | ||
| 536 | if (!$structure instanceof ArrayAccess) { |
|
| 537 | throw new UnexpectedValueException(sprintf( |
|
| 538 | 'Structure [%s] must implement [%s]', |
|
| 539 | $model, |
|
| 540 | ArrayAccess::class |
|
| 541 | )); |
|
| 542 | } |
|
| 543 | ||
| 544 | return $structure; |
|
| 545 | } |
|
| 546 | ||
| 547 | return $this->structureProto(); |
|
| 548 | } |
|
| 549 | ||
| 550 | /** |
|
| 551 | * PropertyInterface::save(). |
|
| @@ 673-687 (lines=15) @@ | ||
| 670 | * @throws UnexpectedValueException If the structure is invalid. |
|
| 671 | * @return ArrayAccess |
|
| 672 | */ |
|
| 673 | private function createStructureModel() |
|
| 674 | { |
|
| 675 | $structClass = $this->getStructureModelClass(); |
|
| 676 | $structure = $this->structureModelFactory()->create($structClass); |
|
| 677 | ||
| 678 | if (!$structure instanceof ArrayAccess) { |
|
| 679 | throw new UnexpectedValueException(sprintf( |
|
| 680 | 'Structure [%s] must implement [%s]', |
|
| 681 | $structClass, |
|
| 682 | ArrayAccess::class |
|
| 683 | )); |
|
| 684 | } |
|
| 685 | ||
| 686 | return $structure; |
|
| 687 | } |
|
| 688 | ||
| 689 | /** |
|
| 690 | * Create a data-model structure. |
|