1
|
|
|
<?php namespace Anomaly\UsersModule\Seeder; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Database\Seeder\Seeder; |
4
|
|
|
use Anomaly\UsersModule\Role\Contract\RoleRepositoryInterface; |
5
|
|
|
use Anomaly\UsersModule\User\Contract\UserInterface; |
6
|
|
|
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface; |
7
|
|
|
use Anomaly\UsersModule\User\UserActivator; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class UserSeeder |
11
|
|
|
* |
12
|
|
|
* @link http://pyrocms.com/ |
13
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
14
|
|
|
* @author Ryan Thompson <[email protected]> |
15
|
|
|
* @package Anomaly\UsersModule\Seeder |
16
|
|
|
*/ |
17
|
|
|
class UserSeeder extends Seeder |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The user repository. |
22
|
|
|
* |
23
|
|
|
* @var UserRepositoryInterface |
24
|
|
|
*/ |
25
|
|
|
protected $users; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The role repository. |
29
|
|
|
* |
30
|
|
|
* @var RoleRepositoryInterface |
31
|
|
|
*/ |
32
|
|
|
protected $roles; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The activator utility. |
36
|
|
|
* |
37
|
|
|
* @var UserActivator |
38
|
|
|
*/ |
39
|
|
|
protected $activator; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Create a new UserSeeder instance. |
43
|
|
|
* |
44
|
|
|
* @param UserRepositoryInterface $users |
45
|
|
|
* @param RoleRepositoryInterface $roles |
46
|
|
|
* @param UserActivator $activator |
47
|
|
|
*/ |
48
|
|
|
public function __construct( |
49
|
|
|
UserRepositoryInterface $users, |
50
|
|
|
RoleRepositoryInterface $roles, |
51
|
|
|
UserActivator $activator |
52
|
|
|
) { |
53
|
|
|
$this->users = $users; |
54
|
|
|
$this->roles = $roles; |
55
|
|
|
$this->activator = $activator; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Run the seeder. |
60
|
|
|
*/ |
61
|
|
|
public function run() |
62
|
|
|
{ |
63
|
|
|
$this->users->truncate(); |
64
|
|
|
|
65
|
|
|
$admin = $this->roles->findBySlug('admin'); |
66
|
|
|
$user = $this->roles->findBySlug('user'); |
67
|
|
|
|
68
|
|
|
/* @var UserInterface $administrator */ |
69
|
|
|
$administrator = $this->users->create( |
70
|
|
|
[ |
71
|
|
|
'display_name' => 'Administrator', |
72
|
|
|
'email' => env('ADMIN_EMAIL'), |
73
|
|
|
'username' => env('ADMIN_USERNAME'), |
74
|
|
|
'password' => env('ADMIN_PASSWORD') |
75
|
|
|
] |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
/* @var UserInterface $demo */ |
79
|
|
|
$demo = $this->users->create( |
80
|
|
|
[ |
81
|
|
|
'display_name' => 'Demo User', |
82
|
|
|
'email' => '[email protected]', |
83
|
|
|
'password' => 'password', |
84
|
|
|
'username' => 'demo' |
85
|
|
|
] |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$demo->roles()->sync([$user->getId()]); |
89
|
|
|
$administrator->roles()->sync([$admin->getId()]); |
90
|
|
|
|
91
|
|
|
$this->activator->force($demo); |
92
|
|
|
$this->activator->force($administrator); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|