1
0
mirror of https://github.com/flarum/core.git synced 2025-10-12 23:44:27 +02:00

Refactor translation and validation

We now use Symfony's Translation component. Yay! We get more powerful pluralisation and better a fallback mechanism. Will want to implement the caching mechanism at some point too. The API is replicated in JavaScript, which could definitely use some testing.

Validators have been refactored so that they are decoupled from models completely (i.e. they simply validate arrays of user input). Language packs should include Laravel's validation messages.

ref #267
This commit is contained in:
Toby Zerner
2015-10-15 22:30:45 +10:30
parent a23180f279
commit c08b62af80
32 changed files with 578 additions and 4096 deletions

View File

@@ -14,6 +14,7 @@ use Exception;
use Flarum\Core\Access\AssertPermissionTrait;
use Flarum\Core\Discussion;
use Flarum\Core\Support\DispatchEventsTrait;
use Flarum\Core\Validator\DiscussionValidator;
use Flarum\Event\DiscussionWillBeSaved;
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
@@ -28,15 +29,22 @@ class StartDiscussionHandler
*/
protected $bus;
/**
* @var DiscussionValidator
*/
protected $validator;
/**
* @param EventDispatcher $events
* @param BusDispatcher $bus
* @param DiscussionValidator $validator
* @internal param Forum $forum
*/
public function __construct(EventDispatcher $events, BusDispatcher $bus)
public function __construct(EventDispatcher $events, BusDispatcher $bus, DiscussionValidator $validator)
{
$this->events = $events;
$this->bus = $bus;
$this->validator = $validator;
}
/**
@@ -64,6 +72,8 @@ class StartDiscussionHandler
new DiscussionWillBeSaved($discussion, $actor, $data)
);
$this->validator->assertValid($discussion->getAttributes());
$discussion->save();
// Now that the discussion has been created, we can add the first post.