Completed
Push — master ( 60d200...e262bd )
by Andrea
08:44
created

ProjectPath::getSrcPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Fi\PannelloAmministrazioneBundle\DependencyInjection;
4
5
class ProjectPath
6
{
7
8
    /**
9
     * La funzione ritorna un array con i path dell'applicazione.
10
     *
11
     * @param $container Container dell'applicazione
12
     *
13
     * @return array Ritorna l'array contenente i path
14
     */
15
    private $container;
16
    private $rootdir;
17
    private $prjdir;
18
19 3
    public function __construct($container)
20
    {
21 3
        $this->container = $container;
22 3
        $rootdir = dirname($this->container->get('kernel')->getRootDir());
23 3
        $this->rootdir = $rootdir;
24 3
        $this->prjdir = $rootdir;
25 3
    }
26
27 1
    public function getRootPath()
28
    {
29 1
        return $this->rootdir;
30
    }
31
32 2
    public function getProjectPath()
33
    {
34 2
        return $this->prjdir;
35
    }
36
37
    public function getBinPath()
38
    {
39
        $bindir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'bin';
40
        if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) {
41
            if (!file_exists($bindir)) {
42
                $bindir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'vendor' .
43
                        DIRECTORY_SEPARATOR . 'bin';
44
            }
45
        }
46
        if (!file_exists($bindir)) {
47
            throw new \Exception("Cartella Bin non trovata", -100);
48
        }
49
        return $bindir;
50
    }
51
52
    public function getVendorBinPath()
53
    {
54
        $vendorbindir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin';
55
        if (!file_exists($vendorbindir)) {
56
            $vendorbindir = $this->getProjectPath() . '/../vendor/bin';
57
            if (!file_exists($vendorbindir)) {
58
                throw new \Exception("Cartella Bin in vendor non trovata", -100);
59
            }
60
        }
61
        return $vendorbindir;
62
    }
63
64 1
    public function getSrcPath()
65
    {
66 1
        $srcdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'src';
67 1
        return $srcdir;
68
    }
69
70 1
    public function getAppPath()
71
    {
72 1
        $appdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'app';
73 1
        return $appdir;
74
    }
75
76 1
    public function getVarPath()
77
    {
78 1
        $vardir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'var';
79 1
        return $vardir;
80
    }
81
82
    public function getDocPath()
83
    {
84
        $docdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'doc';
85
        return $docdir;
86
    }
87
88 1
    public function getCachePath()
89
    {
90 1
        $cachedir = $this->getAppPath() . DIRECTORY_SEPARATOR . 'cache';
91 1
        if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) {
92 1
            if (!file_exists($cachedir)) {
93 1
                $cachedir = $this->getVarPath() . DIRECTORY_SEPARATOR . 'cache';
94
            }
95
        }
96 1
        if (!file_exists($cachedir)) {
97
            throw new \Exception("Cache non trovata", -100);
98
        }
99 1
        return $cachedir;
100
    }
101
102
    public function getLogsPath()
103
    {
104
        $logsdir = $this->getAppPath() . DIRECTORY_SEPARATOR . 'logs';
105
        if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) {
106
            if (!file_exists($logsdir)) {
107
                $logsdir = $this->getVarPath() . DIRECTORY_SEPARATOR . 'logs';
108
            }
109
        }
110
        if (!file_exists($logsdir)) {
111
            throw new \Exception("Logs non trovata", -100);
112
        }
113
        return $logsdir;
114
    }
115
116
    public function getConsole()
117
    {
118
        $console = $this->getAppPath() . DIRECTORY_SEPARATOR . 'console';
119
        // Questo codice per versioni che usano un symfony 2 o 3
120
        if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) {
121
            if (!file_exists($console)) {
122
                $console = $this->getBinPath() . DIRECTORY_SEPARATOR . 'console';
123
            }
124
        }
125
        if (!file_exists($console)) {
126
            throw new \Exception("Console non trovata", -100);
127
        }
128
        return $console;
129
    }
130
}
131