Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
manifest
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 handle
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14namespace phpbb;
15
16use phpbb\config\config;
17use phpbb\event\dispatcher_interface;
18use phpbb\exception\http_exception;
19use phpbb\language\language;
20use Symfony\Component\HttpFoundation\JsonResponse;
21use Symfony\Component\HttpFoundation\Response;
22
23class manifest
24{
25    /** @var config */
26    protected $config;
27
28    /** @var language */
29    protected $language;
30
31    /** @var path_helper */
32    protected $path_helper;
33
34    /** @var dispatcher_interface */
35    protected $phpbb_dispatcher;
36
37    /** @var user */
38    protected $user;
39
40    /**
41     * Constructor for manifest controller
42     *
43     * @param config $config
44     * @param language $language
45     * @param path_helper $path_helper
46     * @param dispatcher_interface $phpbb_dispatcher
47     * @param user $user
48     */
49    public function __construct(config $config, language $language, path_helper $path_helper, dispatcher_interface $phpbb_dispatcher, user $user)
50    {
51        $this->config = $config;
52        $this->path_helper = $path_helper;
53        $this->phpbb_dispatcher = $phpbb_dispatcher;
54        $this->language = $language;
55        $this->user = $user;
56    }
57
58    /**
59     * Handle creation of a manifest json file for progressive web-app support
60     *
61     * @return JsonResponse
62     */
63    public function handle(): JsonResponse
64    {
65        if ($this->user->data['is_bot'])
66        {
67            throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION');
68        }
69
70        $board_path = $this->config['force_server_vars'] ? $this->config['script_path'] : $this->path_helper->get_web_root_path();
71
72        $manifest = [
73            'name'            => $this->config['sitename'],
74            'short_name'    => $this->config['sitename_short'] ?: substr($this->config['sitename'], 0, 12),
75            'display'        => 'standalone',
76            'orientation'    => 'portrait',
77            'dir'            => $this->language->lang('DIRECTION'),
78            'start_url'        => $board_path,
79            'scope'            => $board_path,
80        ];
81
82        /**
83         * Event to modify manifest data before it is outputted
84         *
85         * @event core.modify_manifest
86         * @var    array    manifest    Array of manifest members
87         * @var    string    board_path    Path to the board root
88         * @since 4.0.0-a1
89         */
90        $vars = array('manifest', 'board_path');
91        extract($this->phpbb_dispatcher->trigger_event('core.modify_manifest', compact($vars)));
92
93        return new JsonResponse($manifest);
94    }
95}