@@ -119,6 +119,12 @@ protected function formatComments(?\phpDocumentor\Reflection\DocBlock $docBlock,
119119 $ ul ->addItem (new \PHPFUI \ListItem ($ this ->getColor ('name ' , $ name ) . ' ' . $ this ->getColor ('description ' , $ body )));
120120 }
121121
122+ $ attributes = $ this ->getAttributes ($ reflectionMethod );
123+ foreach ($ attributes as $ attribute )
124+ {
125+ $ ul ->addItem (new \PHPFUI \ListItem ($ this ->getColor ('name ' , 'attribute ' ) . ' ' . $ this ->formatAttribute ($ attribute )));
126+ }
127+
122128 $ container ->add ($ ul );
123129 }
124130
@@ -211,6 +217,11 @@ protected function getComments(?\phpDocumentor\Reflection\DocBlock $docBlock, ?\
211217
212218 protected function getDocBlock ($ method ) : ?\phpDocumentor \Reflection \DocBlock
213219 {
220+ /**
221+ * @todo get attributes everywhere
222+ * $attributes = $this->getAttributes($method);
223+ */
224+
214225 $ comments = $ method ->getDocComment ();
215226 $ comments = \str_replace ('{@inheritdoc} ' , '@inheritdoc ' , $ comments );
216227
@@ -342,6 +353,7 @@ protected function getParameters($method) : string
342353 {
343354 $ info = '( ' ;
344355 $ comma = '' ;
356+
345357 $ docBlock = $ this ->getDocBlock ($ method );
346358
347359 $ parameterComments = $ this ->getParameterComments ($ docBlock );
@@ -361,6 +373,11 @@ protected function getParameters($method) : string
361373 $ name = $ parameter ->getName ();
362374 $ tip = '$ ' . $ name ;
363375
376+ /**
377+ * @todo add attributes for parameters
378+ * $attributes = $this->getAttributes($parameter);
379+ */
380+
364381 if (isset ($ parameterComments [$ name ]))
365382 {
366383 $ tip = new \PHPFUI \ToolTip ($ tip , $ parameterComments [$ name ]);
@@ -479,4 +496,91 @@ protected function section(string $name) : string
479496
480497 return $ section ;
481498 }
499+
500+ protected function getAttributes ($ reflection ) : array
501+ {
502+ if ($ reflection && method_exists ($ reflection , 'getAttributes ' ))
503+ {
504+ return $ reflection ->getAttributes ();
505+ }
506+
507+ return [];
508+ }
509+
510+ private function getAttributeName (string $ name , bool $ asValue = false ) : string
511+ {
512+ $ link = $ this ->getClassName ($ name );
513+ if (strpos ($ link , 'href= ' ))
514+ {
515+ $ name = $ link ;
516+ }
517+ elseif ($ asValue )
518+ {
519+ $ name = $ this ->getValueString ($ name );
520+ }
521+
522+ return $ name ;
523+ }
524+
525+ protected function formatAttribute (\ReflectionAttribute $ attribute ) : string
526+ {
527+ $ parameters = '' ;
528+ $ arguments = $ attribute ->getArguments ();
529+ if ($ arguments )
530+ {
531+ $ parameters = ' ( ' ;
532+ $ comma = '' ;
533+ foreach ($ arguments as $ name => $ argument )
534+ {
535+ $ name = is_int ($ name ) ? '' : $ this ->getAttributeName ($ name ) . ': ' ;
536+ if (is_string ($ argument ))
537+ {
538+ $ link = $ this ->getAttributeName ($ argument , true );
539+ }
540+ else
541+ {
542+ $ link = $ this ->getValueString ($ argument );
543+ }
544+ $ parameters .= "{$ comma } {$ name }{$ link }" ;
545+
546+ $ comma = ', ' ;
547+ }
548+ $ parameters .= ') ' ;
549+ }
550+
551+ $ targeting = '' ;
552+ /*
553+
554+ Not sure how useful this is, so commenting out for now.
555+
556+ $target = $attribute->getTarget();
557+ $targets = [];
558+ $definedTargets = [
559+ "CLASS" => \Attribute::TARGET_CLASS,
560+ "FUNCTION" => \Attribute::TARGET_FUNCTION,
561+ "METHOD" => \Attribute::TARGET_METHOD,
562+ "PROPERTY" => \Attribute::TARGET_PROPERTY,
563+ "CLASS_CONSTANT" => \Attribute::TARGET_CLASS_CONSTANT,
564+ "PARAMETER" => \Attribute::TARGET_PARAMETER,
565+ ];
566+ foreach ($definedTargets as $name => $value)
567+ {
568+ if ($target & $value)
569+ {
570+ $targets[] = '\\Attribute::TARGET_' . $name;
571+ }
572+ }
573+ if ($attribute->isRepeated())
574+ {
575+ $targets[] = '\\Attribute::IS_REPEATABLE';
576+ }
577+ if ($targets)
578+ {
579+ $targeting = ' ' . implode(' | ', $targets);
580+ }
581+ */
582+
583+ return $ this ->getClassName ($ attribute ->getName ()) . $ parameters . $ targeting ;
584+ }
585+
482586 }
0 commit comments