123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- declare(strict_types=1);
- namespace Magento\InventoryMultiDimensionalIndexerApi\Model;
- use Magento\Framework\ObjectManagerInterface;
- /**
- * Index Name builder. It is Facade for simplifying IndexName object creation
- *
- * @api
- */
- class IndexNameBuilder
- {
- /**
- * Index id parameter name. Used internally in this object
- *
- * Can not replace on private constant (feature of PHP 7.1) because we need to support PHP 7.0
- */
- private static $indexId = 'indexId';
- /**
- * Dimensions parameter name. Used internally in this object
- *
- * Can not replace on private constant (feature of PHP 7.1) because we need to support PHP 7.0
- */
- private static $dimensions = 'dimensions';
- /**
- * Alias parameter name. Used internally in this object
- *
- * Can not replace on private constant (feature of PHP 7.1) because we need to support PHP 7.0
- */
- private static $alias = 'alias';
- /**
- * @var ObjectManagerInterface
- */
- private $objectManager;
- /**
- * @var DimensionFactory
- */
- private $dimensionFactory;
- /**
- * @var AliasFactory
- */
- private $aliasFactory;
- /**
- * @var array
- */
- private $data = [];
- /**
- * @param ObjectManagerInterface $objectManager
- * @param DimensionFactory $dimensionFactory
- * @param AliasFactory $aliasFactory
- */
- public function __construct(
- ObjectManagerInterface $objectManager,
- DimensionFactory $dimensionFactory,
- AliasFactory $aliasFactory
- ) {
- $this->objectManager = $objectManager;
- $this->dimensionFactory = $dimensionFactory;
- $this->aliasFactory = $aliasFactory;
- }
- /**
- * @param string $indexId
- * @return self
- */
- public function setIndexId(string $indexId): self
- {
- $this->data[self::$indexId] = $indexId;
- return $this;
- }
- /**
- * @param string $name
- * @param string $value
- * @return self
- */
- public function addDimension(string $name, string $value): self
- {
- $this->data[self::$dimensions][] = $this->dimensionFactory->create([
- 'name' => $name,
- 'value' => $value,
- ]);
- return $this;
- }
- /**
- * @param string $alias
- * @return self
- */
- public function setAlias(string $alias): self
- {
- $this->data[self::$alias] = $this->aliasFactory->create(['value' => $alias]);
- return $this;
- }
- /**
- * @return IndexName
- */
- public function build(): IndexName
- {
- $indexName = $this->objectManager->create(IndexName::class, $this->data);
- $this->data = [];
- return $indexName;
- }
- }
|