Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
core_kernel_uri_UriService
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 singleton
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 generateUri
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setUriProvider
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getUriProvider
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2015 (original work) Open Assessment Technologies SA;
19 *
20 */
21
22use oat\generis\model\kernel\uri\UriProvider;
23use oat\oatbox\service\ServiceManager;
24
25/**
26 * Provides backward compatibility to generates a URI
27 *
28 * @author Joel Bout <joel@taotesting.com>
29 * @deprecated
30 */
31class core_kernel_uri_UriService
32{
33    public const CONFIG_KEY = 'uriProvider';
34
35    private static $instance;
36
37    public static function singleton()
38    {
39        if (is_null(self::$instance)) {
40            self::$instance = new self();
41        }
42        return self::$instance;
43    }
44
45    private $uriProvider = null;
46
47    /**
48     * Generate a new URI with the UriProvider in force.
49     *
50     * @return string
51     */
52    public function generateUri()
53    {
54        return (string) $this->getUriProvider()->provide();
55    }
56
57    /**
58     * Set the UriProvider in force.
59     *
60     * @param UriProvider $provider
61     */
62    public function setUriProvider(UriProvider $provider)
63    {
64        $this->uriProvider = $provider;
65        ServiceManager::getServiceManager()->register(UriProvider::SERVICE_ID, $provider);
66    }
67
68    /**
69     * Get the UriProvider in force.
70     *
71     * @return UriProvider
72     */
73    public function getUriProvider()
74    {
75        if (is_null($this->uriProvider)) {
76            $this->uriProvider = ServiceManager::getServiceManager()->get(UriProvider::SERVICE_ID);
77        }
78        return $this->uriProvider;
79    }
80}