1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
controllertemplate.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Cli\Command\Make\Templates;
4
5use Bitrix\Main\Cli\Helper\Renderer\Template;
6
7final class ControllerTemplate implements Template
8{
9 public function __construct(
10 private readonly string $name,
11 private readonly string $namespace,
12 private readonly ?string $module,
13 private readonly ?string $alias,
14 private readonly array $actions = [],
15 )
16 {}
17
18 public function getContent(): string
19 {
20 return <<<PHP
21<?php
22
23namespace {$this->namespace};
24
26
27final class {$this->name} extends Controller
28{
29 protected function init()
30 {
31 parent::init();
32
33 // initialize services and/or load modules
34 }
35{$this->renderAutoWiredParameters()}
36
37{$this->renderActionsConfig()}
38
39{$this->renderActions()}
40}
41PHP;
42 }
43
44 private function renderAutoWiredParameters(): string
45 {
46 return <<<PHP
47 public function getAutoWiredParameters(): array
48 {
49 return [];
50 }
51PHP;
52 }
53
54 private function renderActionsConfig(): string
55 {
56 if (empty($this->actions))
57 {
58 return <<<PHP
59 public function configureActions(): array
60 {
61 return [];
62 }
63PHP;
64 }
65 $code = [];
66 foreach ($this->actions as $action)
67 {
68 $code []= "'{$action}' => [],";
69 }
70
71 $code = implode("\n\t\t\t", $code);
72
73 return <<<PHP
74 public function configureActions(): array
75 {
76 return [
77 {$code}
78 ];
79 }
80PHP;
81 }
82
83 private function renderActions(): string
84 {
85 if (empty($this->actions))
86 {
87 return '';
88 }
89
90 $module = $this->module ?? 'module';
91 $alias = $this->alias ?? 'alias';
92
93 $code = [];
94 if ($this->alias === null)
95 {
96 $code[] = "\t// replace aliases with alias form settings";
97 }
98
99 if ($this->module === null)
100 {
101 $code[] = "\t// replace module your module";
102 }
103
104 foreach ($this->actions as $action)
105 {
106 $code[] = <<<PHP
108 public function {$action}Action(): ?array
109 {
110 return null;
111 }
112PHP;
113 }
114
115 return implode("\n\n", $code);
116 }
117}
__construct(private readonly string $name, private readonly string $namespace, private readonly ?string $module, private readonly ?string $alias, private readonly array $actions=[],)
Определения controllertemplate.php:9
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$name
Определения menu_edit.php:35
$action
Определения file_dialog.php:21