1<?php
2/**
3 * LdapMissingException.php
4 *
5 * -Description-
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 *
20 * @link       https://www.librenms.org
21 * @copyright  2019 Tony Murray
22 * @author     Tony Murray <murraytony@gmail.com>
23 */
24
25namespace LibreNMS\Exceptions;
26
27class LdapMissingException extends AuthenticationException
28{
29    private const DEFAULT_MESSAGE = 'PHP does not support LDAP, please install or enable the PHP LDAP extension';
30
31    public function __construct(
32        string $message = self::DEFAULT_MESSAGE,
33        int $code = 0,
34        \Exception $previous = null
35    ) {
36        parent::__construct($message, false, $code, $previous);
37    }
38
39    /**
40     * Render the exception into an HTTP or JSON response.
41     *
42     * @return \Illuminate\Http\Response
43     */
44    public function render(\Illuminate\Http\Request $request)
45    {
46        $title = trans('exceptions.ldap_missing.title');
47        $message = ($this->message == self::DEFAULT_MESSAGE) ? trans('exceptions.ldap_missing.message') : $this->getMessage();
48
49        return $request->wantsJson() ? response()->json([
50            'status' => 'error',
51            'message' => "$title: $message",
52        ]) : response()->view('errors.generic', [
53            'title' => $title,
54            'content' => $message,
55        ]);
56    }
57}
58