1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Flextype\Plugin\Admin\Controllers; |
6
|
|
|
|
7
|
|
|
use DateTime; |
8
|
|
|
use Flextype\Component\Arrays\Arrays; |
|
|
|
|
9
|
|
|
use Flextype\Component\Filesystem\Filesystem; |
|
|
|
|
10
|
|
|
use Psr\Http\Message\ResponseInterface as Response; |
|
|
|
|
11
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
|
|
|
|
12
|
|
|
use function array_merge; |
13
|
|
|
use function explode; |
14
|
|
|
use function Flextype\Component\I18n\__; |
|
|
|
|
15
|
|
|
use Flextype\App\Foundation\Container; |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @property View $view |
19
|
|
|
* @property Router $router |
20
|
|
|
* @property Cache $cache |
21
|
|
|
* @property Entries $entries |
22
|
|
|
* @property Plugins $plugins |
23
|
|
|
* @property Registry $registry |
24
|
|
|
* @property Flash $flash |
25
|
|
|
*/ |
26
|
|
|
class SettingsController extends Container |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Index page |
30
|
|
|
* |
31
|
|
|
* @param Request $request PSR7 request |
32
|
|
|
* @param Response $response PSR7 response |
33
|
|
|
*/ |
34
|
|
|
public function index(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response |
35
|
|
|
{ |
36
|
|
|
return $this->twig->render( |
37
|
|
|
$response, |
38
|
|
|
'plugins/admin/templates/system/settings/index.html', |
39
|
|
|
[ |
40
|
|
|
'data' => Filesystem::read(PATH['project'] . '/config/flextype/settings.yaml'), |
|
|
|
|
41
|
|
|
'menu_item' => 'settings', |
42
|
|
|
'links' => [ |
43
|
|
|
'settings' => [ |
44
|
|
|
'link' => $this->router->pathFor('admin.settings.index'), |
45
|
|
|
'title' => __('admin_settings'), |
|
|
|
|
46
|
|
|
'active' => true |
47
|
|
|
], |
48
|
|
|
], |
49
|
|
|
'buttons' => [ |
50
|
|
|
'save' => [ |
51
|
|
|
'link' => 'javascript:;', |
52
|
|
|
'title' => __('admin_save'), |
53
|
|
|
'type' => 'action' |
54
|
|
|
], |
55
|
|
|
], |
56
|
|
|
] |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Update settings process |
62
|
|
|
* |
63
|
|
|
* @param Request $request PSR7 request |
64
|
|
|
* @param Response $response PSR7 response |
65
|
|
|
*/ |
66
|
|
|
public function updateSettingsProcess(Request $request, Response $response) : Response |
67
|
|
|
{ |
68
|
|
|
$post_data = $request->getParsedBody(); |
69
|
|
|
|
70
|
|
|
if (Filesystem::write(PATH['project'] . '/config/' . '/settings.yaml', $post_data['data'])) { |
|
|
|
|
71
|
|
|
$this->flash->addMessage('success', __('admin_message_settings_saved')); |
|
|
|
|
72
|
|
|
} else { |
73
|
|
|
$this->flash->addMessage('error', __('admin_message_settings_was_not_saved')); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $response->withRedirect($this->router->pathFor('admin.settings.index')); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Return date formats allowed |
81
|
|
|
* |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
public function dateFormats() : array |
85
|
|
|
{ |
86
|
|
|
$now = new DateTime(); |
87
|
|
|
|
88
|
|
|
return [ |
89
|
|
|
'd-m-Y H:i' => $now->format('d-m-Y H:i'), |
90
|
|
|
'Y-m-d H:i' => $now->format('Y-m-d H:i'), |
91
|
|
|
'm/d/Y h:i a' => $now->format('m/d/Y h:i a'), |
92
|
|
|
'H:i d-m-Y' => $now->format('H:i d-m-Y'), |
93
|
|
|
'h:i a m/d/Y' => $now->format('h:i a m/d/Y'), |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Return display date formats allowed |
99
|
|
|
* |
100
|
|
|
* @return array |
101
|
|
|
*/ |
102
|
|
|
public function displayDateFormats() : array |
103
|
|
|
{ |
104
|
|
|
$now = new DateTime(); |
105
|
|
|
|
106
|
|
|
return [ |
107
|
|
|
'F jS \\a\\t g:ia' => $now->format('F jS \\a\\t g:ia'), |
108
|
|
|
'l jS \\of F g:i A' => $now->format('l jS \\of F g:i A'), |
109
|
|
|
'D, d M Y G:i:s' => $now->format('m/d/Y h:i a'), |
110
|
|
|
'd-m-y G:i' => $now->format('d-m-y G:i'), |
111
|
|
|
'jS M Y' => $now->format('jS M Y'), |
112
|
|
|
]; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths