Moved enumeration of all sources to PluginFactory

This commit is contained in:
2010-08-30 21:56:18 +01:00
parent f05ceada23
commit 16fb478652
3 changed files with 32 additions and 32 deletions

View File

@@ -1,31 +0,0 @@
<?php
class RippingCluster_Rips_SourceLister {
protected $base_directory;
protected $sources = array();
public function __construct($base_directory) {
$this->base_directory = $base_directory;
$this->scan();
}
public function scan() {
if (!is_dir($this->base_directory)) {
throw new RippingCluster_Exception_InvalidSourceDirectory($this->base_directory);
}
$iterator = new RippingCluster_Utility_DvdDirectoryIterator(new RippingCluster_Utility_VisibleFilesIterator(new DirectoryIterator($this->base_directory)));
foreach ($iterator as /** @var SplFileInfo */ $source_vts) {
$this->sources[] = RippingCluster_Rips_Source::load($source_vts->getPathname(), false);
}
}
public function sources() {
return $this->sources;
}
};
?>

View File

@@ -8,7 +8,7 @@ interface RippingCluster_Source_IPlugin extends RippingCluster_IPlugin {
public static function loadEncoded($encoded_filename, $scan = true, $use_cache = true);
public static function isValidSource($source);
public static function isValidSource($source_filename);
}

View File

@@ -16,6 +16,27 @@ class RippingCluster_Source_PluginFactory extends RippingCluster_PluginFactory {
self::loadPlugins($candidatePlugins, self::PLUGIN_PREFIX, self::PLUGIN_INTERFACE);
}
public static function enumerate($plugin) {
self::ensureScanned();
if ( ! self::isValidPlugin($plugin)) {
return null;
}
return call_user_func(array(self::classname($plugin), 'enumerate'));
}
public static function enumerateAll() {
self::ensureScanned();
$sources = array();
foreach (self::getValidPlugins() as $plugin) {
$this->sources = array_merge($this->sources, self::enumerate($plugin));
}
return $sources;
}
public static function load($plugin, $source_filename, $scan = true, $use_cache = true) {
self::ensureScanned();
@@ -36,6 +57,16 @@ class RippingCluster_Source_PluginFactory extends RippingCluster_PluginFactory {
return call_user_func(array(self::classname($plugin), 'loadEncoded'), $encoded_filename, $scan, $use_cache);
}
public static function isValidSource($plugin, $source_filename) {
self::ensureScanned();
if ( ! self::isValidPlugin($plugin)) {
return null;
}
return call_user_func(array(self::classname($plugin), 'isValidSource'), source_filename);
}
}
?>