1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yoghi\Bundle\MaddaBundle\Generator; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the MADDA project. |
7
|
|
|
* |
8
|
|
|
* (c) Stefano Tamagnini <> |
9
|
|
|
* |
10
|
|
|
* This source file is subject to the GPLv3 license that is bundled |
11
|
|
|
* with this source code in the file LICENSE. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
use League\Flysystem\Adapter\Local; |
15
|
|
|
use League\Flysystem\Filesystem; |
16
|
|
|
use Psr\Log\LoggerInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Stefano Tamagnini <> |
20
|
|
|
*/ |
21
|
|
|
abstract class AbstractFileGenerator |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* [$currentFile description] |
25
|
|
|
* |
26
|
|
|
* @var [type] |
27
|
|
|
*/ |
28
|
|
|
protected $currentFile; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Array process errors |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected $errors; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* [$logger description] |
39
|
|
|
* |
40
|
|
|
* @var \Psr\Log\LoggerInterface |
41
|
|
|
*/ |
42
|
|
|
protected $logger; |
43
|
|
|
|
44
|
|
|
public function setLogger(LoggerInterface $logger) |
45
|
|
|
{ |
46
|
|
|
$this->logger = $logger; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function error($message, $context = []) |
50
|
|
|
{ |
51
|
|
|
if (!is_null($this->logger)) { |
52
|
|
|
$this->logger->error($message, $context); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function info($message, $context = []) |
57
|
|
|
{ |
58
|
|
|
if (!is_null($this->logger)) { |
59
|
|
|
$this->logger->info($message, $context); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* errori durante la generazione |
65
|
|
|
* |
66
|
|
|
* @return array of string |
67
|
|
|
*/ |
68
|
|
|
public function getErrors() |
69
|
|
|
{ |
70
|
|
|
return $this->errors; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function toString() |
74
|
|
|
{ |
75
|
|
|
return (string) $this->currentFile; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
protected function _createFileOnDir(Local $adapter, $outFile) |
79
|
|
|
{ |
80
|
|
|
$filesystem = new Filesystem($adapter); |
81
|
|
|
|
82
|
|
|
$dir = pathinfo($adapter->getPathPrefix().$outFile, PATHINFO_DIRNAME).'/'; |
83
|
|
|
if (!is_dir($dir)) { |
84
|
|
|
$this->logger->info('Creo directory mancante: '.$dir); |
85
|
|
|
mkdir($dir, 0700, true); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ($filesystem->has($outFile)) { |
89
|
|
|
$filesystem->put($outFile, (string) $this->currentFile); |
90
|
|
|
} else { |
91
|
|
|
$filesystem->write($outFile, (string) $this->currentFile); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $outFile; //$io->text('Outfile: '.$outFile); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.