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