@@ -123,7 +123,30 @@ public function display(array $classPagesToShow = Controller::VALID_CLASS_PAGES,
123
123
return $ this ->getSection ('GitDiff ' )->generate ($ page , $ fullClassName );
124
124
}
125
125
$ section = new Section ($ this );
126
- $ mainColumn ->add ($ section ->getBreadCrumbs ($ fullClassName ));
126
+
127
+ $ div = new \PHPFUI \GridX ('div ' );
128
+ $ div ->add ($ section ->getBreadCrumbs ($ fullClassName ));
129
+
130
+ $ cell = new \PHPFUI \Cell ();
131
+ $ div ->add (' ' );
132
+ $ icon = new \PHPFUI \FAIcon ('far ' , 'clipboard ' );
133
+ $ parameters = $ this ->getMethodParameters ($ fullClassName );
134
+ $ hidden = new \PHPFUI \Input ('text ' , 'clipboard ' , "new \\{$ fullClassName }( {$ parameters }); " );
135
+ $ hidden ->addClass ('hide ' );
136
+ $ div ->add ($ hidden );
137
+ $ icon ->setToolTip ('Send Constructor to Clipboard ' );
138
+ $ div ->add ($ icon );
139
+ $ callout = new \PHPFUI \Callout ('success ' );
140
+ $ callout ->add ('Copied! ' );
141
+ $ callout ->addClass ('small ' );
142
+ $ callout ->addClass ('hide ' );
143
+ $ icon ->setAttribute ('onclick ' , 'copyText(" ' . $ hidden ->getId () . '"," ' . $ callout ->getId () .'") ' );
144
+ $ js = 'function copyText(id,callout){$("#"+callout).toggleClass("hide");$("#"+id).toggleClass("hide").select();document.execCommand("copy");$("#"+id).toggleClass("hide");setTimeout(function(){$("#"+callout).toggleClass("hide")},2000);} ' ;
145
+ $ page ->addJavaScript ($ js );
146
+ $ page ->setDebug (1 );
147
+ $ div ->add ($ callout );
148
+ $ mainColumn ->add ($ div );
149
+
127
150
$ mainColumn ->add ($ section ->getMenu ($ fullClassName , $ classPagesToShow ));
128
151
129
152
if (Controller::DOC_PAGE == $ this ->getParameter (Controller::PAGE ))
@@ -403,6 +426,108 @@ public function getParameters() : array
403
426
return $ this ->parameters ;
404
427
}
405
428
429
+ /**
430
+ * Get parameters for the class and method
431
+ */
432
+ public function getMethodParameters (string $ className , $ methodName = '__construct ' ) : string
433
+ {
434
+ $ reflection = new \ReflectionClass ($ className );
435
+ if (! $ reflection ->hasMethod ($ methodName ))
436
+ {
437
+ return '' ;
438
+ }
439
+ $ method = $ reflection ->getMethod ($ methodName );
440
+
441
+ $ info = '' ;
442
+ $ comma = '' ;
443
+ foreach ($ method ->getParameters () as $ parameter )
444
+ {
445
+ $ info .= $ comma ;
446
+ $ comma = ', ' ;
447
+
448
+ if ($ parameter ->hasType ())
449
+ {
450
+ $ type = $ parameter ->getType ();
451
+ $ info .= $ type ->allowsNull () ? '? ' : '' ;
452
+ $ info .= $ type ->getName ();
453
+ $ info .= ' ' ;
454
+ $ name = $ parameter ->getName ();
455
+ $ info .= '$ ' . $ name ;
456
+ }
457
+ if ($ parameter ->isDefaultValueAvailable ())
458
+ {
459
+ $ value = $ parameter ->getDefaultValue ();
460
+ $ info .= ' = ' . $ this ->getValueString ($ value );
461
+ }
462
+ }
463
+
464
+ return $ info ;
465
+ }
466
+
467
+ protected function getValueString ($ value ) : string
468
+ {
469
+ switch (gettype ($ value ))
470
+ {
471
+ case 'array ' :
472
+ $ index = 0 ;
473
+ $ text = '[ ' ;
474
+ $ comma = '' ;
475
+
476
+ foreach ($ value as $ key => $ part )
477
+ {
478
+ $ text .= $ comma ;
479
+
480
+ if ($ index !== $ key )
481
+ {
482
+ $ text .= $ this ->getValueString ($ key ) . ' => ' ;
483
+ }
484
+ ++$ index ;
485
+ $ text .= $ this ->getValueString ($ part );
486
+ $ comma = ', ' ;
487
+ }
488
+ $ text .= '] ' ;
489
+ $ value = $ text ;
490
+
491
+ break ;
492
+
493
+ case 'string ' :
494
+ $ value = "' {$ value }' " ;
495
+
496
+ break ;
497
+
498
+ case 'object ' :
499
+ $ class = get_class ($ value );
500
+
501
+ if ('ReflectionNamedType ' == $ class )
502
+ {
503
+ $ value = ($ value ->allowsNull () ? '? ' : '' ) . $ value ->getName ();
504
+ }
505
+ else
506
+ {
507
+ $ value = $ class ;
508
+ }
509
+
510
+ break ;
511
+
512
+ case 'resource ' :
513
+ $ value = 'resource ' ;
514
+
515
+ break ;
516
+
517
+ case 'boolean ' :
518
+ $ value = $ value ? 'true ' : 'false ' ;
519
+
520
+ break ;
521
+
522
+ case 'NULL ' :
523
+ $ value = 'NULL ' ;
524
+
525
+ break ;
526
+ }
527
+
528
+ return $ value ;
529
+ }
530
+
406
531
/**
407
532
* Get a section for display. Override to change layout
408
533
*/
0 commit comments