xref: /plugin/struct/meta/StructException.php (revision 2d502a6a3ef5b3317084d13a109bfc7d32e0ddd6)
15511bd5bSAndreas Gohr<?php
25511bd5bSAndreas Gohr
3ba766201SAndreas Gohrnamespace dokuwiki\plugin\struct\meta;
45511bd5bSAndreas Gohr
55511bd5bSAndreas Gohr/**
65511bd5bSAndreas Gohr * Class StructException
75511bd5bSAndreas Gohr *
85511bd5bSAndreas Gohr * A translatable exception
95511bd5bSAndreas Gohr *
10ba766201SAndreas Gohr * @package dokuwiki\plugin\struct\meta
115511bd5bSAndreas Gohr */
12d6d97f60SAnna Dabrowskaclass StructException extends \RuntimeException
13d6d97f60SAnna Dabrowska{
1417560ecbSAndreas Gohr    protected $trans_prefix = 'Exception ';
1517560ecbSAndreas Gohr
165511bd5bSAndreas Gohr    /**
175511bd5bSAndreas Gohr     * StructException constructor.
185511bd5bSAndreas Gohr     *
195511bd5bSAndreas Gohr     * @param string $message
205511bd5bSAndreas Gohr     * @param ...string $vars
215511bd5bSAndreas Gohr     */
22d6d97f60SAnna Dabrowska    public function __construct($message)
23d6d97f60SAnna Dabrowska    {
24ba766201SAndreas Gohr        /** @var \helper_plugin_struct $plugin */
25ba766201SAndreas Gohr        $plugin = plugin_load('helper', 'struct');
2617560ecbSAndreas Gohr        $trans = $plugin->getLang($this->trans_prefix . $message);
275511bd5bSAndreas Gohr        if (!$trans) $trans = $message;
285511bd5bSAndreas Gohr
295511bd5bSAndreas Gohr        $args = func_get_args();
305511bd5bSAndreas Gohr        array_shift($args);
315511bd5bSAndreas Gohr
325511bd5bSAndreas Gohr        $trans = vsprintf($trans, $args);
33*2d502a6aSAndreas Gohr        $trans .= $this->getVersionPostfix();
345511bd5bSAndreas Gohr
355511bd5bSAndreas Gohr        parent::__construct($trans, -1, null);
365511bd5bSAndreas Gohr    }
37*2d502a6aSAndreas Gohr
38*2d502a6aSAndreas Gohr    /**
39*2d502a6aSAndreas Gohr     * Get the plugin version to add as postfix to the exception message
40*2d502a6aSAndreas Gohr     * @return string
41*2d502a6aSAndreas Gohr     */
42*2d502a6aSAndreas Gohr    protected function getVersionPostfix()
43*2d502a6aSAndreas Gohr    {
44*2d502a6aSAndreas Gohr        /** @var \helper_plugin_struct $plugin */
45*2d502a6aSAndreas Gohr        $plugin = plugin_load('helper', 'struct');
46*2d502a6aSAndreas Gohr        $info = $plugin->getInfo();
47*2d502a6aSAndreas Gohr        return ' [struct ' . $info['date'] . ']';
48*2d502a6aSAndreas Gohr    }
495511bd5bSAndreas Gohr}
50