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.

78 lines
1.7 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
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. * @author Björn Hase, Tentakelfabrik
  7. * @license http://opensource.org/licenses/MIT The MIT License
  8. * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
  9. *
  10. */
  11. class NginxTemplateHelper
  12. {
  13. // path for templates files
  14. const TEMPLATES_DIR = '/resources/nginx/templates';
  15. // path for custom template files
  16. const TEMPLATES_CUSTOM_DIR = '/resources/nginx/templates/custom';
  17. // ignore files
  18. const IGNORE_FILES = [
  19. '.', '..'
  20. ];
  21. /**
  22. * search for templates
  23. *
  24. *
  25. * @param string $templatePath
  26. * @return array
  27. */
  28. private function getTemplates($templatePath)
  29. {
  30. $results = [];
  31. foreach(scandir(base_path().$templatePath) as $file) {
  32. if (!in_array($file, self::IGNORE_FILES)) {
  33. // create filepath
  34. $filepath = base_path().$templatePath.'/'.$file;
  35. // getting info
  36. $pathinfo = pathinfo($filepath);
  37. // if extension isset and php
  38. if (isset($pathinfo['extension']) && $pathinfo['extension'] === 'php') {
  39. $name = str_replace('.blade.php', '', $file);
  40. $results[] = [
  41. 'name' => $name,
  42. 'file' => $file,
  43. 'filepath' => $filepath
  44. ];
  45. }
  46. }
  47. }
  48. return $results;
  49. }
  50. /**
  51. * find templates
  52. *
  53. * @return array
  54. *
  55. */
  56. public function find()
  57. {
  58. $results = array_merge(
  59. $this->getTemplates(self::TEMPLATES_DIR),
  60. $this->getTemplates(self::TEMPLATES_CUSTOM_DIR)
  61. );
  62. return $results;
  63. }
  64. }