|
4 | 4 |
|
5 | 5 | use Illuminate\Config\Repository; |
6 | 6 | use Illuminate\Console\Command; |
| 7 | +use Potsky\LaravelLocalizationHelpers\Factory\CodeStyle; |
7 | 8 | use Potsky\LaravelLocalizationHelpers\Factory\Localization; |
8 | 9 | use Potsky\LaravelLocalizationHelpers\Factory\MessageBagInterface; |
9 | 10 |
|
10 | 11 | abstract class LocalizationAbstract extends Command implements MessageBagInterface |
11 | 12 | { |
12 | | - const SUCCESS = 0; |
13 | | - const ERROR = 1; |
14 | | - |
15 | | - /** |
16 | | - * Init log file for first log |
17 | | - * |
18 | | - * @var boolean |
19 | | - */ |
20 | | - protected static $logInFileFirst = true; |
21 | | - /** |
22 | | - * Config repository. |
23 | | - * |
24 | | - * @var \Illuminate\Config\Repository |
25 | | - */ |
26 | | - protected $configRepository; |
27 | | - /** |
28 | | - * The localization manager |
29 | | - * |
30 | | - * @var Localization |
31 | | - */ |
32 | | - protected $manager; |
33 | | - /** |
34 | | - * Should commands display something |
35 | | - * |
36 | | - * @var boolean |
37 | | - */ |
38 | | - protected $display = true; |
39 | | - |
40 | | - /** |
41 | | - * Create a new command instance. |
42 | | - * |
43 | | - * @param \Illuminate\Config\Repository $configRepository |
44 | | - */ |
45 | | - public function __construct( Repository $configRepository ) |
46 | | - { |
47 | | - // Inject this command just to have access to writeLine, writeError, etc... methods |
48 | | - $this->manager = new Localization( $this ); |
49 | | - |
50 | | - parent::__construct(); |
51 | | - } |
52 | | - |
53 | | - /** |
54 | | - * Display console message |
55 | | - * |
56 | | - * @param string $s the message to display |
57 | | - * |
58 | | - * @return void |
59 | | - */ |
60 | | - public function writeLine( $s ) |
61 | | - { |
62 | | - if ( $this->display ) |
63 | | - { |
64 | | - parent::line( $s ); |
65 | | - } |
66 | | - } |
67 | | - |
68 | | - /** |
69 | | - * Display console message |
70 | | - * |
71 | | - * @param string $s the message to display |
72 | | - * |
73 | | - * @return void |
74 | | - */ |
75 | | - public function writeInfo( $s ) |
76 | | - { |
77 | | - if ( $this->display ) |
78 | | - { |
79 | | - parent::info( $s ); |
80 | | - } |
81 | | - } |
82 | | - |
83 | | - /** |
84 | | - * Display console message |
85 | | - * |
86 | | - * @param string $s the message to display |
87 | | - * |
88 | | - * @return void |
89 | | - */ |
90 | | - public function writeComment( $s ) |
91 | | - { |
92 | | - if ( $this->display ) |
93 | | - { |
94 | | - parent::comment( $s ); |
95 | | - } |
96 | | - } |
97 | | - |
98 | | - /** |
99 | | - * Display console message |
100 | | - * |
101 | | - * @param string $s the message to display |
102 | | - * |
103 | | - * @return void |
104 | | - * |
105 | | - * @codeCoverageIgnore |
106 | | - */ |
107 | | - public function writeQuestion( $s ) |
108 | | - { |
109 | | - if ( $this->display ) |
110 | | - { |
111 | | - parent::question( $s ); |
112 | | - } |
113 | | - } |
114 | | - |
115 | | - /** |
116 | | - * Display console message |
117 | | - * |
118 | | - * @param string $s the message to display |
119 | | - * |
120 | | - * @return void |
121 | | - */ |
122 | | - public function writeError( $s ) |
123 | | - { |
124 | | - if ( $this->display ) |
125 | | - { |
126 | | - parent::error( $s ); |
127 | | - } |
128 | | - } |
129 | | - |
130 | | - /** |
131 | | - * Log in a file for debug purpose only |
132 | | - * |
133 | | - * @param mixed $txt |
134 | | - * @param string $logFile |
135 | | - * |
136 | | - * @codeCoverageIgnore |
137 | | - */ |
138 | | - protected function logInFile( $txt = '' , $logFile = '/tmp/llh.log' ) |
139 | | - { |
140 | | - if ( ! is_string( $txt ) ) |
141 | | - { |
142 | | - $txt = print_r( $txt , true ); |
143 | | - } |
144 | | - |
145 | | - $txt = '==> ' . date( 'Y/m/d H:i:s' ) . ' ==> ' . $txt . "\n"; |
146 | | - |
147 | | - if ( self::$logInFileFirst === true ) |
148 | | - { |
149 | | - file_put_contents( $logFile , $txt ); |
150 | | - |
151 | | - self::$logInFileFirst = false; |
152 | | - } |
153 | | - else |
154 | | - { |
155 | | - file_put_contents( $logFile , $txt , FILE_APPEND ); |
156 | | - } |
157 | | - } |
158 | | - |
| 13 | + const SUCCESS = 0; |
| 14 | + |
| 15 | + const ERROR = 1; |
| 16 | + |
| 17 | + /** |
| 18 | + * Init log file for first log |
| 19 | + * |
| 20 | + * @var boolean |
| 21 | + */ |
| 22 | + protected static $logInFileFirst = true; |
| 23 | + |
| 24 | + /** |
| 25 | + * Config repository. |
| 26 | + * |
| 27 | + * @var \Illuminate\Config\Repository |
| 28 | + */ |
| 29 | + protected $configRepository; |
| 30 | + |
| 31 | + /** |
| 32 | + * The localization manager |
| 33 | + * |
| 34 | + * @var Localization |
| 35 | + */ |
| 36 | + protected $manager; |
| 37 | + |
| 38 | + /** |
| 39 | + * Should commands display something |
| 40 | + * |
| 41 | + * @var boolean |
| 42 | + */ |
| 43 | + protected $display = true; |
| 44 | + |
| 45 | + /** |
| 46 | + * Create a new command instance. |
| 47 | + * |
| 48 | + * @param \Illuminate\Config\Repository $configRepository |
| 49 | + */ |
| 50 | + public function __construct(Repository $configRepository) |
| 51 | + { |
| 52 | + // Inject this command just to have access to writeLine, writeError, etc... methods |
| 53 | + $this->manager = new Localization($this); |
| 54 | + |
| 55 | + parent::__construct(); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Display console message |
| 60 | + * |
| 61 | + * @param string $s the message to display |
| 62 | + * |
| 63 | + * @return void |
| 64 | + */ |
| 65 | + public function writeLine($s) |
| 66 | + { |
| 67 | + if ($this->display) { |
| 68 | + parent::line($s); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Display console message |
| 74 | + * |
| 75 | + * @param string $s the message to display |
| 76 | + * |
| 77 | + * @return void |
| 78 | + */ |
| 79 | + public function writeInfo($s) |
| 80 | + { |
| 81 | + if ($this->display) { |
| 82 | + parent::info($s); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Display console message |
| 88 | + * |
| 89 | + * @param string $s the message to display |
| 90 | + * |
| 91 | + * @return void |
| 92 | + */ |
| 93 | + public function writeComment($s) |
| 94 | + { |
| 95 | + if ($this->display) { |
| 96 | + parent::comment($s); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Display console message |
| 102 | + * |
| 103 | + * @param string $s the message to display |
| 104 | + * |
| 105 | + * @return void |
| 106 | + * |
| 107 | + * @codeCoverageIgnore |
| 108 | + */ |
| 109 | + public function writeQuestion($s) |
| 110 | + { |
| 111 | + if ($this->display) { |
| 112 | + parent::question($s); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Display console message |
| 118 | + * |
| 119 | + * @param string $s the message to display |
| 120 | + * |
| 121 | + * @return void |
| 122 | + */ |
| 123 | + public function writeError($s) |
| 124 | + { |
| 125 | + if ($this->display) { |
| 126 | + parent::error($s); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Log in a file for debug purpose only |
| 132 | + * |
| 133 | + * @param mixed $txt |
| 134 | + * @param string $logFile |
| 135 | + * |
| 136 | + * @codeCoverageIgnore |
| 137 | + */ |
| 138 | + protected function logInFile($txt = '', $logFile = '/tmp/llh.log') |
| 139 | + { |
| 140 | + if (! is_string($txt)) { |
| 141 | + $txt = print_r($txt, true); |
| 142 | + } |
| 143 | + |
| 144 | + $txt = '==> '.date('Y/m/d H:i:s').' ==> '.$txt."\n"; |
| 145 | + |
| 146 | + if (self::$logInFileFirst === true) { |
| 147 | + file_put_contents($logFile, $txt); |
| 148 | + |
| 149 | + self::$logInFileFirst = false; |
| 150 | + } else { |
| 151 | + file_put_contents($logFile, $txt, FILE_APPEND); |
| 152 | + } |
| 153 | + } |
159 | 154 | } |
0 commit comments