Destroy every zig! The official Gerry Vandermaesen blog

29Oct/101

Organizing larger symfony projects with plugins

Update: if you are French speaking, check out this follow-up to my post with step-by-step instructions.

Maybe you have discovered the advantages of developing your symfony applications in plugins, like I have. This allows you to group modules, models and libraries together, helping you organize larger symfony projects.

One thing that bothered me however is that my project's plugins directory grew to a mix of real plugins, I checked out from other repositories, and my application specific plugins, which I prefer to think of as "packages".

It seems though there is a relative easy way to seperate the two, by implementing a similar method in your ProjectConfiguration class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
 
class ProjectConfiguration extends sfProjectConfiguration {
 
  public function enablePackages($packages) {
    if (!is_array($packages)) {
      if (func_num_args() > 1) {
        $packages = func_get_args();
      } else {
        $packages = array($packages);
      }
    }
    foreach ($packages as $package) {
      $this->setPluginPath($package, sfConfig::get('sf_root_dir') . '/packages/' . $package);
    }
    $this->enablePlugins($packages);
  }
 
}

This way I can keep using my plugins directory for external plugins, and stick my "packages" in SF_ROOT_DIR/packages. Enabling these packages is a simple as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
 
class ProjectConfiguration extends sfProjectConfiguration {
 
  public function setup() {
    $this->enablePlugins(
      'sfDoctrinePlugin',
      'sfFormExtraPlugin',
      ...
    );
    $this->enablePackages(
      'fooPackage',
      'barPackage',
      ...
    );
  }
 
  ...
 
}
Comments (1) Trackbacks (0)
  1. Thanks it works great !


Leave a comment

(required)

No trackbacks yet.