1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\PannelloAmministrazioneBundle\Utils; |
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 $rootdir; |
16
|
|
|
private $projectdir; |
17
|
|
|
private $cacheDir; |
18
|
|
|
private $logsDir; |
19
|
|
|
|
20
|
2 |
|
public function setRootDir($projectDir) |
21
|
|
|
{ |
22
|
2 |
|
$this->projectdir = dirname($projectDir); |
23
|
2 |
|
$this->rootdir = dirname($projectDir); |
|
|
|
|
24
|
2 |
|
} |
25
|
|
|
|
26
|
2 |
|
public function setCacheDir($cacheDir) |
27
|
|
|
{ |
28
|
2 |
|
$this->cacheDir = $cacheDir; |
29
|
2 |
|
} |
30
|
|
|
|
31
|
2 |
|
public function setLogsDir($logsDir) |
32
|
|
|
{ |
33
|
2 |
|
$this->logsDir = $logsDir; |
34
|
2 |
|
} |
35
|
|
|
|
36
|
1 |
|
public function getRootPath() |
37
|
|
|
{ |
38
|
1 |
|
return $this->rootdir; |
39
|
|
|
} |
40
|
2 |
|
public function getProjectPath() |
41
|
|
|
{ |
42
|
2 |
|
return $this->projectdir; |
43
|
|
|
} |
44
|
1 |
|
public function getBinPath() |
45
|
|
|
{ |
46
|
1 |
|
$bindir = $this->getProjectPath() . '/bin'; |
47
|
1 |
|
if (!file_exists($bindir)) { |
48
|
1 |
|
$bindir = realpath($this->getProjectPath() . '/../bin'); |
49
|
|
|
} |
50
|
1 |
|
if (!file_exists($bindir)) { |
51
|
|
|
$bindir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'vendor' . |
52
|
|
|
DIRECTORY_SEPARATOR . 'bin'; |
53
|
|
|
} |
54
|
1 |
|
if (!file_exists($bindir)) { |
55
|
|
|
throw new \Exception("Cartella Bin non trovata", -100); |
|
|
|
|
56
|
|
|
} |
57
|
1 |
|
return $bindir; |
58
|
|
|
} |
59
|
1 |
|
public function getVendorBinPath() |
60
|
|
|
{ |
61
|
1 |
|
$vendorbindir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin'; |
62
|
1 |
|
if (!file_exists($vendorbindir)) { |
63
|
1 |
|
$vendorbindir = realpath($this->getProjectPath() . '/../vendor/bin'); |
64
|
1 |
|
if (!file_exists($vendorbindir)) { |
65
|
|
|
throw new \Exception("Cartella Bin in vendor non trovata", -100); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
} |
68
|
1 |
|
return $vendorbindir; |
69
|
|
|
} |
70
|
2 |
|
public function getSrcPath() |
71
|
|
|
{ |
72
|
2 |
|
$srcdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'src'; |
73
|
2 |
|
return $srcdir; |
74
|
|
|
} |
75
|
|
|
public function getPublicPath() |
76
|
|
|
{ |
77
|
|
|
$publicdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'public'; |
78
|
|
|
return $publicdir; |
79
|
|
|
} |
80
|
|
|
public function getAppPath() |
81
|
|
|
{ |
82
|
|
|
$appdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'app'; |
83
|
|
|
return $appdir; |
84
|
|
|
} |
85
|
1 |
|
public function getTemplatePath() |
86
|
|
|
{ |
87
|
1 |
|
$srcdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'templates'; |
88
|
1 |
|
return realpath($srcdir); |
89
|
|
|
} |
90
|
|
|
public function getVarPath() |
91
|
|
|
{ |
92
|
|
|
$vardir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'var'; |
93
|
|
|
return realpath($vardir); |
94
|
|
|
} |
95
|
1 |
|
public function getDocPath() |
96
|
|
|
{ |
97
|
1 |
|
$docdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'doc'; |
98
|
1 |
|
return realpath($docdir); |
99
|
|
|
} |
100
|
1 |
|
public function getCachePath() |
101
|
|
|
{ |
102
|
1 |
|
$cachedir = $this->cacheDir; |
103
|
1 |
|
if (!file_exists($cachedir)) { |
104
|
|
|
throw new \Exception("Cache non trovata", -100); |
|
|
|
|
105
|
|
|
} |
106
|
1 |
|
return $cachedir; |
107
|
|
|
} |
108
|
1 |
|
public function getLogsPath() |
109
|
|
|
{ |
110
|
1 |
|
$logsdir = $this->logsDir; |
111
|
1 |
|
if (!file_exists($logsdir)) { |
112
|
|
|
throw new \Exception("Logs non trovata", -100); |
|
|
|
|
113
|
|
|
} |
114
|
1 |
|
return $logsdir; |
115
|
|
|
} |
116
|
1 |
|
public function getConsole() |
117
|
|
|
{ |
118
|
1 |
|
$console = $this->getBinPath() . '/console'; |
119
|
|
|
// Questo codice per versioni che usano un symfony 2 o 3 |
120
|
1 |
|
if (!file_exists($console)) { |
121
|
|
|
throw new \Exception("Console non trovata", -100); |
|
|
|
|
122
|
|
|
} |
123
|
1 |
|
return $console; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
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.