public static function factory($bucket)
 {
     $type = isset($bucket['type']) ? $bucket['type'] : 'file';
     if (!PERCH_RUNWAY || $type == 'file') {
         return new PerchResourceBucket($bucket);
     }
     $handlers = PerchSystem::get_registered_bucket_handlers();
     if (isset($handlers[$type])) {
         return new $handlers[$type]($bucket);
     } else {
         $config = PerchConfig::get($type);
         if ($config && is_array($config) && isset($config['handler']) && isset($config['handler_path'])) {
             include $config['handler_path'];
             PerchSystem::register_bucket_handler($type, $config['handler']);
             return new $config['handler']($bucket);
         } else {
             error_log("Handler not found: {$type}");
         }
     }
 }