- First commit, routes and database builder are usable

This commit is contained in:
mcndave committed 2020-10-20 14:01:34 +00:00
commit 5f6ce82fd2
23 files changed
+787

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
<?php
namespace Lean\Console\Lib;
class DatabaseMigrations
{
public array $folderList;
public array $entities;
public function __construct(array $folders = [])
{
$this->folderList = $folders;
}
public function getEntities() : void
{
$this->entities = [];
foreach($this->folderList as $folder => $namespace) {
foreach(static::files($folder) as $file) {
$name = $file->getBasename(".".$file->getExtension());
$entity = rtrim($namespace, "\\") . "\\{$name}";
$this->entities[$entity] = $entity::resolveEntity();
}
}
}
protected static function files(string $path, string $fileExtension = "") : \Generator
{
if ( \file_exists($path) ) {
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST, \RecursiveIteratorIterator::CATCH_GET_CHILD);
foreach ($iterator as $file) {
if ( $file->isFile() || $file->isDir() ) {
if ($fileExtension && ( $file->getExtension() === $fileExtension )) {
yield $file;
}
else {
yield $file;
}
}
}
}
}
}