wishthis/vendor/grandel/include-directory/src/IncludeDirectory.php

44 lines
948 B
PHP
Raw Normal View History

2022-01-13 12:48:28 +00:00
<?php
/**
* include-directory.php
*
* @author Jay Trees <github.jay@grandel.anonaddy.me>
*/
namespace Grandel;
class IncludeDirectory
{
/**
* Include Directory
*
* @param string $directoryToInclude The directory to include.
*
* @return void
*/
public function __construct(string $directoryToInclude)
{
self::includeDirectory($directoryToInclude);
}
private static function includeDirectory(string $directoryToInclude)
{
foreach (scandir($directoryToInclude) as $filename) {
if ($filename === '.' || $filename === '..') {
continue;
}
$filepath = str_replace('\\', '/', $directoryToInclude . '/' . $filename);
if (is_file($filepath)) {
require $filepath;
}
if (is_dir($filepath)) {
self::includeDirectory($filepath);
}
}
}
}