1
0
mirror of https://github.com/flarum/core.git synced 2025-07-26 11:10:41 +02:00
Files
php-flarum/src/Api/Controller/SetSettingsController.php
Franz Liedke 78f3681fc1 Fix namespace orderings
(Thanks, StyleCI!)
2017-10-03 18:54:06 +02:00

66 lines
1.5 KiB
PHP

<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Api\Controller;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\Settings\Event\Saved;
use Flarum\Settings\Event\Serializing;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\AssertPermissionTrait;
use Illuminate\Contracts\Events\Dispatcher;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\EmptyResponse;
class SetSettingsController implements ControllerInterface
{
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)
{
$this->assertAdmin($request->getAttribute('actor'));
$settings = $request->getParsedBody();
foreach ($settings as $k => $v) {
$this->dispatcher->fire(new Serializing($k, $v));
$this->settings->set($k, $v);
$this->dispatcher->fire(new Saved($k, $v));
}
return new EmptyResponse(204);
}
}