Aspects.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Devtool\Adapter;
  12. use Hyperf\Di\Annotation\AspectCollector;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. class Aspects extends AbstractAdapter
  16. {
  17. public function execute(InputInterface $input, OutputInterface $output)
  18. {
  19. $result = $this->prepareResult();
  20. $this->dump($result, $output);
  21. }
  22. /**
  23. * Prepare the result, maybe this result not just use in here.
  24. */
  25. public function prepareResult(): array
  26. {
  27. $result = [];
  28. $aspects = AspectCollector::list();
  29. foreach ($aspects as $type => $collections) {
  30. foreach ($collections as $aspect => $target) {
  31. $result[$aspect][$type] = $target;
  32. }
  33. }
  34. return $result;
  35. }
  36. /**
  37. * Dump to the console according to the prepared result.
  38. */
  39. private function dump(array $result, OutputInterface $output): void
  40. {
  41. foreach ($result as $aspect => $targets) {
  42. $output->writeln("<info>{$aspect}</info>");
  43. if (isset($targets['annotations'])) {
  44. $output->writeln($this->tab('Annotations:'));
  45. foreach ($targets['annotations'] ?? [] as $annotation) {
  46. $output->writeln($this->tab($annotation ?? '', 2));
  47. }
  48. }
  49. if (isset($targets['classes'])) {
  50. $output->writeln($this->tab('Classes:'));
  51. foreach ($targets['classes'] ?? [] as $class) {
  52. $output->writeln($this->tab($class ?? '', 2));
  53. }
  54. }
  55. }
  56. }
  57. }