Skip to content
This repository was archived by the owner on Feb 18, 2023. It is now read-only.

Commit 8087c3f

Browse files
committed
#17 remove command bus in favor of Laravel Pipeline class
#16 Upgrade passport to 3.0
1 parent 6ef9d9c commit 8087c3f

File tree

5 files changed

+214
-247
lines changed

5 files changed

+214
-247
lines changed

app/Services/Installation/AppInstallationService.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace App\Services\Installation;
44

5-
use Joselfonseca\LaravelTactician\CommandBusInterface;
6-
use Joselfonseca\LaravelTactician\Middleware\DatabaseTransactions;
5+
use Illuminate\Pipeline\Pipeline;
6+
use Illuminate\Support\Facades\DB;
77

88
/**
99
* Class AppInstallationService
@@ -12,25 +12,19 @@
1212
class AppInstallationService implements AppInstallationServiceContract
1313
{
1414

15-
/**
16-
* @var CommandBusInterface
17-
*/
18-
protected $bus;
15+
protected $pipeline;
1916

2017
/**
2118
* @var array
2219
*/
2320
protected $middleware = [
24-
DatabaseTransactions::class
21+
InstallAppHandler::class
2522
];
2623

27-
/**
28-
* AppInstallationService constructor.
29-
* @param CommandBusInterface $bus
30-
*/
31-
public function __construct(CommandBusInterface $bus)
24+
25+
public function __construct(Pipeline $pipeline)
3226
{
33-
$this->bus = $bus;
27+
$this->pipeline = $pipeline;
3428
}
3529

3630

@@ -40,7 +34,12 @@ public function __construct(CommandBusInterface $bus)
4034
*/
4135
public function installApp(array $installationData = [])
4236
{
43-
$this->bus->addHandler(InstallAppCommand::class, InstallAppHandler::class);
44-
return $this->bus->dispatch(InstallAppCommand::class, $installationData, $this->middleware);
37+
return DB::transaction(function() use ($installationData) {
38+
$this->pipeline->send((object) $installationData)
39+
->through($this->middleware)
40+
->then(function($installation) {
41+
return $installation;
42+
});
43+
});
4544
}
4645
}

app/Services/Installation/InstallAppHandler.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use App\Entities\Role;
66
use App\Entities\User;
77
use App\Entities\Permission;
8-
use App\Services\Installation\Events\ApplicationWasInstalled;
98
use Illuminate\Validation\ValidationException;
9+
use App\Services\Installation\Events\ApplicationWasInstalled;
1010

1111
/**
1212
* Class InstallAppHandler
@@ -57,19 +57,20 @@ public function __construct()
5757
$this->permissions = collect($this->permissions);
5858
}
5959

60+
6061
/**
61-
* @param InstallAppCommand $command
62+
* @param $installationData
6263
* @return $this
6364
*/
64-
public function handle(InstallAppCommand $command)
65+
public function handle($installationData)
6566
{
6667
$this->createRoles()
6768
->createPermissions()
68-
->createAdminUser((array) $command)
69+
->createAdminUser((array) $installationData)
6970
->assignAdminRoleToAdminUser()
7071
->assignAllPermissionsToAdminRole();
7172
event(new ApplicationWasInstalled($this->adminUser, $this->roles, $this->permissions));
72-
return $this;
73+
return $installationData;
7374
}
7475

7576
/**

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"require": {
1616
"php": ">=7.0.0",
1717
"laravel/framework": "5.4.*",
18-
"laravel/passport": "^2.0",
19-
"joselfonseca/laravel-tactician": "0.3.*",
18+
"laravel/passport": "^3.0",
2019
"laravel/tinker": "~1.0",
2120
"predis/predis": "^1.1",
2221
"dingo/api": "1.0.*@dev",

0 commit comments

Comments
 (0)