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.7 KiB

<?php
namespace App\Helpers;
/**
*
*
* @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;
}
}