Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MixinFactory.php
Go to the documentation of this file.
1 <?php
7 
12 {
16  const SPAN_MIXIN = 'span';
17  const BOLD_MIXIN = 'b';
18  const BRAKE_MIXIN = 'br';
19  const PARAGRAPH_MIXIN = 'p';
20  const HEADER_MIXIN = 'h1';
21  const ITALIC_MIXIN = 'i';
27  private $typeClassMap = [
28  self::SPAN_MIXIN => SpanMixin::class,
29  self::BOLD_MIXIN => BoldMixin::class,
30  self::BRAKE_MIXIN => BrakeMixin::class,
31  self::PARAGRAPH_MIXIN => ParagraphMixin::class,
32  self::HEADER_MIXIN => HeaderMixin::class,
33  self::ITALIC_MIXIN => ItalicMixin::class,
34  ];
35 
39  private $objectManager;
40 
45  public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
46  {
47  $this->objectManager = $objectManager;
48  }
49 
57  public function create($mixinType)
58  {
59  if (!isset($this->typeClassMap[$mixinType])) {
60  throw new \InvalidArgumentException(sprintf('Undefined mixin type: %s.', $mixinType));
61  }
62 
63  $mixin = $this->objectManager->get($this->typeClassMap[$mixinType]);
64 
65  if (!$mixin instanceof \Magento\Setup\Model\Description\Mixin\DescriptionMixinInterface) {
66  throw new \InvalidArgumentException(
67  sprintf(
68  'Class "%s" must implement \Magento\Setup\Model\Description\Mixin\DescriptionMixinInterface.',
69  get_class($mixin)
70  )
71  );
72  }
73 
74  return $mixin;
75  }
76 }
__construct(\Magento\Framework\ObjectManagerInterface $objectManager)
$objectManager
Definition: bootstrap.php:17