Added Component events and handlers
This commit is contained in:
34
app/Events/Component/ComponentWasAddedEvent.php
Normal file
34
app/Events/Component/ComponentWasAddedEvent.php
Normal 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;
|
||||
}
|
||||
}
|
||||
34
app/Events/Component/ComponentWasRemovedEvent.php
Normal file
34
app/Events/Component/ComponentWasRemovedEvent.php
Normal 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;
|
||||
}
|
||||
}
|
||||
42
app/Handlers/Commands/Component/AddComponentHandler.php
Normal file
42
app/Handlers/Commands/Component/AddComponentHandler.php
Normal 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;
|
||||
}
|
||||
}
|
||||
35
app/Handlers/Commands/Component/RemoveComponentHandler.php
Normal file
35
app/Handlers/Commands/Component/RemoveComponentHandler.php
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user