Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event action system #2346

Merged
merged 2 commits into from
Feb 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/Bus/Events/ActionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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\Bus\Events;

/**
* This is the action interface.
*
* @author Graham Campbell <[email protected]>
* @author James Brooks <[email protected]>
*/
interface ActionInterface
{
/**
* Get the event action.
*
* @return array
*/
public function getAction();
}
6 changes: 6 additions & 0 deletions app/Bus/Events/Component/ComponentEventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

use CachetHQ\Cachet\Bus\Events\EventInterface;

/**
* This is the component event interface.
*
* @author Graham Campbell <[email protected]>
* @author James Brooks <[email protected]>
*/
interface ComponentEventInterface extends EventInterface
{
//
Expand Down
28 changes: 26 additions & 2 deletions app/Bus/Events/Component/ComponentStatusWasUpdatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@

namespace CachetHQ\Cachet\Bus\Events\Component;

use CachetHQ\Cachet\Bus\Events\ActionInterface;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\User;

/**
* This is the component status was updated event.
*
* @author James Brooks <[email protected]>
*/
final class ComponentStatusWasUpdatedEvent implements ComponentEventInterface
final class ComponentStatusWasUpdatedEvent implements ActionInterface, ComponentEventInterface
{
/**
* The user who updated the component.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;

/**
* The component that was updated.
*
Expand All @@ -44,14 +53,16 @@ final class ComponentStatusWasUpdatedEvent implements ComponentEventInterface
/**
* Create a new component was updated event instance.
*
* @param \CachetHQ\Cachet\Models\User $user
* @param \CachetHQ\Cachet\Models\Component $component
* @param int $original_status
* @param int $new_status
*
* @return void
*/
public function __construct(Component $component, $original_status, $new_status)
public function __construct(User $user, Component $component, $original_status, $new_status)
{
$this->user = $user;
$this->component = $component;
$this->original_status = $original_status;
$this->new_status = $new_status;
Expand All @@ -66,4 +77,17 @@ public function __toString()
{
return 'Component status was updated.';
}

/**
* Get the event action.
*
* @return array
*/
public function getAction()
{
return [
'user' => $this->user,
'description' => (string) $this,
];
}
}
28 changes: 26 additions & 2 deletions app/Bus/Events/Component/ComponentWasAddedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@

namespace CachetHQ\Cachet\Bus\Events\Component;

use CachetHQ\Cachet\Bus\Events\ActionInterface;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\User;

final class ComponentWasAddedEvent implements ComponentEventInterface
final class ComponentWasAddedEvent implements ActionInterface, ComponentEventInterface
{
/**
* The user who added the component.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;

/**
* The component that was added.
*
Expand All @@ -25,12 +34,14 @@ final class ComponentWasAddedEvent implements ComponentEventInterface
/**
* Create a new component was added event instance.
*
* @param \CachetHQ\Cachet\Models\User $user
* @param \CachetHQ\Cachet\Models\Component $component
*
* @return void
*/
public function __construct(Component $component)
public function __construct(User $user, Component $component)
{
$this->user = $user;
$this->component = $component;
}

Expand All @@ -43,4 +54,17 @@ public function __toString()
{
return 'Component was added.';
}

/**
* Get the event action.
*
* @return array
*/
public function getAction()
{
return [
'user' => $this->user,
'description' => (string) $this,
];
}
}
33 changes: 31 additions & 2 deletions app/Bus/Events/Component/ComponentWasRemovedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,24 @@

namespace CachetHQ\Cachet\Bus\Events\Component;

use CachetHQ\Cachet\Bus\Events\ActionInterface;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\User;

final class ComponentWasRemovedEvent implements ComponentEventInterface
/**
* This is the component was removed event class.
*
* @author James Brooks <[email protected]>
*/
final class ComponentWasRemovedEvent implements ActionInterface, ComponentEventInterface
{
/**
* The user who removed the component.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;

/**
* The component that was removed.
*
Expand All @@ -25,12 +39,14 @@ final class ComponentWasRemovedEvent implements ComponentEventInterface
/**
* Create a new component was removed event instance.
*
* @param \CachetHQ\Cachet\Models\User $user
* @param \CachetHQ\Cachet\Models\Component $component
*
* @return void
*/
public function __construct(Component $component)
public function __construct(User $user, Component $component)
{
$this->user = $user;
$this->component = $component;
}

Expand All @@ -43,4 +59,17 @@ public function __toString()
{
return 'Component was removed.';
}

/**
* Get the event action.
*
* @return array
*/
public function getAction()
{
return [
'user' => $this->user,
'description' => (string) $this,
];
}
}
28 changes: 26 additions & 2 deletions app/Bus/Events/Component/ComponentWasUpdatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@

namespace CachetHQ\Cachet\Bus\Events\Component;

use CachetHQ\Cachet\Bus\Events\ActionInterface;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\User;

/**
* This is the component was updated event class.
*
* @author James Brooks <[email protected]>
* @author Graham Campbell <[email protected]>
*/
final class ComponentWasUpdatedEvent implements ComponentEventInterface
final class ComponentWasUpdatedEvent implements ActionInterface, ComponentEventInterface
{
/**
* The user who updated the component.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;

/**
* The component that was updated.
*
Expand All @@ -31,12 +40,14 @@ final class ComponentWasUpdatedEvent implements ComponentEventInterface
/**
* Create a new component was updated event instance.
*
* @param \CachetHQ\Cachet\Models\User $user
* @param \CachetHQ\Cachet\Models\Component $component
*
* @return void
*/
public function __construct(Component $component)
public function __construct(User $user, Component $component)
{
$this->user = $user;
$this->component = $component;
}

Expand All @@ -49,4 +60,17 @@ public function __toString()
{
return 'Component was updated.';
}

/**
* Get the event action.
*
* @return array
*/
public function getAction()
{
return [
'user' => $this->user,
'description' => (string) $this,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

use CachetHQ\Cachet\Bus\Events\EventInterface;

/**
* This is the component group event interface.
*
* @author Graham Campbell <[email protected]>
* @author James Brooks <[email protected]>
*/
interface ComponentGroupEventInterface extends EventInterface
{
//
Expand Down
28 changes: 26 additions & 2 deletions app/Bus/Events/ComponentGroup/ComponentGroupWasAddedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@

namespace CachetHQ\Cachet\Bus\Events\ComponentGroup;

use CachetHQ\Cachet\Bus\Events\ActionInterface;
use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\User;

final class ComponentGroupWasAddedEvent implements ComponentGroupEventInterface
final class ComponentGroupWasAddedEvent implements ActionInterface, ComponentGroupEventInterface
{
/**
* The user who added the component group.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;

/**
* The component group that was added.
*
Expand All @@ -25,12 +34,14 @@ final class ComponentGroupWasAddedEvent implements ComponentGroupEventInterface
/**
* Create a new component group was added event instance.
*
* @param \CachetHQ\Cachet\Models\User $group
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
*
* @return void
*/
public function __construct(ComponentGroup $group)
public function __construct(User $user, ComponentGroup $group)
{
$this->user = $user;
$this->group = $group;
}

Expand All @@ -43,4 +54,17 @@ public function __toString()
{
return 'Component Group was added.';
}

/**
* Get the event action.
*
* @return array
*/
public function getAction()
{
return [
'user' => $this->user,
'description' => (string) $this,
];
}
}
Loading