From 16fb47865279850f81b67c7ce04eeaa4e51c09cc Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Mon, 30 Aug 2010 21:56:18 +0100 Subject: [PATCH] Moved enumeration of all sources to PluginFactory --- .../Rips/SourceLister.class.php | 31 ------------------- lib/RippingCluster/Source/IPlugin.class.php | 2 +- .../Source/PluginFactory.class.php | 31 +++++++++++++++++++ 3 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 lib/RippingCluster/Rips/SourceLister.class.php diff --git a/lib/RippingCluster/Rips/SourceLister.class.php b/lib/RippingCluster/Rips/SourceLister.class.php deleted file mode 100644 index 1a4e0f4..0000000 --- a/lib/RippingCluster/Rips/SourceLister.class.php +++ /dev/null @@ -1,31 +0,0 @@ -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; - } - -}; - -?> diff --git a/lib/RippingCluster/Source/IPlugin.class.php b/lib/RippingCluster/Source/IPlugin.class.php index 72f8b47..b21e43e 100644 --- a/lib/RippingCluster/Source/IPlugin.class.php +++ b/lib/RippingCluster/Source/IPlugin.class.php @@ -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); } diff --git a/lib/RippingCluster/Source/PluginFactory.class.php b/lib/RippingCluster/Source/PluginFactory.class.php index 0f385c3..f447c78 100644 --- a/lib/RippingCluster/Source/PluginFactory.class.php +++ b/lib/RippingCluster/Source/PluginFactory.class.php @@ -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); + } + } ?> \ No newline at end of file