Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changing model events to use observer classes
- Loading branch information
1 parent
cf4b731
commit 6536878
Showing
54 changed files
with
925 additions
and
654 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/Listeners/CreateJwt.php → app/Events/Listeners/CreateJwt.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Listeners/SendEmailChangeConfirmation.php → ...Listeners/SendEmailChangeConfirmation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/Listeners/SendSignupEmail.php → app/Events/Listeners/SendSignupEmail.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/Listeners/TestProjectUrls.php → app/Events/Listeners/TestProjectUrls.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace REBELinBLUE\Deployer\Events\Observers; | ||
|
||
use Illuminate\Contracts\Translation\Translator; | ||
use REBELinBLUE\Deployer\Channel; | ||
use REBELinBLUE\Deployer\Notifications\System\NewTestNotification; | ||
|
||
/** | ||
* Event observer for Channel model. | ||
*/ | ||
class ChannelObserver | ||
{ | ||
/** | ||
* @var Translator | ||
*/ | ||
private $translator; | ||
|
||
/** | ||
* @param Translator $translator | ||
*/ | ||
public function __construct(Translator $translator) | ||
{ | ||
$this->translator = $translator; | ||
} | ||
|
||
/** | ||
* Called when the model is saved. | ||
* | ||
* @param Channel $channel | ||
*/ | ||
public function saved(Channel $channel) | ||
{ | ||
$channel->notify(new NewTestNotification($this->translator)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace REBELinBLUE\Deployer\Events\Observers; | ||
|
||
use Illuminate\Contracts\Events\Dispatcher; | ||
use Illuminate\Foundation\Bus\DispatchesJobs; | ||
use Illuminate\Support\Collection; | ||
use REBELinBLUE\Deployer\CheckUrl; | ||
use REBELinBLUE\Deployer\Events\UrlDown as UrlDownEvent; | ||
use REBELinBLUE\Deployer\Events\UrlUp as UrlUpEvent; | ||
use REBELinBLUE\Deployer\Jobs\RequestProjectCheckUrl; | ||
|
||
/** | ||
* Event observer for CheckUrl model. | ||
*/ | ||
class CheckUrlObserver | ||
{ | ||
use DispatchesJobs; | ||
|
||
/** | ||
* @var Dispatcher | ||
*/ | ||
private $dispatcher; | ||
|
||
/** | ||
* @param Dispatcher $dispatcher | ||
*/ | ||
public function __construct(Dispatcher $dispatcher) | ||
{ | ||
$this->dispatcher = $dispatcher; | ||
} | ||
|
||
/** | ||
* Called when the model is saved. | ||
* | ||
* @param CheckUrl $url | ||
*/ | ||
public function saved(CheckUrl $url) | ||
{ | ||
if ($url->status === CheckUrl::UNTESTED) { | ||
$collection = new Collection([$url]); | ||
|
||
$this->dispatch(new RequestProjectCheckUrl($collection)); | ||
} | ||
} | ||
|
||
/** | ||
* Called when the model is updated. | ||
* | ||
* @param CheckUrl $url | ||
*/ | ||
public function updated(CheckUrl $url) | ||
{ | ||
if ($url->status === CheckUrl::OFFLINE) { | ||
$this->dispatcher->dispatch(new UrlDownEvent($url)); | ||
} elseif ($url->status === CheckUrl::ONLINE && $url->getOriginal('status') === CheckUrl::OFFLINE) { | ||
$this->dispatcher->dispatch(new UrlUpEvent($url)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace REBELinBLUE\Deployer\Events\Observers; | ||
|
||
use REBELinBLUE\Deployer\Heartbeat; | ||
|
||
/** | ||
* Event observer for Heartbeat model. | ||
*/ | ||
class HeartbeatObserver | ||
{ | ||
/** | ||
* Called when the model is being created. | ||
* | ||
* @param Heartbeat $heartbeat | ||
*/ | ||
public function creating(Heartbeat $heartbeat) | ||
{ | ||
if (empty($heartbeat->hash)) { | ||
$heartbeat->generateHash(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace REBELinBLUE\Deployer\Events\Observers; | ||
|
||
use Illuminate\Foundation\Bus\DispatchesJobs; | ||
use REBELinBLUE\Deployer\Jobs\GenerateKey; | ||
use REBELinBLUE\Deployer\Jobs\RegeneratePublicKey; | ||
use REBELinBLUE\Deployer\Project; | ||
|
||
/** | ||
* Event observer for Project model. | ||
*/ | ||
class ProjectObserver | ||
{ | ||
use DispatchesJobs; | ||
|
||
/** | ||
* Called when the model is being created. | ||
* | ||
* @param Project $project | ||
*/ | ||
public function creating(Project $project) | ||
{ | ||
if (empty($project->private_key)) { | ||
$this->dispatch(new GenerateKey($project)); | ||
} elseif (empty($project->public_key)) { | ||
$this->dispatch(new RegeneratePublicKey($project)); | ||
} | ||
|
||
if (empty($project->hash)) { | ||
$project->generateHash(); | ||
} | ||
} | ||
|
||
/** | ||
* Called when the model is being updated. | ||
* | ||
* @param Project $project | ||
*/ | ||
public function updating(Project $project) | ||
{ | ||
if (empty($project->public_key)) { | ||
$this->dispatch(new RegeneratePublicKey($project)); | ||
} | ||
} | ||
} |
Oops, something went wrong.