Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Factory Class Reference

Public Member Functions

 __construct (ObjectManagerInterface $objectManager)
 
 create ($type, $text=null)
 

Protected Attributes

 $types
 
 $objectManager
 

Detailed Description

Message model factory

Definition at line 14 of file Factory.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ObjectManagerInterface  $objectManager)

Factory constructor

Parameters
ObjectManagerInterface$objectManager

Definition at line 40 of file Factory.php.

41  {
42  $this->objectManager = $objectManager;
43  }

Member Function Documentation

◆ create()

create (   $type,
  $text = null 
)

Create a message instance of a given type with given text.

Parameters
string | null$typeThe message type to create, must correspond to a message type under the namespace Magento\Framework\Message\
string$textThe text to inject into the message
Exceptions

Definition at line 54 of file Factory.php.

55  {
56  if (!in_array($type, $this->types)) {
57  throw new \InvalidArgumentException('Wrong message type');
58  }
59 
60  $className = 'Magento\\Framework\\Message\\' . ucfirst($type);
61 
62  $message = $this->objectManager->create($className, $text === null ? [] : ['text' => $text]);
63  if (!$message instanceof MessageInterface) {
64  throw new \InvalidArgumentException(
65  $className . ' doesn\'t implement \Magento\Framework\Message\MessageInterface'
66  );
67  }
68 
69  return $message;
70  }
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43
$message
$type
Definition: item.phtml:13
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

Field Documentation

◆ $objectManager

$objectManager
protected

Definition at line 33 of file Factory.php.

◆ $types

$types
protected

The documentation for this class was generated from the following file: