Открыть боковую панель
Коротков Данила
Rudra Documentation Collector
Коммиты
5e7ecd96
Коммит
5e7ecd96
создал
Июн 25, 2025
по автору
Коротков Данила
Просмотр файлов
update
владелец
ae1bacdd
Изменения
3
Скрыть пробелы
Построчно
Рядом
src/Commands/DocumentationCommand.php
Просмотр файла @
5e7ecd96
...
...
@@ -17,7 +17,7 @@ use Rudra\Markdown\Creators\DocumentationCreatorInterface;
class
DocumentationCommand
{
pr
otec
te
d
DocumentationCreatorInterface
$docCreator
;
pr
iva
te
DocumentationCreatorInterface
$docCreator
;
public
function
actionIndex
():
void
{
...
...
@@ -53,22 +53,27 @@ class DocumentationCommand
$this
->
scandir
(
$inputPath
,
$outputPath
);
$this
->
docCreator
->
createDocs
(
$outputPath
);
Cli
::
printer
(
"Documentation: "
.
$outputPath
.
" created
\n
"
,
"green"
);
Cli
::
printer
(
"
✅
Documentation: "
.
$outputPath
.
" created
\n
"
,
"green"
);
}
protected
function
scandir
(
string
$inputPath
,
string
$outputPath
):
void
/**
* Recursively scans a directory for PHP classes and processes files with uppercase filenames.
*
* @param string $inputPath
* @param string $outputPath
* @return void
*/
private
function
scandir
(
string
$inputPath
,
string
$outputPath
):
void
{
$directory
=
array_diff
(
scandir
(
$inputPath
),
array
(
'..'
,
'.'
));
foreach
(
$directory
as
$item
)
{
if
(
str_contains
(
$item
,
".php"
))
{
if
(
ctype_upper
(
$item
[
0
]))
{
$fileContent
=
file_get_contents
(
$inputPath
.
'/'
.
$item
);
$className
=
str_replace
(
".php"
,
""
,
$item
);
if
(
preg_match
(
'/namespace[\\s]+([A-Za-z0-9\\\\]+?);/sm'
,
$fileContent
,
$match
))
{
$fullClassName
=
$match
[
1
]
.
"
\\
"
.
$className
;
if
(
class_exists
(
$fullClassName
)
or
interface_exists
(
$fullClassName
)
or
trait_exists
(
$fullClassName
))
{
...
...
@@ -87,7 +92,14 @@ class DocumentationCommand
}
}
protected
function
setData
(
string
$fullClassName
,
string
$type
=
'header'
):
void
/**
* Generates and appends documentation content for a class based on the specified type.
*
* @param string $fullClassName
* @param string $type
* @return void
*/
private
function
setData
(
string
$fullClassName
,
string
$type
=
'header'
):
void
{
$methodName
=
"create"
.
ucfirst
(
$type
)
.
"String"
;
...
...
src/Creators/DocumentationCreatorInterface.php
Просмотр файла @
5e7ecd96
...
...
@@ -9,7 +9,21 @@ namespace Rudra\Markdown\Creators;
interface
DocumentationCreatorInterface
{
/**
* @param string $outputPath
* @return void
*/
public
function
createDocs
(
string
$outputPath
):
void
;
/**
* @param string $fullClassName
* @return string
*/
public
function
createHeaderString
(
string
$fullClassName
):
string
;
/**
* @param string $fullClassName
* @return string
*/
public
function
createBodyString
(
string
$fullClassName
):
string
;
}
src/Creators/HtmlCreator.php
Просмотр файла @
5e7ecd96
...
...
@@ -11,13 +11,20 @@ namespace Rudra\Markdown\Creators;
class
HtmlCreator
implements
DocumentationCreatorInterface
{
pr
otec
te
d
string
$frameworkType
;
pr
iva
te
string
$frameworkType
;
/**
* @param string $frameworkType
*/
public
function
__construct
(
string
$frameworkType
=
'bsp'
)
{
$this
->
frameworkType
=
$frameworkType
;
}
/**
* @param string $outputPath
* @return void
*/
public
function
createDocs
(
string
$outputPath
):
void
{
file_put_contents
(
$outputPath
,
$this
->
setHtmlHeader
(),
FILE_APPEND
);
...
...
@@ -33,11 +40,19 @@ class HtmlCreator implements DocumentationCreatorInterface
file_put_contents
(
$outputPath
,
$this
->
setHtmlFooter
(),
FILE_APPEND
);
}
/**
* @param string $fullClassName
* @return string
*/
public
function
createHeaderString
(
string
$fullClassName
):
string
{
return
'<p><a href="#'
.
str_replace
(
"
\\
"
,
"_"
,
strtolower
(
$fullClassName
))
.
'">'
.
$fullClassName
.
'</a></p>'
;
}
/**
* @param string $fullClassName
* @return string
*/
public
function
createBodyString
(
string
$fullClassName
):
string
{
$class
=
new
\
ReflectionClass
(
$fullClassName
);
...
...
@@ -105,12 +120,19 @@ class HtmlCreator implements DocumentationCreatorInterface
return
$header
.
$table
.
'</table>'
;
}
private
function
getAnchorName
(
$className
):
string
/**
* @param string $className
* @return string
*/
private
function
getAnchorName
(
string
$className
):
string
{
return
str_replace
(
"
\\
"
,
"_"
,
strtolower
(
$className
));
}
protected
function
setHtmlHeader
():
string
/**
* @return string
*/
private
function
setHtmlHeader
():
string
{
switch
(
$this
->
frameworkType
)
{
case
'ui'
:
...
...
@@ -166,11 +188,13 @@ class HtmlCreator implements DocumentationCreatorInterface
}
}
protected
function
setHtmlFooter
():
string
/**
* @return string
*/
private
function
setHtmlFooter
():
string
{
switch
(
$this
->
frameworkType
)
{
case
'ui'
:
return
'</div></body></html>'
;
case
'ui'
:
case
'f'
:
return
'</div></body></html>'
;
default
:
...
...
@@ -183,7 +207,10 @@ class HtmlCreator implements DocumentationCreatorInterface
}
}
protected
function
setTableClass
():
string
/**
* @return string
*/
private
function
setTableClass
():
string
{
switch
(
$this
->
frameworkType
)
{
case
'ui'
:
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать