Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomConditionProvider.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
18 {
22  private $customConditionProcessors;
23 
28  public function __construct(array $customConditionProcessors = [])
29  {
30  foreach ($customConditionProcessors as $processor) {
31  if (!$processor instanceof CustomConditionInterface) {
32  throw new InputException(
33  new Phrase('Custom processor must implement "%1".', [CustomConditionInterface::class])
34  );
35  }
36  }
37 
38  $this->customConditionProcessors = $customConditionProcessors;
39  }
40 
48  public function getProcessorByField(string $fieldName): CustomConditionInterface
49  {
50  if (!$this->hasProcessorForField($fieldName)) {
51  throw new InputException(
52  new Phrase('Custom processor for field "%1" is absent.', [$fieldName])
53  );
54  }
55 
56  return $this->customConditionProcessors[$fieldName];
57  }
58 
65  public function hasProcessorForField(string $fieldName): bool
66  {
67  return array_key_exists($fieldName, $this->customConditionProcessors);
68  }
69 }
$processor
Definition: 404.php:10