Passed
Push — master ( f3eaf1...0fde80 )
by Reza
04:06
created

BaseInput::setKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace EasyPanel\Parsers\HTMLInputs;
4
5
abstract class BaseInput
6
{
7
    protected $key;
8
    protected $action;
9
    protected $mode;
10
    protected $label;
11
    protected $placeholder;
12
    protected $inputStyle;
13
    protected $autocomplete = 'on';
14
15
    public function __construct($label)
16
    {
17
        $this->label = $label;
18
        $this->mode = config('easy_panel.lazy_mode') ? 'wire:model.lazy' : 'wire:model';
19
    }
20
21
    public static function label($label)
22
    {
23
        return new static($label);
24
    }
25
26
    public function inputStyle($inputStyle)
27
    {
28
        $this->inputStyle = $inputStyle;
29
30
        return $this;
31
    }
32
33
    public function setKey($key)
34
    {
35
        $this->key = $key;
36
37
        return $this;
38
    }
39
40
    public function setAction($action)
41
    {
42
        $this->action = $action;
43
44
        return $this;
45
    }
46
47
    public function placeholder($placeholder)
48
    {
49
        $this->placeholder = $placeholder;
50
51
        return $this;
52
    }
53
54
    public function lazyMode()
55
    {
56
        $this->mode = 'wire:model.lazy';
57
58
        return $this;
59
    }
60
61
    public function deferMode()
62
    {
63
        $this->mode = 'wire:model.defer';
64
65
        return $this;
66
    }
67
68
    public function withoutAutocomplete()
69
    {
70
        $this->autocomplete = 'off';
71
72
        return $this;
73
    }
74
75
    public function withoutAutofill()
76
    {
77
        $this->withoutAutocomplete();
78
79
        return $this;
80
    }
81
82
    public function render()
83
    {
84
        $array = [
85
            '{{ Title }}' => $this->label,
86
            '{{ Name }}' => $this->key,
87
            '{{ Mode }}' => $this->mode,
88
            '{{ Action }}' => $this->action,
89
            '{{ placeholder }}' => $this->placeholder,
90
            '{{ inputStyle }}' => $this->inputStyle,
91
            '{{ autocomplete }}' => $this->autocomplete,
92
        ];
93
94
        return str_replace(array_keys($array), array_values($array), file_get_contents(__DIR__.'/stubs/'.$this->stub));
95
    }
96
97
    public function getTitle()
98
    {
99
        return $this->label;
100
    }
101
102
    public function getPlaceholder()
103
    {
104
        return $this->placeholder;
105
    }
106
107
}
108