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