Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ImageProvider.php
Go to the documentation of this file.
1 <?php
7 
14 
19 {
23  private $imageBuilder;
24 
28  private $storeManager;
29 
33  private $appEmulation;
34 
40  public function __construct(
41  ImageBuilder $imageBuilder,
42  StoreManagerInterface $storeManager,
43  Emulation $appEmulation
44  ) {
45  $this->imageBuilder = $imageBuilder;
46  $this->storeManager = $storeManager;
47  $this->appEmulation = $appEmulation;
48  }
49 
57  public function getImage(Product $product, $imageId, $attributes = [])
58  {
59  $storeId = $this->storeManager->getStore()->getId();
60  $this->appEmulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND, true);
61 
62  try {
63  $image = $this->imageBuilder->create($product, $imageId, $attributes);
64  } catch (\Exception $exception) {
65  $this->appEmulation->stopEnvironmentEmulation();
66  throw $exception;
67  }
68 
69  $this->appEmulation->stopEnvironmentEmulation();
70  return $image;
71  }
72 }
__construct(ImageBuilder $imageBuilder, StoreManagerInterface $storeManager, Emulation $appEmulation)
$storeManager
$attributes
Definition: matrix.phtml:13
getImage(Product $product, $imageId, $attributes=[])