是否可以在symfony中使用两个不同的插件文件夹?

时间:2010-09-15 08:51:01

标签: plugins symfony1

在symfony中,默认的插件文件夹是/ plugin,我想知道是否有办法使用多个文件夹来分类不同类型的插件?

有一个sf_plugin_dir,但我不确定是否可以配置为数组,如

array(
  '/plugin-folder1/..',
  '/plugin-folder2/..',
)

仍然保持一切正常运转?像插件:publish-assets任务。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

您可以在此处找到解决方案:http://gist.github.com/572781

让我在这里复制一下以方便和将来参考:

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this->setupProjectPlugins();
  }

  /**
   * Responsible for initiating any plugins and pointing vendor plugins
   * to the "vendor" subdirectory
   */
  protected function setupProjectPlugins()
  {
    $this->enableAllPluginsExcept(array('sfPropelPlugin'));

    $vendorPlugins = array(
      'ioMenuPlugin',
      'sfCKEditorPlugin',
      'vjCommentPlugin',
      'sfThemePlugin',
      'sfDoctrineSlotPlugin',
      'sfFormExtraPlugin',
      'sfFeed2Plugin',
      'sfImageTransformPlugin',
      'sfDoctrineGuardPlugin',
      'isicsBreadcrumbsPlugin',
      'sfDoctrineActAsTaggablePlugin',
      'sfInlineObjectPlugin',
      'ioEditableContentPlugin',
    );

    foreach ($vendorPlugins as $plugin)
    {
      $this->setPluginPath($plugin, sfConfig::get('sf_plugins_dir').'/vendor/'.$plugin);
    }
    $this->enablePlugins($vendorPlugins);
  }
}

答案 1 :(得分:0)

我有另一个解决方案,它不需要你维护插件列表:

在ProjectConfiguration.class.php中

public function getAllPluginPaths()
{
  $pluginPaths = array();

  // search for *Plugin directories representing plugins
  // follow links and do not recurse. No need to exclude VC because they do not end with *Plugin
  $finder = sfFinder::type('dir')->maxdepth(0)->ignore_version_control(false)->follow_link()->name('*Plugin');
  $dirs = array(
    $this->getSymfonyLibDir().'/plugins',
    'path/to/some/other/dir/plugins', # add path to your dir here.
    sfConfig::get('sf_plugins_dir'),
  );

  foreach ($finder->in($dirs) as $path)
  {
    $pluginPaths[basename($path)] = $path;
  }

  foreach ($this->overriddenPluginPaths as $plugin => $path)
  {
    $pluginPaths[$plugin] = $path;
  }

  return $pluginPaths;
}

(这是symfony核心中发现的方法的一个小模块)