Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ExtraPoService
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 4
240
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
12
 addPoPath
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
20
 removePoPath
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
20
 requirePos
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace oat\tao\model\i18n;
4
5use oat\oatbox\service\ConfigurableService;
6
7class ExtraPoService extends ConfigurableService
8{
9    public const SERVICE_ID = 'tao/ExtraPoService';
10
11    public function __construct(array $options = [])
12    {
13        if (isset($options['paths']) === false || is_array($options['paths']) === false) {
14            $options['paths'] = [];
15        }
16
17        parent::__construct($options);
18    }
19
20    public function addPoPath($extensionId, $path)
21    {
22        $paths = $this->getOption('paths');
23
24        try {
25            $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById($extensionId);
26
27            if (isset($paths[$ext->getId()]) === false) {
28                $paths[$ext->getId()] = [];
29            }
30
31            if (in_array($path, $paths[$ext->getId()]) === false) {
32                $paths[$ext->getId()][] = $path;
33            }
34
35            $this->setOption('paths', $paths);
36
37            return true;
38        } catch (\common_ext_ExtensionException $e) {
39            return false;
40        }
41    }
42
43    public function removePoPath($extensionId, $path)
44    {
45        $paths = $this->getOption('paths');
46
47        try {
48            $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById($extensionId);
49
50            if (isset($paths[$ext->getId()]) === false) {
51                return false;
52            }
53
54            $index = array_search($path, $paths[$ext->getId()]);
55
56            if ($index === false) {
57                return $index;
58            }
59
60            unset($paths[$ext->getId()][$index]);
61
62            return true;
63        } catch (\common_ext_ExtensionException $e) {
64            return false;
65        }
66    }
67
68    public function requirePos()
69    {
70        $count = 0;
71        $extensionManager = \common_ext_ExtensionsManager::singleton();
72
73        foreach ($this->getOption('paths') as $extId => $files) {
74            $ext = $extensionManager->getExtensionById($extId);
75            foreach ($files as $file) {
76                if (\l10n::set($ext->getDir() . $file) !== false) {
77                    $count++;
78                }
79            }
80        }
81
82        return $count;
83    }
84}