Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.00% covered (warning)
85.00%
17 / 20
75.00% covered (warning)
75.00%
6 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApplicationService
85.00% covered (warning)
85.00%
17 / 20
75.00% covered (warning)
75.00%
6 / 8
13.57
0.00% covered (danger)
0.00%
0 / 1
 isDemo
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getVersionName
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 getProductName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPlatformVersion
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDefaultEncoding
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isDebugMode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
 isInstallationFinished
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 getConstantValue
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
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) 2018 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
19 *
20 */
21
22namespace oat\tao\model\service;
23
24use common_ext_ExtensionsManager;
25use common_exception_Error;
26use oat\oatbox\service\ConfigurableService;
27use Zend\ServiceManager\ServiceLocatorInterface;
28
29class ApplicationService extends ConfigurableService
30{
31    public const SERVICE_ID = 'tao/ApplicationService';
32
33    public const OPTION_BUILD_NUMBER = 'taoBuildNumber';
34
35    public const OPTION_INSTALLATION_FINISHED = 'installationFinished';
36
37    /**
38     * Returns a whenever or not the current instance is used as demo instance
39     *
40     * @return boolean
41     */
42    public function isDemo()
43    {
44        $releaseStatus = $this->getConstantValue('TAO_RELEASE_STATUS');
45
46        return in_array($releaseStatus, ['demo', 'demoA', 'demoB', 'demoS']);
47    }
48
49    /**
50     * @return string
51     */
52    public function getVersionName()
53    {
54        $version = $this->getPlatformVersion();
55
56        if ($this->hasOption(self::OPTION_BUILD_NUMBER)) {
57            $buildNumber = $this->getOption(self::OPTION_BUILD_NUMBER);
58            $version = 'v' . $version;
59            $version = is_numeric($buildNumber) ? "{$version}+build{$buildNumber}" : $version;
60        }
61
62        return $version;
63    }
64
65    /**
66     * @return string
67     * @throws \common_exception_Error
68     * @throws \common_ext_ExtensionException
69     */
70    public function getProductName()
71    {
72        return $this->getConstantValue('PRODUCT_NAME');
73    }
74
75    /**
76     * @return string
77     * @throws \common_exception_Error
78     * @throws \common_ext_ExtensionException
79     */
80    public function getPlatformVersion()
81    {
82        return $this->getConstantValue('TAO_VERSION');
83    }
84
85    /**
86     * @return string
87     * @throws \common_exception_Error
88     * @throws \common_ext_ExtensionException
89     */
90    public function getDefaultEncoding()
91    {
92        return $this->getConstantValue('TAO_DEFAULT_ENCODING');
93    }
94
95    /**
96     * Return true if platform is on debug mode
97     *
98     * @return bool
99     */
100    public function isDebugMode()
101    {
102        return defined('DEBUG_MODE') && (DEBUG_MODE === true);
103    }
104
105    /**
106     * @return bool
107     */
108    public function isInstallationFinished()
109    {
110        return $this->hasOption(self::OPTION_INSTALLATION_FINISHED) &&
111            $this->getOption(self::OPTION_INSTALLATION_FINISHED);
112    }
113
114    /**
115     * @param string $constantName
116     * @return string
117     *
118     * @throws \common_exception_Error
119     * @throws \common_ext_ExtensionException
120     */
121    private function getConstantValue($constantName)
122    {
123        $serviceLocator = $this->getServiceLocator();
124        if (!$serviceLocator instanceof ServiceLocatorInterface) {
125            throw new common_exception_Error();
126        }
127
128        return $serviceLocator->get(common_ext_ExtensionsManager::SERVICE_ID)
129            ->getExtensionById('tao')
130            ->getConstant($constantName);
131    }
132}