Conditions | 4 |
Paths | 6 |
Total Lines | 37 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
19 | public function editor($file) |
||
|
|||
20 | { |
||
21 | if ('/admin/appearance/editor' === $file) { |
||
22 | $this->redirectTo('/admin/appearance/editor/file/dGVtcGxhdGVzL19oZWFkLmh0bWwucGhw'); |
||
23 | } |
||
24 | |||
25 | $model = new EditorModel(); |
||
26 | |||
27 | $filesList['templates'] = $model->getFilesListByPath('templates'); |
||
28 | $filesList['css'] = $model->getFilesListByPath('css'); |
||
29 | $filesList['js'] = $model->getFilesListByPath('js'); |
||
30 | |||
31 | $filename = base64_decode($file); |
||
32 | |||
33 | // if data was send |
||
34 | if (isset($_POST['save'])) { |
||
35 | /** @var array $_POST */ |
||
36 | if ($model->saveFile($filename, $_POST['content'])) { |
||
37 | AlertsCollection::add(new Alert( |
||
38 | 'success', |
||
39 | 'Pomyślnie zapisano plik szablonu '.$filename.'.' |
||
40 | )); |
||
41 | } else { |
||
42 | AlertsCollection::add(new Alert( |
||
43 | 'error', |
||
44 | 'Coś poszło nie tak podczas zapisywania pliku '.$filename.'. '. |
||
45 | 'Sprawdź prawa dostępu' |
||
46 | )); |
||
47 | } |
||
48 | |||
49 | $this->redirectTo($file); |
||
50 | } |
||
51 | |||
52 | $view = new EditorView(); |
||
53 | $view->editor($filesList, $model->getFileInfo($filename)); |
||
54 | $view->render('admin'); |
||
55 | } |
||
56 | } |
||
57 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: