Loader.php 784 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace Knuckles\Camel\Tools;
  3. use Illuminate\Support\Str;
  4. use Knuckles\Camel\Output\Group;
  5. use League\Flysystem\Adapter\Local;
  6. use League\Flysystem\Filesystem;
  7. use Symfony\Component\Yaml\Yaml;
  8. class Loader
  9. {
  10. /**
  11. * @param string $folder
  12. * @return Group[]
  13. */
  14. public static function loadEndpoints(string $folder): array
  15. {
  16. $adapter = new Local(getcwd());
  17. $fs = new Filesystem($adapter);
  18. $contents = $fs->listContents($folder);;
  19. $groups = [];
  20. foreach ($contents as $object) {
  21. if ($object['type'] == 'file' && Str::endsWith($object['basename'], '.yaml')) {
  22. $groups[] = Group::createFromSpec(Yaml::parseFile($object['path']));
  23. }
  24. }
  25. return $groups;
  26. }
  27. }