1
0
Fork 0
mirror of synced 2024-06-27 02:31:04 +12:00

WIP - Static file loaded

This commit is contained in:
Eldad Fux 2020-07-06 12:19:47 +03:00
parent 5b624419b7
commit 241f9e3964
2 changed files with 73 additions and 0 deletions

View file

@ -0,0 +1,66 @@
<?php
namespace Appwrite\Utopia;
use Exception;
class Files
{
/**
* @var array
*/
static protected $loaded = [];
/**
* @var int
*/
static protected $count = 0;
/**
* Load
*
* @var string $path
*/
public static function load(string $directory, string $root = null)
{
if(!is_readable($directory)) {
throw new Exception('Failed to load directory: '.$directory);
}
$directory = realpath($directory);
$root = ($root) ? $root : $directory;
$handle = opendir($directory);
while ($path = readdir($handle)) {
if (in_array($path, ['.', '..'])) {
continue;
}
if (in_array(pathinfo($path, PATHINFO_EXTENSION), ['php', 'phtml'])) {
continue;
}
if(substr($path, 0, 1) === '.') {
continue;
}
if (is_dir($directory.'/'.$path)) {
self::load($directory.'/'.$path, $root);
continue;
}
self::$count++;
self::$loaded[substr($directory.'/'.$path , strlen($root))] = file_get_contents($directory.'/'.$path);
}
closedir($handle);
if($directory === $root) {
echo '[Static Files] Loadded '.self::$count.' files'.PHP_EOL;
}
}
}

7
test.php Normal file
View file

@ -0,0 +1,7 @@
<?php
use Appwrite\Utopia\Files;
include 'vendor/autoload.php';
Files::load('./public');