1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
moduleskeletonservice.php
См. документацию.
1
<?php
2
3
declare(strict_types=1);
4
5
namespace
Bitrix\Main\Cli\Command\Dev\Service;
6
7
use Bitrix\Main\Application;
8
use Bitrix\Main\Cli\Command\Dev\Service\Module\ModuleSkeletonDto;
9
use Bitrix\Main\Cli\Command\Dev\Service\Module\ModuleStructure;
10
use Bitrix\Main\IO\Directory;
11
use Symfony\Component\Console\Exception\InvalidArgumentException;
12
13
final
class
ModuleSkeletonService
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
$path
Определения
access_edit.php:21
Bitrix\Main\Application\getDocumentRoot
static getDocumentRoot()
Определения
application.php:736
Bitrix\Main\Application\getPersonalRoot
static getPersonalRoot()
Определения
application.php:762
Bitrix\Main\Cli\Command\Dev\Service\Module\ModuleSkeletonDto
Определения
moduleskeletondto.php:8
Bitrix\Main\Cli\Command\Dev\Service\Module\ModuleStructure
Определения
modulestructure.php:8
Bitrix\Main\Cli\Command\Dev\Service\ModuleSkeletonService
Определения
moduleskeletonservice.php:14
Bitrix\Main\Cli\Command\Dev\Service\ModuleSkeletonService\generateSkeleton
generateSkeleton(ModuleSkeletonDto $dto)
Определения
moduleskeletonservice.php:15
Bitrix\Main\IO\Directory
Определения
directory.php:6
$localPath
$localPath
Определения
template_copy.php:184
bitrix
modules
main
lib
cli
command
dev
service
moduleskeletonservice.php
Создано системой
1.14.0