<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
/**
|
|
* handle Templates for nginx
|
|
*
|
|
*
|
|
* @author Björn Hase, Tentakelfabrik
|
|
* @license http://opensource.org/licenses/MIT The MIT License
|
|
* @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
|
|
*
|
|
*/
|
|
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 = [
|
|
'.', '..'
|
|
];
|
|
|
|
/**
|
|
* search for templates
|
|
*
|
|
*
|
|
* @param string $templatePath
|
|
* @return array
|
|
*/
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* find templates
|
|
*
|
|
* @return array
|
|
*
|
|
*/
|
|
public function find()
|
|
{
|
|
$results = array_merge(
|
|
$this->getTemplates(self::TEMPLATES_DIR),
|
|
$this->getTemplates(self::TEMPLATES_CUSTOM_DIR)
|
|
);
|
|
|
|
return $results;
|
|
}
|
|
}
|