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