FusionDirectory
class_SimplePluginHookError.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4  Copyright (C) 2019-2020 FusionDirectory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
25 {
26  protected $hookType;
27 
28  public function __construct ($origin, string $type, string $output = '', int $code = 0, Throwable $previous = NULL)
29  {
30  $this->hookType = $type;
31 
32  parent::__construct($origin, nl2br('<samp>'.htmlescape($output).'</samp>'), $code, $previous);
33  }
34 
35  public function toArray (): array
36  {
37  $array = parent::toArray();
38 
39  $array['hookType'] = $this->hookType;
40  $array['hookCode'] = $this->getCode();
41 
42  return $array;
43  }
44 
45  public function computeMsgDialogParameters (): array
46  {
47  $html = '';
48 
49  if (isset($this->object->dn)) {
50  $html .= htmlescape($this->object->dn.' > ');
51  }
52 
53  if (isset($this->tab) && isset($this->tab->parent->by_name[get_class($this->tab)])) {
54  $html .= htmlescape($this->tab->parent->by_name[get_class($this->tab)].' > ');
55  }
56 
57  if (isset($this->attribute)) {
58  $label = $this->attribute->getLabel();
59  if (empty($label)) {
60  $html .= '<i>'.htmlescape($this->attribute->getLdapName()).'</i>';
61  } else {
62  $html .= htmlescape($label);
63  }
64  $html .= htmlescape(' > ');
65  }
66  $html .= htmlescape($this->hookType);
67 
68  $html .= '<br/><br/>'."\n";
69 
70  $html .= htmlescape(_('Trigger returned an error!'));
71 
72  $html .= '<br/><br/>'."\n";
73  $html .= htmlescape(sprintf(_('Exit code: %d'), $this->getCode())).'<br/>'."\n";
74  if (!empty($this->htmlMessage)) {
75  $html .= 'Result: '.$this->htmlMessage."\n";
76  }
77 
78  return [_('Error'), $html, ERROR_DIALOG, FusionDirectoryError::formatTrace($this)];
79  }
80 }
htmlescape(string $str)
Escape string for HTML output.
Definition: php_setup.inc:32
Error returned by any method of SimplePlugin.
Error returned by a hook called from SimplePlugin.