xref: /plugin/struct/types/Mail.php (revision 16b7d914c0b69bf27d1ddd8a08e05beddbeedf02)
1<?php
2namespace plugin\struct\types;
3
4use plugin\struct\meta\ValidationException;
5
6class Mail extends Text {
7
8    protected $config = array(
9        'prefix' => '',
10        'postfix' => '',
11    );
12
13    /**
14     * Output the stored data
15     *
16     * @param string|int $value the value stored in the database
17     * @param \Doku_Renderer $R the renderer currently used to render the data
18     * @param string $mode The mode the output is rendered in (eg. XHTML)
19     * @return bool true if $mode could be satisfied
20     */
21    public function renderValue($value, \Doku_Renderer $R, $mode) {
22        $mail = $this->config['prefix'] . $value . $this->config['postfix'];
23        $R->emaillink($mail);
24        return true;
25    }
26
27    /**
28     * Validate
29     *
30     * @param int|string $value
31     * @return int|string
32     */
33    public function validate($value) {
34        $value = parent::validate($value);
35
36        $mail = $this->config['prefix'] . $value . $this->config['postfix'];
37        if(!mail_isvalid($mail)) {
38            throw new ValidationException('Mail invalid', $mail);
39        }
40
41        return $value;
42    }
43
44}
45