Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
api-3449634
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
api-3449634
Commits
68502c2b
Commit
68502c2b
authored
9 months ago
by
chx
Browse files
Options
Downloads
Patches
Plain Diff
store attribute references
parent
a25adace
No related branches found
No related tags found
No related merge requests found
Pipeline
#286220
passed with warnings
9 months ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Entity/DocBlock.php
+20
-0
20 additions, 0 deletions
src/Entity/DocBlock.php
src/Parser.php
+39
-0
39 additions, 0 deletions
src/Parser.php
with
59 additions
and
0 deletions
src/Entity/DocBlock.php
+
20
−
0
View file @
68502c2b
...
...
@@ -1232,6 +1232,8 @@ class DocBlock extends ContentEntityBase implements DocBlockInterface {
$use_aliases
=
[];
$processed_ids
=
[];
$class_ids
=
[];
$attributes
=
[];
$old_ids
=
self
::
findByFileName
(
$docblocks
[
0
][
'file_name'
],
$branch
);
$docblocks
=
$parser
->
fileDocblockFirst
(
$docblocks
);
...
...
@@ -1245,6 +1247,10 @@ class DocBlock extends ContentEntityBase implements DocBlockInterface {
// Do the heavy lifting for the docblock and then save if all went well.
if
(
$parser
->
processDocblock
(
$docblock
,
$namespace
,
$use_aliases
,
$nested_groups
,
$class_ids
,
$branch
))
{
$parser
->
addTextDefaults
(
$docblock
);
if
(
$docblock
[
'object_type'
]
===
'attribute'
)
{
$attributes
[]
=
$docblock
;
continue
;
}
$entity
=
self
::
upsert
(
$docblock
,
$branch
,
$processed_ids
);
if
(
empty
(
$entity
))
{
...
...
@@ -1275,6 +1281,20 @@ class DocBlock extends ContentEntityBase implements DocBlockInterface {
self
::
deleteMultiple
(
$old_ids
);
}
// Save attributes. Can't use upsert because multiple attributes are
// possible on the same thing and so it's impossible to say what was
// changed. Just delete them and save new records.
$txn
=
\Drupal
::
database
()
->
startTransaction
();
$attribute_ids
=
self
::
matches
([
'file_name'
=>
$docblocks
[
0
][
'file_name'
],
'object_type'
=>
'attribute'
,
],
$branch
);
self
::
deleteMultiple
(
$attribute_ids
);
foreach
(
$attributes
as
$attribute
)
{
$attribute
[
'branch'
]
=
$branch
->
id
();
self
::
create
(
$attribute
)
->
save
();
}
return
TRUE
;
}
...
...
This diff is collapsed.
Click to expand it.
src/Parser.php
+
39
−
0
View file @
68502c2b
...
...
@@ -19,9 +19,12 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
use
GuzzleHttp\Client
;
use
PhpParser\Comment\Doc
as
CommentDoc
;
use
PhpParser\Error
as
ParserError
;
use
PhpParser\Node\FunctionLike
as
NodeFunctionLike
;
use
PhpParser\Node\Stmt\Class_
as
NodeClass
;
use
PhpParser\Node\Stmt\ClassConst
as
NodeClassConst
;
use
PhpParser\Node\Stmt\ClassLike
as
NodeClassLike
;
use
PhpParser\Node\Stmt\Function_
as
NodeFunction
;
use
PhpParser\Node\Stmt\Property
as
NodeProperty
;
use
PhpParser\ParserFactory
;
use
PhpParser\PrettyPrinter\Standard
as
StandardPrettyPrinter
;
use
Symfony\Component\Finder\Exception\DirectoryNotFoundException
;
...
...
@@ -1481,6 +1484,9 @@ class Parser {
if
(
$type
!=
'Stmt_Global'
&&
$type
!=
'Stmt_Const'
)
{
$docblock
[
'modifiers'
]
=
$this
->
getStatementModifiers
(
$statement
);
}
if
(
$type
===
'Stmt_ClassConst'
||
$type
===
'Stmt_Property'
)
{
$this
->
addAttributeDocblocks
(
$docblocks
,
$statement
,
$docblock
);
}
$docblocks
[]
=
$docblock
;
}
...
...
@@ -1499,6 +1505,7 @@ class Parser {
if
(
$type
==
'Stmt_ClassMethod'
)
{
$docblock
[
'modifiers'
]
=
$this
->
getStatementModifiers
(
$statement
);
}
$this
->
addAttributeDocblocks
(
$docblocks
,
$statement
,
$docblock
);
$docblocks
[]
=
$docblock
;
break
;
...
...
@@ -1540,6 +1547,7 @@ class Parser {
$docblock
[
'object_type'
]
=
'trait'
;
}
$this
->
addAttributeDocblocks
(
$docblocks
,
$statement
,
$docblock
);
$docblocks
[]
=
$docblock
;
// Process the class's internal/body statements.
...
...
@@ -2244,4 +2252,35 @@ class Parser {
}
}
/**
* Add attribute docblocks.
*
* @param array $docblocks
* The array of documentation blocks, passed by reference. Attribute
* docblocks will be added to it.
* @param \PhpParser\Node\Stmt\ClassLike|\PhpParser\Node\FunctionLike|\PhpParser\Node\Stmt\ClassConst|\PhpParser\Node\Stmt\Property $statement
* PHP parser statement.
* @param array $docblock
* The docblock belonging to the statement.
*/
protected
function
addAttributeDocblocks
(
array
&
$docblocks
,
NodeClassLike
|
NodeFunctionLike
|
NodeClassConst
|
NodeProperty
$statement
,
array
$docblock
):
void
{
foreach
(
$statement
->
attrGroups
as
$attrGroup
)
{
// The doxygen shows up on the marked thing as well, no need to store it
// here.
$attrGroup
->
setAttribute
(
'comments'
,
[]);
foreach
(
$attrGroup
->
attrs
as
$attribute
)
{
$attribute_docblock
=
$docblock
;
$attribute_docblock
[
'object_type'
]
=
'attribute'
;
$attribute_docblock
[
'object_name'
]
=
Formatter
::
asString
(
$attribute
->
name
);
$attribute_docblock
[
'title'
]
=
$docblock
[
'object_type'
];
$attribute_docblock
[
'code'
]
=
(
new
StandardPrettyPrinter
())
->
prettyPrint
([
$attrGroup
]);;
$attribute_docblock
[
'references'
]
=
[];
$attribute_docblock
[
'signature'
]
=
''
;
$attribute_docblock
[
'modifiers'
]
=
''
;
$attribute_docblock
[
'content'
]
=
''
;
$docblocks
[]
=
$attribute_docblock
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment