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.

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