1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
moduleskeletonservice.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Main\Cli\Command\Dev\Service;
6
7use Bitrix\Main\Application;
8use Bitrix\Main\Cli\Command\Dev\Service\Module\ModuleSkeletonDto;
9use Bitrix\Main\Cli\Command\Dev\Service\Module\ModuleStructure;
10use Bitrix\Main\IO\Directory;
11use Symfony\Component\Console\Exception\InvalidArgumentException;
12
14{
15 public function generateSkeleton(ModuleSkeletonDto $dto): void
16 {
17 $baseDirectoryPath = $this->getBaseDirectory($dto->module);
18
19 $directoryPath = $baseDirectoryPath . $this->getSubDirectory($dto->directory);
20
21 $directory = new Directory($directoryPath);
22
23 $directory->create();
24
25 $structure = new ModuleStructure($directoryPath);
26
27 foreach ($structure->getStructure() as $path)
28 {
29 $subDirectory = new Directory($path);
30
31 $subDirectory->create();
32 }
33 }
34
35 private function getBaseDirectory(string $module): string
36 {
37 $bitrixPath = Application::getDocumentRoot() . Application::getPersonalRoot() . '/modules/' . $module . '/lib/';
38 if (is_dir($bitrixPath))
39 {
40 return $bitrixPath;
41 }
42
43 $localPath = Application::getDocumentRoot() . '/local/modules/' . $module . '/lib/';
44 if (is_dir($localPath))
45 {
46 return $localPath;
47 }
48
49 throw new InvalidArgumentException('No such module');
50 }
51
52 private function getSubDirectory(string $path): string
53 {
54 if ($path !== '')
55 {
56 if ($path[0] !== '/')
57 {
58 $path = '/' . $path;
59 }
60 if (!str_ends_with($path, '/'))
61 {
62 $path .= '/';
63 }
64 }
65
66 $path = implode('/', array_map('ucfirst', explode('/', trim($path, '/'))));
67
68 return $path . '/';
69 }
70}
$path
Определения access_edit.php:21
static getDocumentRoot()
Определения application.php:736
static getPersonalRoot()
Определения application.php:762
$localPath
Определения template_copy.php:184