Init
This commit is contained in:
commit
60ca58f5ba
80 changed files with 9458 additions and 0 deletions
39
lib/ProjectTypes.php
Normal file
39
lib/ProjectTypes.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
class ProjectTypes {
|
||||
private static array $types = [];
|
||||
|
||||
public static function load(): void {
|
||||
if (!empty(self::$types)) return;
|
||||
require_once ROOT . '/lib/project-types/ProjectTypeBase.php';
|
||||
foreach (glob(ROOT . '/lib/project-types/*.php') as $file) {
|
||||
if (basename($file) === 'ProjectTypeBase.php') continue;
|
||||
require_once $file;
|
||||
}
|
||||
foreach (get_declared_classes() as $class) {
|
||||
if (is_subclass_of($class, 'ProjectTypeBase')) {
|
||||
self::$types[$class::typeSlug()] = $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function all(): array { return self::$types; }
|
||||
|
||||
public static function get(string $slug): ?string {
|
||||
return self::$types[$slug] ?? null;
|
||||
}
|
||||
|
||||
public static function detect(string $path): string {
|
||||
foreach (self::$types as $slug => $class) {
|
||||
if ($slug !== 'generic' && $class::detectFromPath($path)) return $slug;
|
||||
}
|
||||
return 'generic';
|
||||
}
|
||||
|
||||
public static function forSelect(): array {
|
||||
return array_values(array_map(fn($class) => [
|
||||
'slug' => $class::typeSlug(),
|
||||
'name' => $class::typeName(),
|
||||
'icon' => $class::typeIcon(),
|
||||
], self::$types));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue