dedupe getSubclassesOf
This commit is contained in:
		
							parent
							
								
									9b6eb0e5e2
								
							
						
					
					
						commit
						4ade3452ee
					
				| @ -304,9 +304,7 @@ abstract class ExtensionInfo | |||||||
| 
 | 
 | ||||||
|     public static function load_all_extension_info() |     public static function load_all_extension_info() | ||||||
|     { |     { | ||||||
|         foreach (get_declared_classes() as $class) { |         foreach (getSubclassesOf("ExtensionInfo") as $class) { | ||||||
|             $rclass = new ReflectionClass($class); |  | ||||||
|             if (!$rclass->isAbstract() && is_subclass_of($class, "ExtensionInfo")) { |  | ||||||
|             $extension_info = new $class(); |             $extension_info = new $class(); | ||||||
|             if (array_key_exists($extension_info->key, self::$all_info_by_key)) { |             if (array_key_exists($extension_info->key, self::$all_info_by_key)) { | ||||||
|                 throw new ScoreException("Extension Info $class with key $extension_info->key has already been loaded"); |                 throw new ScoreException("Extension Info $class with key $extension_info->key has already been loaded"); | ||||||
| @ -320,7 +318,6 @@ abstract class ExtensionInfo | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Class FormatterExtension |  * Class FormatterExtension | ||||||
| @ -462,4 +459,12 @@ abstract class DataHandlerExtension extends Extension | |||||||
|     abstract protected function check_contents(string $tmpname): bool; |     abstract protected function check_contents(string $tmpname): bool; | ||||||
|     abstract protected function create_image_from_data(string $filename, array $metadata); |     abstract protected function create_image_from_data(string $filename, array $metadata); | ||||||
|     abstract protected function create_thumb(string $hash, string $type): bool; |     abstract protected function create_thumb(string $hash, string $type): bool; | ||||||
|  | 
 | ||||||
|  |     public static function get_all_supported_exts(): array { | ||||||
|  |         $arr = []; | ||||||
|  |         foreach(getSubclassesOf("DataHandlerExtension") as $handler) { | ||||||
|  |             $arr = array_merge($arr, $handler->SUPPORTED_EXT); | ||||||
|  |         } | ||||||
|  |         return $arr; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -341,6 +341,17 @@ function get_extension(?string $mime_type): ?string | |||||||
|     return ($ext ? $ext : null); |     return ($ext ? $ext : null); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function getSubclassesOf(string $parent) { | ||||||
|  |     $result = []; | ||||||
|  |     foreach (get_declared_classes() as $class) { | ||||||
|  |         $rclass = new ReflectionClass($class); | ||||||
|  |         if (!$rclass->isAbstract() && is_subclass_of($class, $parent)) { | ||||||
|  |             $result[] = $class; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     return $result; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * Like glob, with support for matching very long patterns with braces. |  * Like glob, with support for matching very long patterns with braces. | ||||||
|  */ |  */ | ||||||
|  | |||||||
| @ -35,9 +35,7 @@ function _set_event_listeners(): void | |||||||
|     global $_shm_event_listeners; |     global $_shm_event_listeners; | ||||||
|     $_shm_event_listeners = []; |     $_shm_event_listeners = []; | ||||||
| 
 | 
 | ||||||
|     foreach (get_declared_classes() as $class) { |     foreach (getSubclassesOf("Extension") as $class) { | ||||||
|         $rclass = new ReflectionClass($class); |  | ||||||
|         if (!$rclass->isAbstract() && is_subclass_of($class, "Extension")) { |  | ||||||
|         /** @var Extension $extension */ |         /** @var Extension $extension */ | ||||||
|         $extension = new $class(); |         $extension = new $class(); | ||||||
| 
 | 
 | ||||||
| @ -58,18 +56,14 @@ function _set_event_listeners(): void | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| function _dump_event_listeners(array $event_listeners, string $path): void | function _dump_event_listeners(array $event_listeners, string $path): void | ||||||
| { | { | ||||||
|     $p = "<"."?php\n"; |     $p = "<"."?php\n"; | ||||||
| 
 | 
 | ||||||
|     foreach (get_declared_classes() as $class) { |     foreach (getSubclassesOf("Extension") as $class) { | ||||||
|         $rclass = new ReflectionClass($class); |  | ||||||
|         if (!$rclass->isAbstract() && is_subclass_of($class, "Extension")) { |  | ||||||
|         $p .= "\$$class = new $class(); "; |         $p .= "\$$class = new $class(); "; | ||||||
|     } |     } | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     $p .= "\$_shm_event_listeners = array(\n"; |     $p .= "\$_shm_event_listeners = array(\n"; | ||||||
|     foreach ($event_listeners as $event => $listeners) { |     foreach ($event_listeners as $event => $listeners) { | ||||||
|  | |||||||
| @ -72,12 +72,9 @@ class ET extends Extension | |||||||
|         $info['stat_image_tags'] = $database->get_one("SELECT COUNT(*) FROM image_tags"); |         $info['stat_image_tags'] = $database->get_one("SELECT COUNT(*) FROM image_tags"); | ||||||
| 
 | 
 | ||||||
|         $els = []; |         $els = []; | ||||||
|         foreach (get_declared_classes() as $class) { |         foreach (getSubclassesOf("Extension") as $class) { | ||||||
|             $rclass = new ReflectionClass($class); |  | ||||||
|             if (!$rclass->isAbstract() && is_subclass_of($class, "Extension")) { |  | ||||||
|             $els[] = $class; |             $els[] = $class; | ||||||
|         } |         } | ||||||
|         } |  | ||||||
|         $info['sys_extensions'] = join(', ', $els); |         $info['sys_extensions'] = join(', ', $els); | ||||||
| 
 | 
 | ||||||
|         //$cfs = array();
 |         //$cfs = array();
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user