123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- abstract class sfPluginConfiguration
- {
- protected
- $configuration = null,
- $dispatcher = null,
- $name = null,
- $rootDir = null;
-
- public function __construct(sfProjectConfiguration $configuration, $rootDir = null, $name = null)
- {
- $this->configuration = $configuration;
- $this->dispatcher = $configuration->getEventDispatcher();
- $this->rootDir = is_null($rootDir) ? $this->guessRootDir() : realpath($rootDir);
- $this->name = is_null($name) ? $this->guessName() : $name;
- $this->setup();
- $this->configure();
- if (!$this->configuration instanceof sfApplicationConfiguration)
- {
- $this->initializeAutoload();
- $this->initialize();
- }
- }
-
- public function setup()
- {
- }
-
- public function configure()
- {
- }
-
- public function initialize()
- {
- }
-
- public function getRootDir()
- {
- return $this->rootDir;
- }
-
- public function getName()
- {
- return $this->name;
- }
-
- public function initializeAutoload()
- {
- $autoload = sfSimpleAutoload::getInstance(sfConfig::get('sf_cache_dir').'/project_autoload.cache');
- if (is_readable($file = $this->rootDir.'/config/autoload.yml'))
- {
- $this->configuration->getEventDispatcher()->connect('autoload.filter_config', array($this, 'filterAutoloadConfig'));
- $config = new sfAutoloadConfigHandler();
- $mappings = $config->evaluate(array($file));
- foreach ($mappings as $class => $file)
- {
- $autoload->setClassPath($class, $file);
- }
- }
- else
- {
- $autoload->addDirectory($this->rootDir.'/lib');
- }
- $autoload->register();
- }
-
- public function filterAutoloadConfig(sfEvent $event, array $config)
- {
-
- if (!isset($config['autoload'][$this->name.'_lib']))
- {
- $config['autoload'] = array_merge(array(
- $this->name.'_lib' => array(
- 'path' => $this->rootDir.'/lib',
- 'recursive' => true,
- ),
- ), $config['autoload']);
- }
- if (!isset($config['autoload'][$this->name.'_module_libs']))
- {
- $config['autoload'] = array_merge(array(
- $this->name.'_module_libs' => array(
- 'path' => $this->rootDir.'/modules/*/lib',
- 'recursive' => true,
- 'prefix' => 1,
- ),
- ), $config['autoload']);
- }
- return $config;
- }
-
- protected function guessRootDir()
- {
- $r = new ReflectionClass(get_class($this));
- return realpath(dirname($r->getFilename()).'/..');
- }
-
- protected function guessName()
- {
- return substr(get_class($this), 0, -13);
- }
- }
|