Skip to content

Commit

Permalink
Merge pull request #66 from upmind-automation/65-provision-registry-u…
Browse files Browse the repository at this point in the history
…pdated-event

65 - Provision Registry Cache updated event
  • Loading branch information
uphlewis authored Aug 19, 2024
2 parents 0fedcb5 + 719b2c9 commit 35e2e45
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help
.PHONY: help setup-php81 setup-php82 setup-php83 shell static-analysis start-containers stop-containers kill-containers composer-install

# List all available Makefile commands.
help:
Expand Down Expand Up @@ -38,7 +38,7 @@ start-containers:

# Stop the dev environment
stop-containers:
docker compose down
if [ -f "./docker-compose.yml" ]; then docker compose down; else echo ''; fi

# Stop and remove all containers
kill-containers:
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ parameters:
level: 0
paths:
- src
ignoreErrors:
-
message: '#Required parameter \$parent follows optional parameter#'
path: src/Registry/Data/FunctionRegister.php
10 changes: 10 additions & 0 deletions src/Events/RegistryEventInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Upmind\ProvisionBase\Events;

interface RegistryEventInterface
{
public function getEventName(): string;
}
13 changes: 10 additions & 3 deletions src/Laravel/Console/CacheRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Console\Command;
use Illuminate\Contracts\Cache\Repository as CacheInterface;
use Illuminate\Contracts\Events\Dispatcher as EventDispatcherInterface;
use Upmind\ProvisionBase\Laravel\Events\RegistryUpdatedEvent;
use Upmind\ProvisionBase\Laravel\ProvisionServiceProvider;
use Upmind\ProvisionBase\Registry\Registry;

Expand All @@ -29,9 +31,14 @@ class CacheRegistry extends Command
/**
* Execute the console command.
*/
public function handle(Registry $registry, CacheInterface $cache): int
public function handle(Registry $registry, CacheInterface $cache, EventDispatcherInterface $eventDispatcher): int
{
$this->cacheRegistry($registry, $cache);
$result = $this->cacheRegistry($registry, $cache);

// Dispatch event to notify listeners that the registry has been updated.
if ($result === true) {
$eventDispatcher->dispatch(new RegistryUpdatedEvent());
}

if (!$this->option('without-summary')) {
$this->call('upmind:provision:summary');
Expand All @@ -41,7 +48,7 @@ public function handle(Registry $registry, CacheInterface $cache): int
}

/**
* @return bool Whether or not new registry data was written to cache
* Whether, or not, new registry data was written to cache.
*/
protected function cacheRegistry(Registry $registry, CacheInterface $cache): bool
{
Expand Down
15 changes: 15 additions & 0 deletions src/Laravel/Events/RegistryUpdatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Upmind\ProvisionBase\Laravel\Events;

use Upmind\ProvisionBase\Events\RegistryEventInterface;

class RegistryUpdatedEvent implements RegistryEventInterface
{
public function getEventName(): string
{
return 'ProvisionRegistryUpdated';
}
}

0 comments on commit 35e2e45

Please sign in to comment.