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