Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FeedFactory.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
8 namespace Magento\Framework\App;
9 
11 use Psr\Log\LoggerInterface;
12 
17 {
21  private $objectManager;
22 
26  private $logger;
27 
31  private $formats;
32 
38  public function __construct(
39  ObjectManagerInterface $objectManger,
40  LoggerInterface $logger,
41  array $formats
42  ) {
43  $this->objectManager = $objectManger;
44  $this->logger = $logger;
45  $this->formats = $formats;
46  }
47 
52  {
53  if (!isset($this->formats[$format])) {
54  throw new \Magento\Framework\Exception\InputException(
55  new \Magento\Framework\Phrase('The format is not supported')
56  );
57  }
58 
59  if (!is_subclass_of($this->formats[$format], \Magento\Framework\App\FeedInterface::class)) {
60  throw new \Magento\Framework\Exception\InputException(
61  new \Magento\Framework\Phrase('Wrong format handler type')
62  );
63  }
64 
65  try {
66  return $this->objectManager->create(
67  $this->formats[$format],
68  ['data' => $data]
69  );
70  } catch (\Exception $e) {
71  $this->logger->error($e->getMessage());
72  throw new \Magento\Framework\Exception\RuntimeException(
73  new \Magento\Framework\Phrase('There has been an error with import'),
74  $e
75  );
76  }
77  }
78 }
is_subclass_of($obj, $className)
$logger
__construct(ObjectManagerInterface $objectManger, LoggerInterface $logger, array $formats)
Definition: FeedFactory.php:38
$format
Definition: list.phtml:12
create(array $data, string $format=FeedFactoryInterface::FORMAT_RSS)
Definition: FeedFactory.php:51