20 return $this->getTemplate($dto)->getContent();
25 $filePath = $this->getFilePath($dto->module);
26 $withTag = !file_exists($filePath);
27 $template = $this->getTemplate($dto, $withTag);
30 $renderer->replaceFileContent(
33 "#region autogenerated services for module {$dto->module}",
38 private function getServicesByModule(
string $module):
array
40 $config = Configuration::getInstance($module);
41 $serviceConfig =
$config->get(
'services');
44 foreach ($serviceConfig as $serviceName => $serviceData)
46 $serviceClass = $this->getServiceClass($serviceData);
47 if ($serviceClass !==
null)
49 $services[$serviceName] = $serviceClass;
56 private function getServiceClass(
array $serviceData): ?string
58 $className = $serviceData[
'className'] ??
null;
59 if ($className !==
null)
61 return '\\' . $className .
'::class';
64 $constructor = $serviceData[
'constructor'] ??
null;
65 if ($constructor !==
null)
67 $reflector =
new ReflectionFunction($constructor);
68 if ($reflector->hasReturnType())
70 return '\\' .$reflector->getReturnType() .
'::class';
77 private function getFilePath(
string $module): string
80 if (is_dir($bitrixPath))
82 return $bitrixPath .
'/.phpstorm.meta.php';
91 throw new InvalidArgumentException(
'No such module');
94 private function getTemplate(LocatorCodesDto $dto,
bool $withTag =
false): Template
96 $services = $this->getServicesByModule($dto->module);
98 return new LocatorCodesTemplate($dto->code, $dto->module, $services, $withTag);
generateFile(LocatorCodesDto $dto)
generateContent(LocatorCodesDto $dto)