xref: /plugin/struct/meta/StructException.php (revision 5511bd5b07a4ce4f72c790c57a0579633941affd)
1*5511bd5bSAndreas Gohr<?php
2*5511bd5bSAndreas Gohr
3*5511bd5bSAndreas Gohrnamespace plugin\struct\meta;
4*5511bd5bSAndreas Gohr
5*5511bd5bSAndreas Gohruse Exception;
6*5511bd5bSAndreas Gohr
7*5511bd5bSAndreas Gohr/**
8*5511bd5bSAndreas Gohr * Class StructException
9*5511bd5bSAndreas Gohr *
10*5511bd5bSAndreas Gohr * A translatable exception
11*5511bd5bSAndreas Gohr *
12*5511bd5bSAndreas Gohr * @package plugin\struct\meta
13*5511bd5bSAndreas Gohr */
14*5511bd5bSAndreas Gohrclass StructException extends \RuntimeException {
15*5511bd5bSAndreas Gohr
16*5511bd5bSAndreas Gohr    /**
17*5511bd5bSAndreas Gohr     * StructException constructor.
18*5511bd5bSAndreas Gohr     *
19*5511bd5bSAndreas Gohr     * @param string $message
20*5511bd5bSAndreas Gohr     * @param ...string $vars
21*5511bd5bSAndreas Gohr     */
22*5511bd5bSAndreas Gohr    public function __construct($message) {
23*5511bd5bSAndreas Gohr        /** @var \action_plugin_struct_autoloader $plugin */
24*5511bd5bSAndreas Gohr        $plugin = plugin_load('action', 'struct_autoloader');
25*5511bd5bSAndreas Gohr        $trans = $plugin->getLang('Exception ' . $message);
26*5511bd5bSAndreas Gohr        if(!$trans) $trans = $message;
27*5511bd5bSAndreas Gohr
28*5511bd5bSAndreas Gohr        $args = func_get_args();
29*5511bd5bSAndreas Gohr        array_shift($args);
30*5511bd5bSAndreas Gohr
31*5511bd5bSAndreas Gohr        $trans = vsprintf($trans, $args);
32*5511bd5bSAndreas Gohr
33*5511bd5bSAndreas Gohr        parent::__construct($trans, -1, null);
34*5511bd5bSAndreas Gohr    }
35*5511bd5bSAndreas Gohr}
36