1
|
|
|
<?php namespace Anomaly\Streams\Platform\Database\Seeder; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Assignment\Contract\AssignmentRepositoryInterface; |
4
|
|
|
use Anomaly\Streams\Platform\Field\Contract\FieldRepositoryInterface; |
5
|
|
|
use Anomaly\Streams\Platform\Stream\Contract\StreamRepositoryInterface; |
6
|
|
|
use Illuminate\Database\Seeder as BaseSeeder; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class Seeder |
10
|
|
|
* |
11
|
|
|
* @link http://anomaly.is/streams-platform |
12
|
|
|
* @author AnomalyLabs, Inc. <[email protected]> |
13
|
|
|
* @author Ryan Thompson <[email protected]> |
14
|
|
|
* @package Anomaly\Streams\Platform\Database\Seeder |
15
|
|
|
*/ |
16
|
|
|
class Seeder extends BaseSeeder |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The field repository. |
21
|
|
|
* |
22
|
|
|
* @var FieldRepositoryInterface $fields |
23
|
|
|
*/ |
24
|
|
|
protected $fields; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The stream repository. |
28
|
|
|
* |
29
|
|
|
* @var StreamRepositoryInterface $streams |
30
|
|
|
*/ |
31
|
|
|
protected $streams; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The assignment repository. |
35
|
|
|
* |
36
|
|
|
* @var AssignmentRepositoryInterface $assignments |
37
|
|
|
*/ |
38
|
|
|
protected $assignments; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The environment this seeder |
42
|
|
|
* applies too if any. |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected $env = null; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Create a new Seeder instance. |
50
|
|
|
*/ |
51
|
|
|
public function __construct() |
52
|
|
|
{ |
53
|
|
|
$this->fields = app(FieldRepositoryInterface::class); |
54
|
|
|
$this->streams = app(StreamRepositoryInterface::class); |
55
|
|
|
$this->assignments = app(AssignmentRepositoryInterface::class); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Seed the given connection from the given path. |
60
|
|
|
* |
61
|
|
|
* @param string $class |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function call($class) |
66
|
|
|
{ |
67
|
|
|
/** @var Seeder $seeder */ |
68
|
|
|
$seeder = $this->resolve($class); |
69
|
|
|
$env = method_exists($seeder, 'isEnvironment') ? $seeder->isEnvironment() : null; |
70
|
|
|
|
71
|
|
|
$seeder->setCommand($this->command); |
72
|
|
|
|
73
|
|
|
if ($env !== false) { |
74
|
|
|
$seeder->run(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$this->command->getOutput()->writeln("<info>Seeded:</info> $class"); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Return whether the seeder applies to |
82
|
|
|
* the current environment or not. |
83
|
|
|
* |
84
|
|
|
* @return bool|null |
85
|
|
|
*/ |
86
|
|
|
public function isEnvironment() |
87
|
|
|
{ |
88
|
|
|
return $this->env ? ($this->env === env('APP_ENV')) : null; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|