Filter component elements that aren't set

This commit is contained in:
James Brooks
2015-10-17 09:59:43 +01:00
parent 654c0265aa
commit 49e4113159
2 changed files with 8 additions and 20 deletions

View File

@@ -26,14 +26,14 @@ class AddComponentCommandHandler
*/
public function handle(AddComponentCommand $command)
{
$component = Component::create([
$component = Component::create(array_filter([
'name' => $command->name,
'description' => $command->description,
'link' => $command->link,
'status' => $command->status,
'order' => $command->order,
'group_id' => $command->group_id,
]);
]));
event(new ComponentWasAddedEvent($component));

View File

@@ -27,29 +27,17 @@ class UpdateComponentCommandHandler
public function handle(UpdateComponentCommand $command)
{
$component = $command->component;
$component->update($this->filterComponentData($command));
event(new ComponentWasUpdatedEvent($component));
return $component;
}
/**
* Filter the command data.
*
* @param \CachetHQ\Cachet\Commands\Component\UpdateComponentCommand $command
*
* @return array
*/
protected function filterComponentData($command)
{
return array_filter([
$component->update(array_filter([
'name' => $command->name,
'description' => $command->description,
'link' => $command->link,
'status' => $command->status,
'order' => $command->order,
'group_id' => $command->group_id,
]);
]));
event(new ComponentWasUpdatedEvent($component));
return $component;
}
}