1 | <?php |
||
2 | |||
3 | namespace Apps\Model\Admin\Main; |
||
4 | |||
5 | use Ffcms\Core\App; |
||
6 | use Ffcms\Core\Arch\Model; |
||
7 | use Ffcms\Core\Exception\SyntaxException; |
||
8 | use Ffcms\Core\Helper\Type\Arr; |
||
9 | |||
10 | /** |
||
11 | * Class EntityDeleteRoute. Business logic of delete routing row from config file |
||
12 | * @package Apps\Model\Admin\Main |
||
13 | */ |
||
14 | class EntityDeleteRoute extends Model |
||
15 | { |
||
16 | public $type; |
||
17 | public $loader; |
||
18 | public $source; |
||
19 | public $target; |
||
20 | |||
21 | private $_cfg; |
||
22 | |||
23 | /** |
||
24 | * EntityDeleteRoute constructor. Pass parameters from controller |
||
25 | * @param string|null $type |
||
26 | * @param string|null $loader |
||
27 | * @param string|null $source |
||
28 | */ |
||
29 | public function __construct($type = null, $loader = null, $source = null) |
||
30 | { |
||
31 | $this->type = $type; |
||
32 | $this->loader = $loader; |
||
33 | $this->source = $source; |
||
34 | $this->_cfg = App::$Properties->getAll('Routing'); |
||
35 | parent::__construct(true); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Check passed params from constructor |
||
40 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
41 | */ |
||
42 | public function before() |
||
43 | { |
||
44 | // check rule type |
||
45 | if (!Arr::in($this->type, ['Alias', 'Callback'])) { |
||
46 | throw new SyntaxException(); |
||
47 | } |
||
48 | |||
49 | // check loader env type |
||
50 | if (!Arr::in($this->loader, ['Front', 'Admin', 'Api'])) { |
||
51 | throw new SyntaxException(); |
||
52 | } |
||
53 | |||
54 | // prepare source path |
||
55 | if ($this->type === 'Alias') { |
||
56 | $this->source = '/' . trim($this->source, '/'); |
||
57 | } else { |
||
58 | $this->source = ucfirst($this->source); |
||
59 | } |
||
60 | |||
61 | if (!isset($this->_cfg[$this->type][$this->loader][$this->source])) { |
||
62 | throw new SyntaxException(); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Define labels for entity |
||
68 | * @return array |
||
69 | */ |
||
70 | public function labels(): array |
||
71 | { |
||
72 | return [ |
||
73 | 'loader' => __('Loader environment'), |
||
74 | 'type' => __('Routing type'), |
||
75 | 'source' => __('Source path/controller') |
||
76 | ]; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Save data to configuration file |
||
81 | */ |
||
82 | public function make() |
||
83 | { |
||
84 | unset($this->_cfg[$this->type][$this->loader][$this->source]); |
||
85 | App::$Properties->writeConfig('Routing', $this->_cfg); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
86 | } |
||
87 | } |
||
88 |