Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AlgorithmFactory.php
Go to the documentation of this file.
1 <?php
8 
13 
15 {
19  const XML_PATH_RANGE_CALCULATION = 'catalog/layered_navigation/price_range_calculation';
20 
21  const RANGE_CALCULATION_AUTO = 'auto';
22  const RANGE_CALCULATION_IMPROVED = 'improved';
23  const RANGE_CALCULATION_MANUAL = 'manual';
24 
30  protected $objectManager;
31 
35  private $scopeConfig;
36 
40  private $algorithms;
41 
49  public function __construct(
51  ScopeConfigInterface $scopeConfig,
52  array $algorithms
53  ) {
54  $this->objectManager = $objectManager;
55  $this->scopeConfig = $scopeConfig;
56  $this->algorithms = $algorithms;
57  }
58 
66  public function create(array $data = [])
67  {
68  $calculationType = $this->scopeConfig->getValue(
69  self::XML_PATH_RANGE_CALCULATION,
70  ScopeInterface::SCOPE_STORE
71  );
72 
73  if (!isset($this->algorithms[$calculationType])) {
74  throw new LocalizedException(__("The %1 value wasn't found in the algorithms.", $calculationType));
75  }
76 
77  $className = $this->algorithms[$calculationType];
78  $model = $this->objectManager->create($className, $data);
79 
80  if (!$model instanceof AlgorithmInterface) {
81  throw new LocalizedException(
82  __('%1 doesn\'t extend \Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmInterface', $className)
83  );
84  }
85 
86  return $model;
87  }
88 }
__construct(ObjectManagerInterface $objectManager, ScopeConfigInterface $scopeConfig, array $algorithms)
__()
Definition: __.php:13
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31