Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdapterFactory.php
Go to the documentation of this file.
1 <?php
7 
9 {
13  protected $config;
14 
18  protected $objectManager;
19 
23  protected $adapterMap;
24 
30  public function __construct(
32  \Magento\Framework\Image\Adapter\ConfigInterface $config,
33  array $adapterMap = []
34  ) {
35  $this->objectManager = $objectManager;
36  $this->config = $config;
37  $this->adapterMap = $adapterMap;
38  }
39 
47  public function create($adapterAlias = null)
48  {
49  $this->adapterMap = array_merge($this->config->getAdapters(), $this->adapterMap);
50  $adapterAlias = !empty($adapterAlias) ? $adapterAlias : $this->config->getAdapterAlias();
51  if (empty($adapterAlias)) {
52  throw new \InvalidArgumentException('Image adapter is not selected.');
53  }
54  if (empty($this->adapterMap[$adapterAlias]['class'])) {
55  throw new \InvalidArgumentException("Image adapter for '{$adapterAlias}' is not setup.");
56  }
57  $imageAdapter = $this->objectManager->create($this->adapterMap[$adapterAlias]['class']);
58  if (!$imageAdapter instanceof Adapter\AdapterInterface) {
59  throw new \InvalidArgumentException(
60  $this->adapterMap[$adapterAlias]['class'] .
61  ' is not instance of \Magento\Framework\Image\Adapter\AdapterInterface'
62  );
63  }
64  $imageAdapter->checkDependencies();
65  return $imageAdapter;
66  }
67 }
__construct(\Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\Image\Adapter\ConfigInterface $config, array $adapterMap=[])