Skip to content

Commit 0c50ad4

Browse files
committed
Added event subscribers and few methods for CacheableRepository trait
1 parent 60611fe commit 0c50ad4

12 files changed

+151
-72
lines changed

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
}
2121
],
2222
"require": {
23-
"illuminate/http": "~5.0|~6.0|~7.0|^8.0|^9.0",
24-
"illuminate/config": "~5.0|~6.0|~7.0|^8.0|^9.0",
25-
"illuminate/support": "~5.0|~6.0|~7.0|^8.0|^9.0",
26-
"illuminate/database": "~5.0|~6.0|~7.0|^8.0|^9.0",
27-
"illuminate/pagination": "~5.0|~6.0|~7.0|^8.0|^9.0",
28-
"illuminate/console": "~5.0|~6.0|~7.0|^8.0|^9.0",
29-
"illuminate/filesystem": "~5.0|~6.0|~7.0|^8.0|^9.0",
30-
"illuminate/validation": "~5.0|~6.0|~7.0|^8.0|^9.0"
23+
"illuminate/http": "~6.0|~7.0|^8.0|^9.0",
24+
"illuminate/config": "~6.0|~7.0|^8.0|^9.0",
25+
"illuminate/support": "~6.0|~7.0|^8.0|^9.0",
26+
"illuminate/database": "~6.0|~7.0|^8.0|^9.0",
27+
"illuminate/pagination": "~6.0|~7.0|^8.0|^9.0",
28+
"illuminate/console": "~6.0|~7.0|^8.0|^9.0",
29+
"illuminate/filesystem": "~6.0|~7.0|^8.0|^9.0",
30+
"illuminate/validation": "~6.0|~7.0|^8.0|^9.0"
3131
},
3232
"require-dev": {
3333
"orchestra/testbench": "^4.0|^5.0|^6.0",

src/CacheRepositoryServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ class CacheRepositoryServiceProvider extends ServiceProvider
88
{
99
public function boot()
1010
{
11+
$this->mergeConfigFrom(__DIR__.'/../config/repository.php', 'repository');
12+
}
1113

14+
public function register()
15+
{
16+
$this->app->register(EventServiceProvider::class);
1217
}
1318
}

src/EventServiceProvider.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace CodeOfDigital\CacheRepository;
4+
5+
use CodeOfDigital\CacheRepository\Listeners\RepositoryEventSubscriber;
6+
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
7+
8+
class EventServiceProvider extends ServiceProvider
9+
{
10+
protected $listen = [];
11+
12+
protected $subscribe = [
13+
RepositoryEventSubscriber::class
14+
];
15+
}

src/Events/RepositoryEntityCreated.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44

55
class RepositoryEntityCreated extends RepositoryEventBase
66
{
7-
/**
8-
* @var string
9-
*/
10-
protected $action = "created";
7+
protected string $action = "created";
118
}

src/Events/RepositoryEntityCreating.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,7 @@
22

33
namespace CodeOfDigital\CacheRepository\Events;
44

5-
use Illuminate\Database\Eloquent\Model;
6-
use CodeOfDigital\CacheRepository\Contracts\RepositoryInterface;
7-
8-
/**
9-
* Class RepositoryEntityCreated
10-
*
11-
* @package Prettus\Repository\Events
12-
* @author Anderson Andrade <contato@andersonandra.de>
13-
*/
145
class RepositoryEntityCreating extends RepositoryEventBase
156
{
16-
/**
17-
* @var string
18-
*/
19-
protected $action = "creating";
20-
21-
public function __construct(RepositoryInterface $repository, array $model)
22-
{
23-
parent::__construct($repository);
24-
$this->model = $model;
25-
}
7+
protected string $action = "creating";
268
}
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
<?php
2-
namespace Prettus\Repository\Events;
32

4-
/**
5-
* Class RepositoryEntityDeleted
6-
* @package Prettus\Repository\Events
7-
* @author Anderson Andrade <contato@andersonandra.de>
8-
*/
3+
namespace CodeOfDigital\CacheRepository\Events;
4+
95
class RepositoryEntityDeleted extends RepositoryEventBase
106
{
11-
/**
12-
* @var string
13-
*/
14-
protected $action = "deleted";
7+
protected string $action = "deleted";
158
}
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
<?php
2-
namespace Prettus\Repository\Events;
32

4-
/**
5-
* Class RepositoryEntityDeleted
6-
* @package Prettus\Repository\Events
7-
* @author Anderson Andrade <contato@andersonandra.de>
8-
*/
3+
namespace CodeOfDigital\CacheRepository\Events;
4+
95
class RepositoryEntityDeleting extends RepositoryEventBase
106
{
11-
/**
12-
* @var string
13-
*/
14-
protected $action = "deleting";
7+
protected string $action = "deleting";
158
}

src/Events/RepositoryEntityUpdated.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
namespace CodeOfDigital\CacheRepository\Events;
44

5-
/**
6-
* Class RepositoryEntityUpdated
7-
* @package Prettus\Repository\Events
8-
* @author Anderson Andrade <contato@andersonandra.de>
9-
*/
105
class RepositoryEntityUpdated extends RepositoryEventBase
116
{
127
protected string $action = "updated";

src/Events/RepositoryEntityUpdating.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
namespace CodeOfDigital\CacheRepository\Events;
44

5-
/**
6-
* Class RepositoryEntityUpdated
7-
* @package Prettus\Repository\Events
8-
* @author Anderson Andrade <contato@andersonandra.de>
9-
*/
105
class RepositoryEntityUpdating extends RepositoryEventBase
116
{
127
protected string $action = "updating";

src/Helpers/CacheKeys.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function putKey($group, $key): void
1919
self::storeKeys();
2020
}
2121

22-
public static function loadKeys()
22+
public static function loadKeys(): array
2323
{
2424
if (!empty(self::$keys)) {
2525
return self::$keys;
@@ -51,7 +51,7 @@ public static function storeKeys(): bool|int
5151
return file_put_contents($file, $content);
5252
}
5353

54-
public static function getKeys($group)
54+
public static function getKeys($group): array
5555
{
5656
self::loadKeys();
5757
self::$keys[$group] = self::$keys[$group] ?? [];

0 commit comments

Comments
 (0)