b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / vendor / magento / framework / Message /
Filename/home/dev2.destoffenstraat.com/vendor/magento/framework/Message/Factory.php
Size1.87 kb
Permissionrw-r--r--
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified07-Jan-2021 21:08
Last accessed21-Aug-2025 12:29
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\Message;

use Magento\Framework\ObjectManagerInterface;

/**
* Message model factory
*/
class Factory
{
/**
* Allowed message types
*
* @var string[]
*/
protected $types = [
MessageInterface::TYPE_ERROR,
MessageInterface::TYPE_WARNING,
MessageInterface::TYPE_NOTICE,
MessageInterface::TYPE_SUCCESS,
];

/**
* Object Manager instance
*
* @var ObjectManagerInterface
*/
protected $objectManager;

/**
* Factory constructor
*
* @param ObjectManagerInterface $objectManager
*/
public function __construct(ObjectManagerInterface $objectManager)
{
$this->objectManager = $objectManager;
}

/**
* Create a message instance of a given type with given text.
*
* @param string|null $type The message type to create, must correspond to a message type under the
* namespace Magento\Framework\Message\
* @param string $text The text to inject into the message
* @throws \InvalidArgumentException Exception gets thrown if type does not correspond to a valid Magento message
* @return MessageInterface
*/
public function create($type, $text = null)
{
if (!in_array($type, $this->types)) {
throw new \InvalidArgumentException('Wrong message type');
}

$className = 'Magento\\Framework\\Message\\' . ucfirst($type);

$message = $this->objectManager->create($className, $text === null ? [] : ['text' => $text]);
if (!$message instanceof MessageInterface) {
throw new \InvalidArgumentException(
$className . ' doesn\'t implement \Magento\Framework\Message\MessageInterface'
);
}

return $message;
}
}