Skip to content
Snippets Groups Projects
Commit 68502c2b authored by chx's avatar chx
Browse files

store attribute references

parent a25adace
No related branches found
No related tags found
No related merge requests found
Pipeline #286220 passed with warnings
......@@ -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;
}
......
......@@ -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;
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment