Source Code: SmartFactory/MessageManager.php

  1: <?php
  2: /**
  3:  * This file contains the implementation of the interface IMessageManager
  4:  * in the class MessageManager for working with messages - errors, warnings etc.
  5:  *
  6:  * @package System
  7:  *
  8:  * @author Oleg Schildt
  9:  */
 10: 
 11: namespace SmartFactory;
 12: 
 13: use \SmartFactory\Interfaces\IMessageManager;
 14: 
 15: /**
 16:  * Class for working with messages - errors, warnings etc.
 17:  *
 18:  * @author Oleg Schildt
 19:  */
 20: class MessageManager implements IMessageManager
 21: {
 22:     /**
 23:      * Internal variable for storing the messages.
 24:      *
 25:      * @var array
 26:      *
 27:      * @author Oleg Schildt
 28:      */
 29:     protected array $messages = [];
 30: 
 31:     /**
 32:      * Internal variable for storing the state whether technical details, programmer warnings and debug information are also sent to the client.
 33:      *
 34:      * @var bool
 35:      *
 36:      * @author Oleg Schildt
 37:      */
 38:     protected bool $debug_mode = false;
 39: 
 40:     /**
 41:      * Internal variable for storing the flag that defines whether for each debug output the source file and
 42:      * line number are written from where it is called.
 43:      *
 44:      * @var bool
 45:      *
 46:      * @author Oleg Schildt
 47:      */
 48:     protected bool $write_source_file_and_line_by_debug = false;
 49: 
 50:     /**
 51:      * Initializes the message manager.
 52:      *
 53:      * @param array $parameters
 54:      * Settings for message management as an associative array in the form key => value:
 55:      *
 56:      * - $parameters["debug_mode"] - if set to True, the technical details, programmer warnings and debug information are also sent to the client. Use it only during debugging!
 57:      *
 58:      * - $parameters["write_source_file_and_line_by_debug"] - the flag that defines whether for each debug output the source file and
 59:      * line number are written from where it is called.
 60:      *
 61:      * @return void
 62:      *
 63:      * @throws \Exception
 64:      * It might throw an exception in the case of any errors.
 65:      *
 66:      * @author Oleg Schildt
 67:      */
 68:     public function init(array $parameters): void
 69:     {
 70:         $this->debug_mode = !empty($parameters["debug_mode"]);
 71: 
 72:         $this->write_source_file_and_line_by_debug = !empty($parameters["write_source_file_and_line_by_debug"]);
 73:     } // init
 74: 
 75:     /**
 76:      * Stores the error to be reported.
 77:      *
 78:      * @param string $message
 79:      * The error message to be reported.
 80:      *
 81:      * @param array $details
 82:      * The details might be useful if the message translations are provided on the client, not
 83:      * on the server, and the message should contain some details that may vary from case to case.
 84:      * In that case, the servers return the message id instead of final text and the details, the client
 85:      * uses the message id, gets the final translated text and substitutes the parameters through the details.
 86:      *
 87:      * @param string $related_element
 88:      * The error element associated with the error.
 89:      *
 90:      * @param string $code
 91:      * The error code to be reported.
 92:      *
 93:      * @param string $technical_info
 94:      * The technical information for the error. Displaying
 95:      * of this part might be controlled over an option
 96:      * "debug_mode".
 97:      *
 98:      * @param string $file
 99:      * The source file where the error occurred. Per default, the file where the adding error called.
100:      *
101:      * @param string $line
102:      * The source file line where the error occurred. Per default, the file line where the adding error called.
103:      *
104:      * @return void
105:      *
106:      * @see MessageManager::addErrorFromSmartException()
107:      * @see MessageManager::addWarning()
108:      * @see MessageManager::addProgWarning()
109:      * @see MessageManager::addDebugMessage()
110:      * @see MessageManager::addInfoMessage()
111:      * @see MessageManager::addBubbleMessage()
112:      * @see MessageManager::getErrors()
113:      * @see MessageManager::hasErrors()
114:      * @see MessageManager::clearErrors()
115:      *
116:      * @author Oleg Schildt
117:      */
118:     public function addError(string $message, array $details = [], string $related_element = "", string $code = "", string $technical_info = "", string $file = "", string $line = ""): void
119:     {
120:         if (empty($message)) {
121:             return;
122:         }
123: 
124:         if (empty($file) || empty($line)) {
125:             $backfiles = debug_backtrace();
126: 
127:             if (empty($file)) {
128:                 $file = empty($backfiles[0]['file']) ? "" : $backfiles[0]['file'];
129:             }
130: 
131:             if (empty($line)) {
132:                 $line = empty($backfiles[0]['line']) ? "" : $backfiles[0]['line'];
133:             }
134:         }
135:         
136:         if (!$this->write_source_file_and_line_by_debug) {
137:             $file = "";
138:             $line = "";
139:         }
140: 
141:         if (!$this->debug_mode) {
142:             $technical_info = "";
143:             $file = "";
144:             $line = "";
145:         }
146: 
147:         $this->messages["errors"][md5($message . implode("#", $details))] = [
148:             "message" => $message,
149:             "details" => $details,
150:             "related_element" => $related_element,
151:             "code" => $code,
152:             "technical_info" => $technical_info,
153:             "file" => $file,
154:             "line" => $line
155:         ];
156:     } // addError
157: 
158:     /**
159:      * Stores the error to be reported.
160:      *
161:      * @param SmartException|SmartExceptionCollection $smart_exception
162:      * The exception object of collection of exceptions.
163:      *
164:      * @return void
165:      *
166:      * @see MessageManager::addError()
167:      * @see MessageManager::addWarning()
168:      * @see MessageManager::addProgWarning()
169:      * @see MessageManager::addDebugMessage()
170:      * @see MessageManager::addInfoMessage()
171:      * @see MessageManager::addBubbleMessage()
172:      * @see MessageManager::getErrors()
173:      * @see MessageManager::hasErrors()
174:      * @see MessageManager::clearErrors()
175:      *
176:      * @author Oleg Schildt
177:      */
178:     public function addErrorFromSmartException(SmartException|SmartExceptionCollection $smart_exception): void
179:     {
180:         if ($smart_exception instanceof SmartException) {
181:             $this->addError($smart_exception->getMessage(), $smart_exception->getErrorDetails(), $smart_exception->getErrorElement(), $smart_exception->getErrorCode(), trim($smart_exception->getTechnicalInfo()), $smart_exception->getFile(), $smart_exception->getLine());
182:         } elseif ($smart_exception instanceof SmartExceptionCollection) {
183:             $errors = $smart_exception->getErrors();
184:             foreach ($errors as $error) {
185:                 $this->addError($error["message"], $error["details"], $error["related_element"], $error["code"], $error["technical_info"], $error["file"], $error["line"]);
186:             }
187:         } else {
188:             $this->addError($smart_exception->getMessage(), [], "", $smart_exception->getCode());
189:         }
190:     }
191: 
192:     /**
193:      * Clears the stored error messages.
194:      *
195:      * @return void
196:      *
197:      * @see MessageManager::clearWarnings()
198:      * @see MessageManager::clearProgWarnings()
199:      * @see MessageManager::clearDebugMessages()
200:      * @see MessageManager::clearInfoMessages()
201:      * @see MessageManager::clearBubbleMessages()
202:      * @see MessageManager::clearAll()
203:      * @see MessageManager::addError()
204:      *
205:      * @author Oleg Schildt
206:      */
207:     public function clearErrors(): void
208:     {
209:         unset($this->messages["errors"]);
210:     } // clearErrors
211: 
212:     /**
213:      * Checks whether a stored error message exist.
214:      *
215:      * @return bool
216:      * Returns true if the stored error message exists, otherwise false.
217:      *
218:      * @see MessageManager::hasWarnings()
219:      * @see MessageManager::hasProgWarnings()
220:      * @see MessageManager::hasDebugMessages()
221:      * @see MessageManager::hasInfoMessages()
222:      * @see MessageManager::hasBubbleMessages()
223:      * @see MessageManager::getErrors()
224:      * @see MessageManager::addError()
225:      *
226:      * @author Oleg Schildt
227:      */
228:     public function hasErrors(): bool
229:     {
230:         return (isset($this->messages["errors"]) && count($this->messages["errors"]) > 0);
231:     } // hasErrors
232: 
233:     /**
234:      * Returns the array of errors if any have been stored.
235:      *
236:      * When the messages are requested, it is assumed they will be displayed. Thus,
237:      * the message array is cleared to avoid displaying of the same messages twice.
238:      *
239:      * @return array
240:      * Returns the array of errors if any have been stored.
241:      *
242:      * @see MessageManager::getWarnings()
243:      * @see MessageManager::getProgWarnings()
244:      * @see MessageManager::getDebugMessages()
245:      * @see MessageManager::getInfoMessages()
246:      * @see MessageManager::getBubbleMessages()
247:      * @see MessageManager::hasErrors()
248:      * @see MessageManager::addError()
249:      *
250:      * @author Oleg Schildt
251:      */
252:     public function getErrors(): array
253:     {
254:         if (!$this->hasErrors()) {
255:             return [];
256:         }
257: 
258:         return $this->getMessages($this->messages["errors"]);
259:     } // getErrors
260: 
261:     /**
262:      * Stores the warning to be reported.
263:      *
264:      * @param string $message
265:      * The warning message to be reported.
266:      *
267:      * @param array $details
268:      * The details might be useful if the message translations are provided on the client, not
269:      * on the server, and the message should contain some details that may vary from case to case.
270:      * In that case, the servers return the message id instead of final text and the details, the client
271:      * uses the message id, gets the final translated text and substitutes the parameters through the details.
272:      *
273:      * @param string $related_element
274:      * The error element associated with the warning.
275:      *
276:      * @return void
277:      *
278:      * @see MessageManager::addError()
279:      * @see MessageManager::addProgWarning()
280:      * @see MessageManager::addDebugMessage()
281:      * @see MessageManager::addInfoMessage()
282:      * @see MessageManager::addBubbleMessage()
283:      * @see MessageManager::getWarnings()
284:      * @see MessageManager::hasWarnings()
285:      * @see MessageManager::clearWarnings()
286:      *
287:      * @author Oleg Schildt
288:      */
289:     public function addWarning(string $message, array $details = [], string $related_element = ""): void
290:     {
291:         if (empty($message)) {
292:             return;
293:         }
294: 
295:         $this->messages["warnings"][$message . implode("#", $details)] = [
296:             "message" => $message,
297:             "details" => $details,
298:             "related_element" => $related_element
299:         ];
300:     } // addWarning
301: 
302:     /**
303:      * Clears the stored warning messages.
304:      *
305:      * @return void
306:      *
307:      * @see MessageManager::clearErrors()
308:      * @see MessageManager::clearProgWarnings()
309:      * @see MessageManager::clearDebugMessages()
310:      * @see MessageManager::clearInfoMessages()
311:      * @see MessageManager::clearBubbleMessages()
312:      * @see MessageManager::clearAll()
313:      * @see MessageManager::addWarning()
314:      *
315:      * @author Oleg Schildt
316:      */
317:     public function clearWarnings(): void
318:     {
319:         unset($this->messages["warnings"]);
320:     } // clearWarnings
321: 
322:     /**
323:      * Checks whether a stored error warning exist.
324:      *
325:      * @return bool
326:      * Returns true if the stored warning message exists, otherwise false.
327:      *
328:      * @see MessageManager::hasErrors()
329:      * @see MessageManager::hasProgWarnings()
330:      * @see MessageManager::hasDebugMessages()
331:      * @see MessageManager::hasInfoMessages()
332:      * @see MessageManager::hasBubbleMessages()
333:      * @see MessageManager::getWarnings()
334:      * @see MessageManager::addWarning()
335:      *
336:      * @author Oleg Schildt
337:      */
338:     public function hasWarnings(): bool
339:     {
340:         return (isset($this->messages["warnings"]) && count($this->messages["warnings"]) > 0);
341:     } // hasWarnings
342: 
343:     /**
344:      * Returns the array of warnings if any have been stored.
345:      *
346:      * When the messages are requested, it is assumed they will be displayed. Thus,
347:      * the message array is cleared to avoid displaying of the same messages twice.
348:      *
349:      * @return array
350:      * Returns the array of warnings if any have been stored.
351:      *
352:      * @see MessageManager::getErrors()
353:      * @see MessageManager::getProgWarnings()
354:      * @see MessageManager::getDebugMessages()
355:      * @see MessageManager::getInfoMessages()
356:      * @see MessageManager::getBubbleMessages()
357:      * @see MessageManager::hasWarnings()
358:      * @see MessageManager::addWarning()
359:      *
360:      * @author Oleg Schildt
361:      */
362:     public function getWarnings(): array
363:     {
364:         if (!$this->hasWarnings()) {
365:             return [];
366:         }
367: 
368:         return $this->getMessages($this->messages["warnings"]);
369:     } // getWarnings
370: 
371:     /**
372:      * Stores the programming warning to be reported.
373:      *
374:      * Programming warnings are shown only if the option
375:      * "show programming warning" is active.
376:      *
377:      * @param string $message
378:      * The programming warning message to be reported.
379:      *
380:      * @param string $file
381:      * The source file where the error occurred. Per default, the file where the adding error called.
382:      *
383:      * @param string $line
384:      * The source file line where the error occurred. Per default, the file line where the adding error called.
385:      *
386:      * @return void
387:      *
388:      * @see MessageManager::addError()
389:      * @see MessageManager::addWarning()
390:      * @see MessageManager::addDebugMessage()
391:      * @see MessageManager::addInfoMessage()
392:      * @see MessageManager::addBubbleMessage()
393:      * @see MessageManager::getProgWarnings()
394:      * @see MessageManager::hasProgWarnings()
395:      * @see MessageManager::clearProgWarnings()
396:      *
397:      * @author Oleg Schildt
398:      */
399:     public function addProgWarning(string $message, string $file = "", string $line = ""): void
400:     {
401:         if (!$this->debug_mode) {
402:             return;
403:         }
404: 
405:         if (empty($message)) {
406:             return;
407:         }
408: 
409:         if (empty($file) || empty($line)) {
410:             $backfiles = debug_backtrace();
411: 
412:             if (empty($file)) {
413:                 $file = empty($backfiles[0]['file']) ? "" : $backfiles[0]['file'];
414:             }
415: 
416:             if (empty($line)) {
417:                 $line = empty($backfiles[0]['line']) ? "" : $backfiles[0]['line'];
418:             }
419:         }
420: 
421:         $this->messages["prog_warnings"][$message] = [
422:             "message" => $message,
423:             "file" => $file,
424:             "line" => $line
425:         ];
426:     } // addProgWarning
427: 
428:     /**
429:      * Clears the stored programming warning messages.
430:      *
431:      * @return void
432:      *
433:      * @see MessageManager::clearErrors()
434:      * @see MessageManager::clearWarnings()
435:      * @see MessageManager::clearDebugMessages()
436:      * @see MessageManager::clearInfoMessages()
437:      * @see MessageManager::clearBubbleMessages()
438:      * @see MessageManager::clearAll()
439:      * @see MessageManager::addProgWarning()
440:      *
441:      * @author Oleg Schildt
442:      */
443:     public function clearProgWarnings(): void
444:     {
445:         unset($this->messages["prog_warnings"]);
446:     } // clearProgWarnings
447: 
448:     /**
449:      * Checks whether a stored programming warning exist.
450:      *
451:      * @return bool
452:      * Returns true if the stored programming warning message exists, otherwise false.
453:      *
454:      * @see MessageManager::hasErrors()
455:      * @see MessageManager::hasWarnings()
456:      * @see MessageManager::hasDebugMessages()
457:      * @see MessageManager::hasInfoMessages()
458:      * @see MessageManager::hasBubbleMessages()
459:      * @see MessageManager::getProgWarnings()
460:      * @see MessageManager::addProgWarning()
461:      *
462:      * @author Oleg Schildt
463:      */
464:     public function hasProgWarnings(): bool
465:     {
466:         return (isset($this->messages["prog_warnings"]) && count($this->messages["prog_warnings"]) > 0);
467:     } // hasProgWarnings
468: 
469:     /**
470:      * Returns the array of programming warnings if any have been stored.
471:      *
472:      * When the messages are requested, it is assumed they will be displayed. Thus,
473:      * the message array is cleared to avoid displaying of the same messages twice.
474:      *
475:      * @return array
476:      * Returns the array of programming warnings if any have been stored.
477:      *
478:      * @see MessageManager::getErrors()
479:      * @see MessageManager::getWarnings()
480:      * @see MessageManager::getDebugMessages()
481:      * @see MessageManager::getInfoMessages()
482:      * @see MessageManager::getBubbleMessages()
483:      * @see MessageManager::hasProgWarnings()
484:      * @see MessageManager::addProgWarning()
485:      *
486:      * @author Oleg Schildt
487:      */
488:     public function getProgWarnings(): array
489:     {
490:         if (!$this->hasProgWarnings()) {
491:             return [];
492:         }
493: 
494:         return $this->getMessages($this->messages["prog_warnings"]);
495:     } // getProgWarnings
496: 
497:     /**
498:      * Stores the debugging message to be reported.
499:      *
500:      * Displaying of the debugging messages might be
501:      * implemented to simplify the debugging process,
502:      * e.g. to the browser console or in a lightbox.
503:      *
504:      * @param string $message
505:      * The debugging message to be reported.
506:      *
507:      * @param string $file
508:      * The source file where the debug output occurred. Per default, the file where the debug output called.
509:      *
510:      * @param string $line
511:      * The source file line where the debug output occurred. Per default, the file line where the debug output called.
512:      *
513:      * @return void
514:      *
515:      * @see MessageManager::addError()
516:      * @see MessageManager::addWarning()
517:      * @see MessageManager::addProgWarning()
518:      * @see MessageManager::addInfoMessage()
519:      * @see MessageManager::addBubbleMessage()
520:      * @see MessageManager::getDebugMessages()
521:      * @see MessageManager::hasDebugMessages()
522:      * @see MessageManager::clearDebugMessages()
523:      *
524:      * @author Oleg Schildt
525:      */
526:     public function addDebugMessage(string $message, string $file = "", string $line = ""): void
527:     {
528:         if (!$this->debug_mode) {
529:             return;
530:         }
531: 
532:         if (empty($message)) {
533:             return;
534:         }
535: 
536: 
537:         if (empty($file) || empty($line)) {
538:             $backfiles = debug_backtrace();
539: 
540:             if (empty($file)) {
541:                 $file = empty($backfiles[0]['file']) ? "" : $backfiles[0]['file'];
542:             }
543: 
544:             if (empty($line)) {
545:                 $line = empty($backfiles[0]['line']) ? "" : $backfiles[0]['line'];
546:             }
547:         }
548: 
549:         if (!$this->write_source_file_and_line_by_debug) {
550:             $file = "";
551:             $line = "";
552:         }
553: 
554:         $this->messages["debug_messages"][$message] = [
555:             "message" => $message,
556:             "file" => $file,
557:             "line" => $line
558:         ];
559:     } // addDebugMessage
560: 
561:     /**
562:      * Clears the stored debugging messages.
563:      *
564:      * @return void
565:      *
566:      * @see MessageManager::clearErrors()
567:      * @see MessageManager::clearWarnings()
568:      * @see MessageManager::clearProgWarnings()
569:      * @see MessageManager::clearInfoMessages()
570:      * @see MessageManager::clearBubbleMessages()
571:      * @see MessageManager::clearAll()
572:      * @see MessageManager::addDebugMessage()
573:      *
574:      * @author Oleg Schildt
575:      */
576:     public function clearDebugMessages(): void
577:     {
578:         unset($this->messages["debug_messages"]);
579:     } // clearDebugMessages
580: 
581:     /**
582:      * Checks whether a stored debugging message exist.
583:      *
584:      * @return bool
585:      * Returns true if the stored debugging message exists, otherwise false.
586:      *
587:      * @see MessageManager::hasErrors()
588:      * @see MessageManager::hasWarnings()
589:      * @see MessageManager::hasProgWarnings()
590:      * @see MessageManager::hasInfoMessages()
591:      * @see MessageManager::hasBubbleMessages()
592:      * @see MessageManager::getDebugMessages()
593:      * @see MessageManager::addDebugMessage()
594:      *
595:      * @author Oleg Schildt
596:      */
597:     public function hasDebugMessages(): bool
598:     {
599:         return (isset($this->messages["debug_messages"]) && count($this->messages["debug_messages"]) > 0);
600:     } // hasDebugMessages
601: 
602:     /**
603:      * Returns the array of debugging messages if any have been stored.
604:      *
605:      * When the messages are requested, it is assumed they will be displayed. Thus,
606:      * the message array is cleared to avoid displaying of the same messages twice.
607:      *
608:      * @return array
609:      * Returns the array of debugging messages if any have been stored.
610:      *
611:      * @see MessageManager::getErrors()
612:      * @see MessageManager::getWarnings()
613:      * @see MessageManager::getProgWarnings()
614:      * @see MessageManager::getInfoMessages()
615:      * @see MessageManager::getBubbleMessages()
616:      * @see MessageManager::hasDebugMessages()
617:      * @see MessageManager::addDebugMessage()
618:      *
619:      * @author Oleg Schildt
620:      */
621:     public function getDebugMessages(): array
622:     {
623:         if (!$this->hasDebugMessages()) {
624:             return [];
625:         }
626: 
627:         return $this->getMessages($this->messages["debug_messages"]);
628:     } // getDebugMessages
629: 
630:     /**
631:      * Stores the information message to be reported.
632:      *
633:      * @param string $message
634:      * The information message to be reported.
635:      *
636:      * @param array $details
637:      * The details might be useful if the message translations are provided on the client, not
638:      * on the server, and the message should contain some details that may vary from case to case.
639:      * In that case, the servers return the message id instead of final text and the details, the client
640:      * uses the message id, gets the final translated text and substitutes the parameters through the details.
641:      *
642:      * @param bool $autoclose
643:      * The flag that controls whether the message box should be closed automatically after a time.
644:      *
645:      * @return void
646:      *
647:      * @see MessageManager::addError()
648:      * @see MessageManager::addWarning()
649:      * @see MessageManager::addProgWarning()
650:      * @see MessageManager::addDebugMessage()
651:      * @see MessageManager::addBubbleMessage()
652:      * @see MessageManager::getInfoMessages()
653:      * @see MessageManager::hasInfoMessages()
654:      * @see MessageManager::clearInfoMessages()
655:      *
656:      * @author Oleg Schildt
657:      */
658:     public function addInfoMessage(string $message, array $details = [], bool $autoclose = false): void
659:     {
660:         if (empty($message)) {
661:             return;
662:         }
663: 
664:         $this->messages["info_messages"][$message . implode("#", $details)] = [
665:             "message" => $message,
666:             "details" => $details,
667:             "autoclose" => $autoclose
668:         ];
669:     } // addInfoMessage
670: 
671:     /**
672:      * Clears the stored information messages.
673:      *
674:      * @return void
675:      *
676:      * @see MessageManager::clearErrors()
677:      * @see MessageManager::clearWarnings()
678:      * @see MessageManager::clearProgWarnings()
679:      * @see MessageManager::clearDebugMessages()
680:      * @see MessageManager::clearBubbleMessages()
681:      * @see MessageManager::clearAll()
682:      * @see MessageManager::addInfoMessage()
683:      *
684:      * @author Oleg Schildt
685:      */
686:     public function clearInfoMessages(): void
687:     {
688:         unset($this->messages["info_messages"]);
689:     } // clearInfoMessages
690: 
691:     /**
692:      * Checks whether an information message exist.
693:      *
694:      * @return bool
695:      * Returns true if the information message exists, otherwise false.
696:      *
697:      * @see MessageManager::hasErrors()
698:      * @see MessageManager::hasWarnings()
699:      * @see MessageManager::hasProgWarnings()
700:      * @see MessageManager::hasDebugMessages()
701:      * @see MessageManager::hasBubbleMessages()
702:      * @see MessageManager::getInfoMessages()
703:      * @see MessageManager::addInfoMessage()
704:      *
705:      * @author Oleg Schildt
706:      */
707:     public function hasInfoMessages(): bool
708:     {
709:         return (isset($this->messages["info_messages"]) && count($this->messages["info_messages"]) > 0);
710:     } // hasInfoMessages
711: 
712:     /**
713:      * Returns the array of information messages if any have been stored.
714:      *
715:      * When the messages are requested, it is assumed they will be displayed. Thus,
716:      * the message array is cleared to avoid displaying of the same messages twice.
717:      *
718:      * @return array
719:      * Returns the array of information messages if any have been stored.
720:      *
721:      * @see MessageManager::getErrors()
722:      * @see MessageManager::getWarnings()
723:      * @see MessageManager::getProgWarnings()
724:      * @see MessageManager::getDebugMessages()
725:      * @see MessageManager::getBubbleMessages()
726:      * @see MessageManager::hasInfoMessages()
727:      * @see MessageManager::addInfoMessage()
728:      *
729:      * @author Oleg Schildt
730:      */
731:     public function getInfoMessages(): array
732:     {
733:         if (!$this->hasInfoMessages()) {
734:             return [];
735:         }
736: 
737:         return $this->getMessages($this->messages["info_messages"]);
738:     } // getInfoMessages
739: 
740:     /**
741:      * Stores the information message to be reported.
742:      *
743:      * @param string $message
744:      * The information message to be reported.
745:      *
746:      * @param array $details
747:      * The details might be useful if the message translations are provided on the client, not
748:      * on the server, and the message should contain some details that may vary from case to case.
749:      * In that case, the servers return the message id instead of final text and the details, the client
750:      * uses the message id, gets the final translated text and substitutes the parameters through the details.
751:      *
752:      * @param bool $autoclose
753:      * The flag that controls whether the message box should be closed
754:      * automatically after a time.
755:      *
756:      * @return void
757:      *
758:      * @see MessageManager::addError()
759:      * @see MessageManager::addWarning()
760:      * @see MessageManager::addProgWarning()
761:      * @see MessageManager::addDebugMessage()
762:      * @see MessageManager::addInfoMessage()
763:      * @see MessageManager::getBubbleMessages()
764:      * @see MessageManager::hasBubbleMessages()
765:      * @see MessageManager::clearBubbleMessages()
766:      *
767:      * @author Oleg Schildt
768:      */
769:     public function addBubbleMessage(string $message, array $details = [], bool $autoclose = true): void
770:     {
771:         if (empty($message)) {
772:             return;
773:         }
774: 
775:         $this->messages["bubble_messages"][$message] = [
776:             "message" => $message,
777:             "details" => $details,
778:             "autoclose" => $autoclose
779:         ];
780:     } // addBubbleMessage
781: 
782:     /**
783:      * Clears the stored information messages.
784:      *
785:      * @return void
786:      *
787:      * @see MessageManager::clearErrors()
788:      * @see MessageManager::clearWarnings()
789:      * @see MessageManager::clearProgWarnings()
790:      * @see MessageManager::clearDebugMessages()
791:      * @see MessageManager::clearInfoMessages()
792:      * @see MessageManager::clearAll()
793:      * @see MessageManager::addBubbleMessage()
794:      *
795:      * @author Oleg Schildt
796:      */
797:     public function clearBubbleMessages(): void
798:     {
799:         unset($this->messages["bubble_messages"]);
800:     } // clearBubbleMessages
801: 
802:     /**
803:      * Checks whether an information message exist.
804:      *
805:      * @return bool
806:      * Returns true if the information message exists, otherwise false.
807:      *
808:      * @see MessageManager::hasErrors()
809:      * @see MessageManager::hasWarnings()
810:      * @see MessageManager::hasProgWarnings()
811:      * @see MessageManager::hasDebugMessages()
812:      * @see MessageManager::hasInfoMessages()
813:      * @see MessageManager::getBubbleMessages()
814:      * @see MessageManager::addBubbleMessage()
815:      *
816:      * @author Oleg Schildt
817:      */
818:     public function hasBubbleMessages(): bool
819:     {
820:         return (isset($this->messages["bubble_messages"]) && count($this->messages["bubble_messages"]) > 0);
821:     } // hasBubbleMessages
822: 
823:     /**
824:      * Returns the array of information messages if any have been stored.
825:      *
826:      * When the messages are requested, it is assumed they will be displayed. Thus,
827:      * the message array is cleared to avoid displaying of the same messages twice.
828:      *
829:      * @return array
830:      * Returns the array of information messages if any have been stored.
831:      *
832:      * @see MessageManager::getErrors()
833:      * @see MessageManager::getWarnings()
834:      * @see MessageManager::getProgWarnings()
835:      * @see MessageManager::getDebugMessages()
836:      * @see MessageManager::getInfoMessages()
837:      * @see MessageManager::hasBubbleMessages()
838:      * @see MessageManager::addBubbleMessage()
839:      *
840:      * @author Oleg Schildt
841:      */
842:     public function getBubbleMessages(): array
843:     {
844:         if (!$this->hasBubbleMessages()) {
845:             return [];
846:         }
847: 
848:         return $this->getMessages($this->messages["bubble_messages"]);
849:     } // getBubbleMessages
850: 
851:     /**
852:      * Clears all stored messages and active elements.
853:      *
854:      * @return void
855:      *
856:      * @see MessageManager::clearErrors()
857:      * @see MessageManager::clearWarnings()
858:      * @see MessageManager::clearProgWarnings()
859:      * @see MessageManager::clearDebugMessages()
860:      * @see MessageManager::clearInfoMessages()
861:      * @see MessageManager::clearBubbleMessages()
862:      *
863:      * @author Oleg Schildt
864:      */
865:     public function clearAll(): void
866:     {
867:         $this->clearErrors();
868:         $this->clearWarnings();
869:         $this->clearProgWarnings();
870:         $this->clearDebugMessages();
871:         $this->clearInfoMessages();
872:         $this->clearBubbleMessages();
873:     } // clearAll
874: 
875:     /**
876:      * This auxiliary function returns the messages of the desired type.
877:      *
878:      * @param array $messages
879:      * The messages to be retrieved.
880:      *
881:      * @return array
882:      * Returns the array of messages.
883:      *
884:      * @author Oleg Schildt
885:      */
886:     protected function getMessages(array $messages): array
887:     {
888:         return array_values($messages);
889:     } // getMessages
890: } // MessageManager