Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Office365
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getBody
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * HTTP POST log writer for Office365 webhooks.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2020.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  Error_Logging
25 * @author   Demian Katz <demian.katz@villanova.edu>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org Main Site
28 */
29
30namespace VuFind\Log\Writer;
31
32use Laminas\Http\Client;
33
34/**
35 * This class extends the Laminas Logging to send errors to Office365 webhooks.
36 *
37 * @category VuFind
38 * @package  Error_Logging
39 * @author   Demian Katz <demian.katz@villanova.edu>
40 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
41 * @link     https://vufind.org Main Site
42 */
43class Office365 extends Post
44{
45    /**
46     * The title for generated cards.
47     *
48     * @var string
49     */
50    protected $title;
51
52    /**
53     * Constructor
54     *
55     * @param string $url     URL to open as a stream
56     * @param Client $client  Pre-configured http client
57     * @param array  $options Optional settings (may contain 'channel' for the
58     * Slack channel to use and/or 'name' for the username messages are posted under)
59     *
60     * @throws \Exception
61     */
62    public function __construct($url, Client $client, array $options = [])
63    {
64        $this->title = $options['title'] ?? 'VuFind Log';
65        parent::__construct($url, $client);
66    }
67
68    /**
69     * Get data for raw body
70     *
71     * @param array $event event data
72     *
73     * @return string
74     */
75    protected function getBody($event)
76    {
77        $data = [
78            '@context' => 'https://schema.org/extensions',
79            '@type' => 'MessageCard',
80            'themeColor' => '0072C6',
81            'title' => $this->title,
82            'text' => $this->formatter->format($event),
83        ];
84        return json_encode($data);
85    }
86}