Completed
Push — master ( e377ec...621e91 )
by Ryan
07:42
created

GetFormCriteria::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace Anomaly\Streams\Platform\Ui\Form\Command;
2
3
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
4
use Anomaly\Streams\Platform\Support\Presenter;
5
use Anomaly\Streams\Platform\Ui\Form\FormCriteria;
6
use Anomaly\Streams\Platform\Ui\Form\FormFactory;
7
use Illuminate\Contracts\Bus\SelfHandling;
8
9
/**
10
 * Class GetFormCriteria
11
 *
12
 * @link          http://anomaly.is/streams-platform
13
 * @author        AnomalyLabs, Inc. <[email protected]>
14
 * @author        Ryan Thompson <[email protected]>
15
 * @package       Anomaly\Streams\Platform\Ui\Form\Command
16
 */
17
class GetFormCriteria implements SelfHandling
18
{
19
20
    /**
21
     * The builder parameters.
22
     *
23
     * @var array
24
     */
25
    protected $parameters;
26
27
    /**
28
     * Create a new GetFormCriteria instance.
29
     *
30
     * @param array $parameters
31
     */
32
    public function __construct($parameters)
33
    {
34
        $this->parameters = $parameters;
35
    }
36
37
    /**
38
     * Handle the command.
39
     *
40
     * @param FormFactory $factory
41
     * @return FormCriteria
42
     */
43
    public function handle(FormFactory $factory)
44
    {
45
        if (is_string($this->parameters)) {
46
            $this->parameters = [
47
                'builder' => $this->parameters
48
            ];
49
        }
50
51
        if ($this->parameters instanceof Presenter) {
52
            $this->parameters = $this->parameters->getObject();
53
        }
54
55
        if ($this->parameters instanceof EntryInterface) {
56
            $this->parameters = [
57
                'entry'     => $this->parameters->getId(),
58
                'stream'    => $this->parameters->getStreamSlug(),
59
                'namespace' => $this->parameters->getStreamNamespace(),
60
            ];
61
        }
62
63
        return $factory->make($this->parameters);
64
    }
65
}
66