/** * A method to return an array of plugin objects from a selected plugin module * or module/package. * * @static * @param string $module The plugin module name (i.e. /plugins/module directory). * @param string $package An optional plugin package name (i.e. /plugins/module/package * directory). If not given, the search for plugin files will start * at the module directory level. * @param boolean $onlyPluginNameAsIndex If true, the array index for the plugins is * "pluginName", otherwise the index is of the * format is "packageName:pluginName". * @param mixed $recursive If the boolean 'true', returns all plugins in the * given module (and package, if specified), and all * subdirectories thereof. * If an integer, returns all plugins in the given * module (and package, if specified) and subdirectories * thereof, down to the depth specified by the parameter. * @return array An array of plugin objects, indexed as specified by the * $onlyPluginNameAsIndex parameter. */ function &getPlugins($module, $package = null, $onlyPluginNameAsIndex = true, $recursive = 1) { $plugins = array(); $pluginFiles = MAX_Plugin::_getPluginsFiles($module, $package, $recursive); foreach ($pluginFiles as $key => $pluginFile) { $pluginInfo = explode(':', $key); if (count($pluginInfo) > 1) { $plugin = MAX_Plugin::factory($module, $pluginInfo[0], $pluginInfo[1]); if ($plugin !== false) { if ($onlyPluginNameAsIndex) { $plugins[$pluginInfo[1]] = $plugin; } else { $plugins[$key] = $plugin; } } } } return $plugins; }
/** * A method to test the _getPluginsFiles() method. */ function test_getPluginsFiles() { // Test on a non-existant plugin module $result = MAX_Plugin::_getPluginsFiles('foo'); $this->assertTrue(is_array($result)); $this->assertEqual(count($result), 0); // Test on a plugin module with plugins, but with a search depth // that doesn't reach down to the level where the plugins are stored $result = MAX_Plugin::_getPluginsFiles('reports', null, 0); $this->assertTrue(is_array($result)); $this->assertEqual(count($result), 0); // Test on a plugin module with plugins, but with a search depth // that does reach down to the level where the plugins are stored $result = MAX_Plugin::_getPluginsFiles('reports', null, 1); $this->assertTrue(is_array($result)); $this->assertEqual(count($result), 5); // Test on a plugin module and package with plugins, but with a search // depth that does reach down to the level where the plugins are stored $result = MAX_Plugin::_getPluginsFiles('reports', 'standard', 0); $this->assertTrue(is_array($result)); $this->assertEqual(count($result), 4); }