|
|
- <?php
-
- namespace App\Helpers;
-
- /**
- *
- *
- *
- *
- */
- class NginxTemplateHelper
- {
- // path for templates files
- const TEMPLATES_DIR = '/resources/nginx/templates';
-
- // path for custom template files
- const TEMPLATES_CUSTOM_DIR = '/resources/nginx/templates/custom';
-
- // ignore files
- const IGNORE_FILES = [
- '.', '..'
- ];
-
- /**
- *
- * @param [type] $files [description]
- * @param [type] $templatePath [description]
- * @return [type] [description]
- */
- private function getTemplates($templatePath)
- {
- $results = [];
-
- foreach(scandir(base_path().$templatePath) as $file) {
- if (!in_array($file, self::IGNORE_FILES)) {
-
- // create filepath
- $filepath = base_path().$templatePath.'/'.$file;
-
- // getting info
- $pathinfo = pathinfo($filepath);
-
- // if extension isset and php
- if (isset($pathinfo['extension']) && $pathinfo['extension'] === 'php') {
-
- $name = str_replace('.blade.php', '', $file);
-
- $results[] = [
- 'name' => $name,
- 'file' => $file,
- 'filepath' => $filepath
- ];
-
- }
- }
- }
-
- return $results;
- }
-
- /**
- * getting templates
- *
- */
- public function find()
- {
- $results = array_merge(
- $this->getTemplates(self::TEMPLATES_DIR),
- $this->getTemplates(self::TEMPLATES_CUSTOM_DIR)
- );
-
- return $results;
- }
- }
|