1<?php 2namespace TYPO3\CMS\Extbase\Error; 3 4/* 5 * This file is part of the TYPO3 CMS project. 6 * 7 * It is free software; you can redistribute it and/or modify it under 8 * the terms of the GNU General Public License, either version 2 9 * of the License, or any later version. 10 * 11 * For the full copyright and license information, please read the 12 * LICENSE.txt file that was distributed with this source code. 13 * 14 * The TYPO3 project - inspiring people to share! 15 */ 16 17/** 18 * An object representation of a generic message. Usually, you will use Error, Warning or Notice instead of this one. 19 */ 20class Message 21{ 22 /** 23 * The default (english) error message 24 * 25 * @var string 26 */ 27 protected $message = 'Unknown message'; 28 29 /** 30 * The error code 31 * 32 * @var string 33 */ 34 protected $code; 35 36 /** 37 * The message arguments. Will be replaced in the message body. 38 * 39 * @var array 40 */ 41 protected $arguments = []; 42 43 /** 44 * An optional title for the message (used eg. in flashMessages). 45 * 46 * @var string 47 */ 48 protected $title = ''; 49 50 /** 51 * Constructs this error 52 * 53 * @param string $message An english error message which is used if no other error message can be resolved 54 * @param int $code A unique error code 55 * @param array $arguments Array of arguments to be replaced in message 56 * @param string $title optional title for the message 57 */ 58 public function __construct($message, $code, array $arguments = [], $title = '') 59 { 60 $this->message = $message; 61 $this->code = $code; 62 $this->arguments = $arguments; 63 $this->title = $title; 64 } 65 66 /** 67 * Returns the error message 68 * 69 * @return string The error message 70 */ 71 public function getMessage() 72 { 73 return $this->message; 74 } 75 76 /** 77 * Returns the error code 78 * 79 * @return string The error code 80 */ 81 public function getCode() 82 { 83 return $this->code; 84 } 85 86 /** 87 * Get arguments 88 * 89 * @return array 90 */ 91 public function getArguments() 92 { 93 return $this->arguments; 94 } 95 96 /** 97 * Get title 98 * 99 * @return string 100 */ 101 public function getTitle() 102 { 103 return $this->title; 104 } 105 106 /** 107 * Return the rendered message 108 * 109 * @return string 110 */ 111 public function render() 112 { 113 if (!empty($this->arguments)) { 114 return vsprintf($this->message, $this->arguments); 115 } 116 return $this->message; 117 } 118 119 /** 120 * Converts this error into a string 121 * 122 * @return string 123 */ 124 public function __toString() 125 { 126 return $this->render(); 127 } 128} 129