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