Issues (6)

src/IndexPage/Actions/AbstractInlineAction.php (1 issue)

1
<?php
2
3
4
namespace UserAdmin\IndexPage\Actions;
5
6
use Illuminate\Support\Str;
7
8
abstract class AbstractInlineAction
9
{
10
    public string $name;
11
12
    public bool $confirmable = false;
13
14
    public string $icon = '';
15
16
    public string $title = '';
17
18
    abstract public function component(): string;
19
20
    /**
21
     * AbstractInlineAction constructor.
22
     *
23
     * @param ...$args - (string $title, string $field, ....)
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
24
     *
25
     * @throws \Exception
26
     */
27 1
    public function __construct(...$args)
28
    {
29 1
        if (empty($args[0]) || !is_string($args[0])) {
30
            throw new \Exception('Please specify action unique name');
31
        }
32
33 1
        $this->name  = $args[0];
34 1
        $this->title = Str::title(Str::snake($this->name, ' '));
35 1
        $this->icon  = Str::limit($this->title, 3);
36 1
    }
37
38
    /**
39
     * @return string
40
     */
41 1
    public function name():string
42
    {
43 1
        return $this->name;
44
    }
45
46
    /**
47
     * Set confirmable.
48
     *
49
     * @param bool $confirmable
50
     *
51
     * @return $this
52
     */
53
    public function confirmable(bool $confirmable = true): self
54
    {
55
        $this->confirmable = $confirmable;
56
57
        return $this;
58
    }
59
60
    /**
61
     * @param string $icon
62
     *
63
     * @return AbstractInlineAction
64
     */
65 1
    public function setIcon(string $icon): self
66
    {
67 1
        $this->icon = $icon;
68
69 1
        return $this;
70
    }
71
72
    /**
73
     * @param string $title
74
     *
75
     * @return AbstractInlineAction
76
     */
77 1
    public function setTitle(string $title): self
78
    {
79 1
        $this->title = $title;
80
81 1
        return $this;
82
    }
83
84
    /**
85
     * Get custom global data.
86
     *
87
     * @return  mixed
88
     */
89
    public function customGlobalData():array
90
    {
91
        return [];
92
    }
93
94
    /**
95
     * @return array
96
     */
97 1
    public function toArray():array
98
    {
99
        return [
100 1
            'component'       => $this->component(),
101 1
            'name'            => $this->name(),
102 1
            'icon'            => $this->icon,
103 1
            'title'           => $this->title,
104 1
            'confirmable'     => $this->confirmable,
105 1
            'data'            => $this->customGlobalData(),
106
        ];
107
    }
108
}
109