OpenSource CLI-App to install and handle stuff related to Web-Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Helpers;
  3. /**
  4. *
  5. *
  6. *
  7. *
  8. */
  9. class NginxTemplateHelper
  10. {
  11. // path for templates files
  12. const TEMPLATES_DIR = '/resources/nginx/templates';
  13. // path for custom template files
  14. const TEMPLATES_CUSTOM_DIR = '/resources/nginx/templates/custom';
  15. // ignore files
  16. const IGNORE_FILES = [
  17. '.', '..'
  18. ];
  19. /**
  20. *
  21. * @param [type] $files [description]
  22. * @param [type] $templatePath [description]
  23. * @return [type] [description]
  24. */
  25. private function getTemplates($templatePath)
  26. {
  27. $results = [];
  28. foreach(scandir(base_path().$templatePath) as $file) {
  29. if (!in_array($file, self::IGNORE_FILES)) {
  30. // create filepath
  31. $filepath = base_path().$templatePath.'/'.$file;
  32. // getting info
  33. $pathinfo = pathinfo($filepath);
  34. // if extension isset and php
  35. if (isset($pathinfo['extension']) && $pathinfo['extension'] === 'php') {
  36. $name = str_replace('.blade.php', '', $file);
  37. $results[] = [
  38. 'name' => $name,
  39. 'file' => $file,
  40. 'filepath' => $filepath
  41. ];
  42. }
  43. }
  44. }
  45. return $results;
  46. }
  47. /**
  48. * getting templates
  49. *
  50. */
  51. public function find()
  52. {
  53. $results = array_merge(
  54. $this->getTemplates(self::TEMPLATES_DIR),
  55. $this->getTemplates(self::TEMPLATES_CUSTOM_DIR)
  56. );
  57. return $results;
  58. }
  59. }