1
0
mirror of https://github.com/flarum/core.git synced 2025-07-15 22:06:24 +02:00
Files
php-flarum/src/Api/Controller/SetSettingsController.php
Franz Liedke d492579638 Apply fixes from StyleCI
[ci skip] [skip ci]
2019-11-28 00:16:50 +00:00

66 lines
1.6 KiB
PHP

<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Api\Controller;
use Flarum\Settings\Event;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\AssertPermissionTrait;
use Illuminate\Contracts\Events\Dispatcher;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\EmptyResponse;
class SetSettingsController implements RequestHandlerInterface
{
use AssertPermissionTrait;
/**
* @var \Flarum\Settings\SettingsRepositoryInterface
*/
protected $settings;
/**
* @var Dispatcher
*/
protected $dispatcher;
/**
* @param SettingsRepositoryInterface $settings
*/
public function __construct(SettingsRepositoryInterface $settings, Dispatcher $dispatcher)
{
$this->settings = $settings;
$this->dispatcher = $dispatcher;
}
/**
* {@inheritdoc}
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$this->assertAdmin($request->getAttribute('actor'));
$settings = $request->getParsedBody();
$this->dispatcher->dispatch(new Event\Saving($settings));
foreach ($settings as $k => $v) {
$this->dispatcher->dispatch(new Event\Serializing($k, $v));
$this->settings->set($k, $v);
}
$this->dispatcher->dispatch(new Event\Saved($settings));
return new EmptyResponse(204);
}
}