|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\Ui\Model\UrlInput; |
| 10 | + |
| 11 | +/** |
| 12 | + * Returns information about allowed links |
| 13 | + */ |
| 14 | +class LinksConfigProvider implements ConfigInterface |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var array |
| 18 | + */ |
| 19 | + private $linksConfiguration; |
| 20 | + |
| 21 | + /** |
| 22 | + * Object manager |
| 23 | + * |
| 24 | + * @var \Magento\Framework\ObjectManagerInterface |
| 25 | + */ |
| 26 | + private $objectManager; |
| 27 | + |
| 28 | + /** |
| 29 | + * LinksProvider constructor. |
| 30 | + * @param array $linksConfiguration |
| 31 | + * @param \Magento\Framework\ObjectManagerInterface $objectManager |
| 32 | + */ |
| 33 | + public function __construct( |
| 34 | + array $linksConfiguration, |
| 35 | + \Magento\Framework\ObjectManagerInterface $objectManager |
| 36 | + ) { |
| 37 | + $this->linksConfiguration = $linksConfiguration; |
| 38 | + $this->objectManager = $objectManager; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * {@inheritdoc} |
| 43 | + */ |
| 44 | + public function getConfig() |
| 45 | + { |
| 46 | + $config = []; |
| 47 | + foreach ($this->linksConfiguration as $linkName => $className) { |
| 48 | + $config[$linkName] = $this->createConfigProvider($className)->getConfig(); |
| 49 | + } |
| 50 | + return $config; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Create config provider |
| 55 | + * |
| 56 | + * @param string $instance |
| 57 | + * @return ConfigInterface |
| 58 | + */ |
| 59 | + private function createConfigProvider($instance) |
| 60 | + { |
| 61 | + if (!is_subclass_of( |
| 62 | + $instance, |
| 63 | + ConfigInterface::class |
| 64 | + ) |
| 65 | + ) { |
| 66 | + throw new \InvalidArgumentException( |
| 67 | + $instance . |
| 68 | + ' does not implement ' . |
| 69 | + ConfigInterface::class |
| 70 | + ); |
| 71 | + } |
| 72 | + return $this->objectManager->create($instance); |
| 73 | + } |
| 74 | +} |
0 commit comments