1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\PannelloAmministrazioneBundle\Utils; |
4
|
|
|
|
5
|
|
|
class ProjectPath |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* La funzione ritorna un array con i path dell'applicazione. |
9
|
|
|
* |
10
|
|
|
* @param $container Container dell'applicazione |
11
|
|
|
* |
12
|
|
|
* @return array Ritorna l'array contenente i path |
13
|
|
|
*/ |
14
|
|
|
private $rootdir; |
15
|
|
|
private $projectdir; |
16
|
|
|
private $cacheDir; |
17
|
|
|
private $logsDir; |
18
|
|
|
|
19
|
2 |
|
public function setRootDir($projectDir) |
20
|
|
|
{ |
21
|
2 |
|
$this->projectdir = dirname($projectDir); |
22
|
2 |
|
$this->rootdir = dirname($projectDir); |
|
|
|
|
23
|
2 |
|
} |
24
|
|
|
|
25
|
2 |
|
public function setCacheDir($cacheDir) |
26
|
|
|
{ |
27
|
2 |
|
$this->cacheDir = $cacheDir; |
28
|
2 |
|
} |
29
|
|
|
|
30
|
2 |
|
public function setLogsDir($logsDir) |
31
|
|
|
{ |
32
|
2 |
|
$this->logsDir = $logsDir; |
33
|
2 |
|
} |
34
|
|
|
|
35
|
1 |
|
public function getRootPath() |
36
|
|
|
{ |
37
|
1 |
|
return $this->rootdir; |
38
|
|
|
} |
39
|
|
|
|
40
|
2 |
|
public function getProjectPath() |
41
|
|
|
{ |
42
|
2 |
|
return $this->projectdir; |
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
public function getBinPath() |
46
|
|
|
{ |
47
|
1 |
|
$bindir = $this->getProjectPath().'/bin'; |
48
|
1 |
|
if (!file_exists($bindir)) { |
49
|
1 |
|
$bindir = realpath($this->getProjectPath().'/../bin'); |
50
|
|
|
} |
51
|
1 |
|
if (!file_exists($bindir)) { |
52
|
|
|
throw new \Exception('Cartella Bin non trovata', -100); |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
return $bindir; |
56
|
|
|
} |
57
|
|
|
|
58
|
1 |
|
public function getVendorBinPath() |
59
|
|
|
{ |
60
|
1 |
|
$vendorbindir = $this->getProjectPath().DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'bin'; |
61
|
1 |
|
if (!file_exists($vendorbindir)) { |
62
|
1 |
|
$vendorbindir = dirname($this->getProjectPath()).DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'bin'; |
63
|
1 |
|
if (!file_exists($vendorbindir)) { |
64
|
|
|
throw new \Exception('Cartella Bin in vendor non trovata', -100); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
1 |
|
return $vendorbindir; |
69
|
|
|
} |
70
|
|
|
|
71
|
2 |
|
public function getSrcPath() |
72
|
|
|
{ |
73
|
2 |
|
$srcdir = $this->getProjectPath().DIRECTORY_SEPARATOR.'src'; |
74
|
|
|
|
75
|
2 |
|
return $srcdir; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getPublicPath() |
79
|
|
|
{ |
80
|
|
|
$publicdir = $this->getProjectPath().DIRECTORY_SEPARATOR.'public'; |
81
|
|
|
|
82
|
|
|
return $publicdir; |
83
|
|
|
} |
84
|
|
|
|
85
|
1 |
|
public function getTemplatePath() |
86
|
|
|
{ |
87
|
1 |
|
$srcdir = $this->getProjectPath().DIRECTORY_SEPARATOR.'templates'; |
88
|
|
|
|
89
|
1 |
|
return realpath($srcdir); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getVarPath() |
93
|
|
|
{ |
94
|
|
|
$vardir = $this->getProjectPath().DIRECTORY_SEPARATOR.'var'; |
95
|
|
|
|
96
|
|
|
return realpath($vardir); |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
public function getDocPath() |
100
|
|
|
{ |
101
|
1 |
|
$docdir = $this->getProjectPath().DIRECTORY_SEPARATOR.'doc'; |
102
|
|
|
|
103
|
1 |
|
return realpath($docdir); |
104
|
|
|
} |
105
|
|
|
|
106
|
1 |
|
public function getCachePath() |
107
|
|
|
{ |
108
|
1 |
|
$cachedir = $this->cacheDir; |
109
|
1 |
|
if (!file_exists($cachedir)) { |
110
|
|
|
throw new \Exception('Cache non trovata', -100); |
111
|
|
|
} |
112
|
|
|
|
113
|
1 |
|
return $cachedir; |
114
|
|
|
} |
115
|
|
|
|
116
|
1 |
|
public function getLogsPath() |
117
|
|
|
{ |
118
|
1 |
|
$logsdir = $this->logsDir; |
119
|
1 |
|
if (!file_exists($logsdir)) { |
120
|
|
|
throw new \Exception('Logs non trovata', -100); |
121
|
|
|
} |
122
|
|
|
|
123
|
1 |
|
return $logsdir; |
124
|
|
|
} |
125
|
|
|
|
126
|
1 |
|
public function getConsole() |
127
|
|
|
{ |
128
|
1 |
|
$console = $this->getBinPath().'/console'; |
129
|
|
|
// Questo codice per versioni che usano un symfony 2 o 3 |
130
|
1 |
|
if (!file_exists($console)) { |
131
|
|
|
throw new \Exception('Console non trovata', -100); |
132
|
|
|
} |
133
|
|
|
|
134
|
1 |
|
return $console; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.