Added Component events and handlers

This commit is contained in:
James Brooks
2015-08-16 13:50:11 +01:00
parent 5bc7a3e6f7
commit 30eec9da24
4 changed files with 145 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Events\Metric;
use CachetHQ\Cachet\Models\Component;
class ComponentWasAddedEvent
{
/**
* The component that was added.
*
* @var \CachetHQ\Cachet\Models\Component
*/
public $component;
/**
* Create a new component was added event instance.
*
* @return void
*/
public function __construct(Component $component)
{
$this->component = $component;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Events\Metric;
use CachetHQ\Cachet\Models\Component;
class ComponentWasRemovedEvent
{
/**
* The component that was removed.
*
* @var \CachetHQ\Cachet\Models\Component
*/
public $component;
/**
* Create a new component was removed event instance.
*
* @return void
*/
public function __construct(Component $component)
{
$this->component = $component;
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Handlers\Commands\Component;
use CachetHQ\Cachet\Commands\Component\AddComponentCommand;
use CachetHQ\Cachet\Events\Component\ComponentWasAddedEvent;
use CachetHQ\Cachet\Models\Component;
class AddComponentHandler
{
/**
* Handle the add component command.
*
* @param \CachetHQ\Cachet\Commands\Component\AddComponentCommand $command
*
* @return void
*/
public function handle(AddComponentCommand $command)
{
$component = Component::create([
'name' => $command->name,
'description' => $command->description,
'link' => $command->link,
'status' => $command->status,
'order' => $command->order,
'group_id' => $command->group_id,
]);
event(new ComponentWasAddedEvent($component));
return $component;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Handlers\Commands\Component;
use CachetHQ\Cachet\Commands\Component\RemoveComponentCommand;
use CachetHQ\Cachet\Events\Component\ComponentWasAddedEvent;
use CachetHQ\Cachet\Models\Component;
class RemoveComponentHandler
{
/**
* Handle the remove component command.
*
* @param \CachetHQ\Cachet\Commands\Component\RemoveComponentCommand $command
*
* @return void
*/
public function handle(RemoveComponentCommand $command)
{
$component = $command->component;
event(new ComponentWasRemovedEvent($component));
$component->delete();
}
}