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