Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EnumFactory.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
18 {
22  private $objectManager;
23 
27  private $enumValueFactory;
28 
33  public function __construct(
34  ObjectManagerInterface $objectManager,
35  EnumValueFactory $enumValueFactory
36  ) {
37  $this->objectManager = $objectManager;
38  $this->enumValueFactory = $enumValueFactory;
39  }
40 
49  public function create(string $name, array $values, string $description = ''): Enum
50  {
51  return $this->objectManager->create(
52  Enum::class,
53  [
54  'name' => $name,
55  'values' => $values,
56  'description' => $description
57  ]
58  );
59  }
60 
68  {
69  $values = [];
70  foreach ($data['items'] as $item) {
71  $values[$item['_value']] = $this->enumValueFactory->create(
72  $item['name'],
73  $item['_value'],
74  isset($item['description']) ? $item['description'] : ''
75  );
76  }
77  return $this->create(
78  $data['name'],
79  $values,
80  isset($data['description']) ? $data['description'] : ''
81  );
82  }
83 }
$objectManager
Definition: bootstrap.php:17
$values
Definition: options.phtml:88
create(string $name, array $values, string $description='')
Definition: EnumFactory.php:49
__construct(ObjectManagerInterface $objectManager, EnumValueFactory $enumValueFactory)
Definition: EnumFactory.php:33
if(!isset($_GET['name'])) $name
Definition: log.php:14