|
1
|
|
|
<?php namespace Anomaly\Streams\Platform\Stream\Console\Command; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
4
|
|
|
use Anomaly\Streams\Platform\Addon\Addon; |
|
5
|
|
|
use Anomaly\Streams\Platform\Support\Parser; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class WriteEntitySeeder |
|
9
|
|
|
* |
|
10
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
|
11
|
|
|
* @author Ryan Thompson <[email protected]> |
|
12
|
|
|
* |
|
13
|
|
|
* @link http://pyrocms.com/ |
|
14
|
|
|
*/ |
|
15
|
|
|
class WriteEntitySeeder |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The entity slug. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $slug; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The addon instance. |
|
27
|
|
|
* |
|
28
|
|
|
* @var Addon |
|
29
|
|
|
*/ |
|
30
|
|
|
private $addon; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The entity stream namespace. |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
private $namespace; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Create a new WriteEntitySeeder instance. |
|
41
|
|
|
* |
|
42
|
|
|
* @param Addon $addon |
|
43
|
|
|
* @param $slug |
|
44
|
|
|
* @param $namespace |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct(Addon $addon, $slug, $namespace) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->slug = $slug; |
|
49
|
|
|
$this->addon = $addon; |
|
50
|
|
|
$this->namespace = $namespace; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Handle the command. |
|
55
|
|
|
* |
|
56
|
|
|
* @param Parser $parser |
|
57
|
|
|
* @param Filesystem $filesystem |
|
58
|
|
|
*/ |
|
59
|
|
|
public function handle(Parser $parser, Filesystem $filesystem) |
|
60
|
|
|
{ |
|
61
|
|
|
$suffix = ucfirst(camel_case($this->slug)); |
|
62
|
|
|
$entity = str_singular($suffix); |
|
63
|
|
|
|
|
64
|
|
|
$class = "{$entity}Seeder"; |
|
65
|
|
|
$namespace = $this->addon->getTransformedClass("{$entity}"); |
|
66
|
|
|
|
|
67
|
|
|
$path = $this->addon->getPath("src/{$entity}/{$entity}Seeder.php"); |
|
68
|
|
|
|
|
69
|
|
|
$template = $filesystem->get( |
|
70
|
|
|
base_path('vendor/anomaly/streams-platform/resources/stubs/entity/seeder.stub') |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
$filesystem->makeDirectory(dirname($path), 0755, true, true); |
|
74
|
|
|
|
|
75
|
|
|
$filesystem->put($path, $parser->parse($template, compact('class', 'namespace'))); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|