Development

Changeset 21916

You must first sign up to be able to contribute.

Changeset 21916

Show
Ignore:
Timestamp:
09/11/09 15:05:45 (4 years ago)
Author:
ornicar2
Message:

[Diem] Implemented Symfony Dependency Injection Container.
Diem services wich benefit of sfServiceContainer : search_engine, doctrine_config, filesystem, user_log, page_tree_watcher, file_backup, helper, cache_manager, sitemap, page_helper, widget_type_manager and more to come...
This pattern is really great. Diem users will be able to replace many parts of the CMS code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/diemPlugin/trunk/TODO

    r21823 r21916  
    164164* DmMail : allow to activate/desactivate a mail 
    165165 
    166 * consider using Symfony Components Dependency Injection Container 
     166* [DONE] consider using Symfony Components Dependency Injection Container 
     167 
     168* [DONE] Implement Symfony Components Dependency Injection Container everywhere it makes sense 
    167169 
    168170* consider feed dmDataService with fixtures 
     
    179181 
    180182* convert this TODO to trac tickets 
     183 
     184* consider using http://www.quasipartikel.at/multiselect/ for admin multiselect 
  • plugins/diemPlugin/trunk/dmAdminPlugin/lib/context/dmAdminContext.php

    r21833 r21916  
    77  $moduleSpace; 
    88 
    9   /** 
    10    * Loads the diem services 
    11    */ 
    12   public function loadServiceContainer() 
    13   { 
    14     $name = 'dm'.md5(dmProject::getRootDir().sfConfig::get('sf_app')).'ServiceContainer'; 
    15      
    16     $file = dmOs::join(sys_get_temp_dir(), $name.'.php'); 
    17       
    18     if (!sfConfig::get('sf_debug') && file_exists($file)) 
    19     { 
    20       require_once $file; 
    21       $sc = new $name; 
    22     } 
    23     else 
    24     { 
    25       // build the service container dynamically 
    26       $sc = new sfServiceContainerBuilder(); 
    27       $loader = new sfServiceContainerLoaderFileYaml($sc); 
    28       $loader->load(dmOs::join(sfConfig::get('dm_core_plugin'), 'config/dm/services.yml')); 
    29       
    30       if (!$isDebug) 
    31       { 
    32         $dumper = new sfServiceContainerDumperPhp($sc); 
    33         file_put_contents($file, $dumper->dump(array('class' => $name))); 
    34       } 
    35     } 
    36      
    37     $this->serviceContainer = $sc; 
    38   } 
     9  public function getSitemap() 
     10  { 
     11    return $this->serviceContainer->getService('sitemap'); 
     12  } 
    3913   
    4014  public function isModuleAction($module, $action) 
  • plugins/diemPlugin/trunk/dmAdminPlugin/lib/dmFilter/dmAdminSeoValidationFilter.php

    r21516 r21916  
    5555       ); 
    5656 
    57         dmCacheManager::getCache('dm/seo/validation')->set('duplicated', $duplicated); 
     57        $this->dmContext->getCacheManager()->getCache('dm/seo/validation')->set('duplicated', $duplicated); 
    5858      } 
    5959    } 
  • plugins/diemPlugin/trunk/dmAdminPlugin/lib/sitemap/dmSitemap.php

    r21557 r21916  
    11<?php 
    22 
    3 class dmSitemapGenerator 
     3class dmSitemap 
    44{ 
    55  protected 
    6   $file
     6  $dispatcher
    77  $filesystem, 
    8   $baseUrl;  
     8  $baseUrl, 
     9  $path;   
    910   
    10   public function __construct($to = 'sitemap.xml'
     11  public function __construct(sfEventDispatcher $dispatcher, dmFilesystem $filesystem, array $options
    1112  { 
    12     $this->file = dmOs::join(sfConfig::get('sf_web_dir'), $to); 
     13    $this->dispatcher = $dispatcher; 
     14     
     15    $this->filesystem = $filesystem; 
    1316     
    14     $this->filesystem = new dmFilesystem(); 
    15      
    16     $this->baseUrl = dm::getRequest()->getAbsoluteUrlRoot().'/'; 
    17      
    18     $this->configure(); 
    19      
    20     $this->checkPermissions(); 
     17    $this->initialize($options); 
    2118  } 
    2219   
    23   protected function configure(
     20  protected function initialize(array $options
    2421  { 
     22    $this->setPath(dmArray::get($options, 'file', 'sitemap.xml')); 
     23     
     24    if(isset($options['baseUrl'])) 
     25    { 
     26      $this->setBaseUrl($options['base_url']); 
     27    } 
     28 
     29    $this->checkPermissions(); 
    2530  } 
    2631   
    27   public function setBaseUrl($baseUrl) 
    28   { 
    29     $this->baseUrl = trim($baseUrl, '/').'/'; 
    30   } 
     32  public function setBaseUrl($baseUrl) 
     33  { 
     34    $this->baseUrl = trim($baseUrl, '/').'/'; 
     35  } 
     36   
     37  public function setPath($path) 
     38  { 
     39    $this->path = trim(dmOs::join($path), '/'); 
     40  } 
     41   
     42  public function getPath() 
     43  { 
     44    return $this->path; 
     45  } 
     46   
     47  public function getFullPath() 
     48  { 
     49    return dmOs::join(sfConfig::get('sf_web_dir'), $this->getPath()); 
     50  } 
    3151   
    3252  /* 
     
    3656  protected function getPages($culture) 
    3757  { 
    38     $query = dmDb::query('DmPage p')->withI18n($culture); 
    39      
    40     $query 
    41     ->where('p.is_secure = ?', false) 
     58    $query = dmDb::query('DmPage p')->withI18n($culture) 
     59    ->where('p.is_secure = ?', false) 
    4260    ->addWhere('translation.is_active = ?', true) 
    43     ->addWhere('p.action != ?', 'error404'); 
    44      
    45     $query 
     61    ->addWhere('p.action != ?', 'error404') 
    4662    ->orderBy('p.lft asc'); 
    4763     
     
    5167  /* 
    5268   * Generates a sitemap 
    53    * and save in sf_web_dir./.$to 
     69   * and save it in fullPath 
    5470   */ 
    55   public function generate($culture = null
     71  public function generate($culture
    5672  { 
    57     $xml = $this->getXml(is_null($culture) ? dm::getUser()->getCulture() : $culture); 
     73    $this->checkBaseUrl(); 
     74     
     75    $xml = $this->getXml($culture); 
    5876     
    59     if(!file_put_contents($this->file, $xml)) 
     77    if(!file_put_contents($this->getFullPath(), $xml)) 
    6078    { 
    61       throw new dmException('Can not save to '.dmProject::unRootify($this->file)); 
     79      throw new dmException('Can not save to '.dmProject::unRootify($this->getFullPath())); 
    6280    } 
    6381  } 
     
    90108      %s 
    91109    </loc> 
    92   </url>', $this->baseUrl.$page->slug); 
     110  </url>', $this->baseUrl.$page->_getI18n('slug')); 
    93111  } 
    94112   
     113  public function fileExists() 
     114  { 
     115    return file_exists($this->getFullPath()); 
     116  } 
     117   
     118  public function getFileContent() 
     119  { 
     120    $this->checkFileExists(); 
     121    return file_get_contents($this->getFullPath()); 
     122  } 
     123   
     124  public function getUpdatedAt() 
     125  { 
     126    $this->checkFileExists(); 
     127    return filemtime($this->getFullPath()); 
     128  } 
     129   
     130  public function countUrls() 
     131  { 
     132    $this->checkFileExists(); 
     133    return substr_count($this->getFileContent(), '<url>'); 
     134  } 
     135   
     136  public function getFileSize() 
     137  { 
     138    $this->checkFileExists(); 
     139    return filesize($this->getFullPath()); 
     140  } 
     141   
     142  public function getWebPath() 
     143  { 
     144    $this->checkBaseUrl(); 
     145    return $this->baseUrl.$this->getPath(); 
     146  } 
     147   
     148  protected function checkFileExists() 
     149  { 
     150    if (!$this->fileExists()) 
     151    { 
     152      throw new dmException(sprintf('The sitemap file does not exists')); 
     153    } 
     154  } 
     155   
    95156  protected function checkPermissions() 
    96157  { 
    97     if (!$this->filesystem->mkdir(dirname($this->file))) 
     158    if (!$this->filesystem->mkdir(dirname($this->getFullPath()))) 
    98159    { 
    99       throw new dmException(sprintf('%s is not writable', dirname($this->file))); 
     160      throw new dmException(sprintf('%s is not writable', dirname($this->getFullPath()))); 
    100161    } 
    101162     
    102     if (file_exists($this->file) && !is_writable($this->file)) 
     163    if (file_exists($this->getFullPath()) && !is_writable($this->getFullPath())) 
    103164    { 
    104       throw new dmException(sprintf('%s is not writable', $this->file)); 
     165      throw new dmException(sprintf('%s is not writable', $this->getFullPath())); 
    105166    } 
    106167  } 
    107168   
     169  protected function checkBaseUrl() 
     170  { 
     171    if (!$this->baseUrl) 
     172    { 
     173      throw new dmException('You must pass a baseUrl'); 
     174    } 
     175  } 
    108176} 
  • plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmAdmin/actions/actions.class.php

    r21824 r21916  
    3333    require_once(dmOs::join(sfConfig::get('dm_admin_dir'), 'modules/dmUserLog/lib/dmUserLogViewLittle.php')); 
    3434     
    35     $this->userLogView = new dmUserLogViewLittle(new dmUserLog, $this->getUser()->getCulture()); 
     35    $this->userLogView = new dmUserLogViewLittle($this->getDmContext()->getUserLog(), $this->getUser()->getCulture()); 
    3636     
    3737    $this->userLogOptions = array( 
  • plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmCodeEditor/actions/actions.class.php

    r21423 r21916  
    142142    try 
    143143    { 
    144       $backup = new dmBackup(); 
    145       $backup->save($file); 
     144      $this->getDmContext()->getFileBackup()->save($file); 
    146145    } 
    147146    catch(dmException $e) 
     
    189188  public function executePaste(sfWebRequest $request) 
    190189  { 
     190    $filesystem = $this->dmContext->getFilesystem(); 
     191     
    191192    $id = $request->getParameter("id"); 
    192193    $this->rootDir = sfConfig::get('sf_root_dir'); 
     
    200201        if($copyDir = $this->getUser()->getAttribute('code_editor_file_copy_cut')) 
    201202        { 
    202           if(!dmFilesystem::get()->copyRecursive(dmCodeEditorTools::decodeUrlTreeForCopy($copyDir),dmCodeEditorTools::decodeUrlTreeForCopy($pasteDir))) 
     203          if(!$this->getDmContext()->getFilesystem()->copyRecursive(dmCodeEditorTools::decodeUrlTreeForCopy($copyDir),dmCodeEditorTools::decodeUrlTreeForCopy($pasteDir))) 
    203204          { 
    204205            return $this->renderText('[KO] | An error occurred '); 
     
    206207          if($this->getUser()->getAttribute('code_editor_is_cut') == 'cut') 
    207208          { 
    208             if(!dmFilesystem::get()->unlink($copyDir)) 
     209            if(!$this->getDmContext()->getFilesystem()->unlink($copyDir)) 
    209210            { 
    210211              return $this->renderText('[KO] | An error occurred while deleting the file or dir : '.$copyDir); 
     
    243244      if(file_exists($deleteDir) && is_writable($deleteDir)) 
    244245      { 
    245         if(dmFilesystem::get()->unlink($deleteDir)) 
     246        if($this->getDmContext()->getFilesystem()->unlink($deleteDir)) 
    246247        { 
    247248          return $this->renderText('[OK] | Successfully deleted'); 
     
    294295        if($request->getParameter('create') == 'file') 
    295296        { 
    296           if(dmFilesystem::get()->touch($newName)) 
     297          if($this->getDmContext()->getFilesystem()->touch($newName)) 
    297298          { 
    298299            return $this->renderText('[OK] | Succefully created new file : '.basename($newName)); 
  • plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmSearchEngine/actions/actions.class.php

    r21423 r21916  
    66  public function executeIndex(dmWebRequest $request) 
    77  { 
    8     $this->index = new mySearchIndexGroup
     8    $this->index = $this->getDmContext()->getSearchEngine()
    99 
    1010    $this->form = $this->getSearchForm(); 
     
    2323  public function executeReload() 
    2424  { 
    25     $filesystem = dmFilesystem::get(); 
    26      
    27     $filesystem->sf('dm:search-update'); 
     25    $this->getDmContext()->getFilesystem()->sf('dm:search-update'); 
    2826 
    2927    return $this->redirect('dmSearchEngine/index'); 
  • plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmSeoValidation/actions/actions.class.php

    r21423 r21916  
    66  public function executeIndex(sfWebRequest $request) 
    77  { 
    8     $this->duplicated = dmCacheManager::getCache('dm/seo/validation')->get('duplicated'); 
     8    $this->duplicated = $this->getDmContext()->getCacheManager()->getCache('dm/seo/validation')->get('duplicated'); 
    99  } 
    1010 
  • plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmSitemap/actions/actions.class.php

    r21423 r21916  
    44{ 
    55   
     6  public function preExecute() 
     7  { 
     8    $this->sitemap = $this->getDmContext()->getSitemap(); 
     9     
     10    $this->sitemap->setBaseUrl($this->getRequest()->getAbsoluteUrlRoot()); 
     11  } 
     12   
    613  public function executeIndex(dmWebRequest $request) 
    714  { 
    8     if (file_exists($this->getFile())) 
     15    if ($this->sitemap->fileExists()) 
    916    { 
    10       $this->sitemap = file_get_contents($this->getFile()); 
    11       $this->updatedAt = filemtime($this->getFile()); 
    12       $this->nbLinks = substr_count($this->sitemap, '<url>'); 
    13       $this->size = dmOs::humanizeSize($this->getFile()); 
    14       $this->sitemapWebPath = $this->getRequest()->getAbsoluteUrlRoot().'/'.$this->getFileName(); 
     17      $this->exists =     true; 
     18      $this->xml =        $this->sitemap->getFileContent(); 
     19      $this->updatedAt =  $this->sitemap->getUpdatedAt(); 
     20      $this->nbLinks =    $this->sitemap->countUrls(); 
     21      $this->size =       dmOs::humanizeSize($this->sitemap->getFileSize()); 
     22      $this->webPath =    $this->sitemap->getWebPath(); 
    1523    } 
    1624    else 
    1725    { 
    18     $this->sitemap = false; 
     26      $this->exists =    false; 
    1927    } 
    2028  } 
     
    2230  public function executeGenerate(dmWebRequest $request) 
    2331  { 
    24     $sitemapGenerator = new mySitemapGenerator($this->getFileName()); 
    25      
    2632    try 
    2733    { 
    28       $sitemapGenerator->generate(); 
     34      $this->sitemap->generate($this->getUser()->getCulture()); 
    2935      $this->getUser()->logInfo('The sitemap has been successfully generated'); 
    3036    } 
     
    4248  } 
    4349     
    44   protected function getFile() 
    45   { 
    46     return dmOs::join(sfConfig::get('sf_web_dir'), $this->getFileName()); 
    47   } 
    48    
    49   protected function getFileName() 
    50   { 
    51     return trim(dmArray::get(sfConfig::get('dm_seo_sitemap'), 'path', 'sitemap.xml'), '/'); 
    52   } 
    5350} 
  • plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmSitemap/templates/indexSuccess.php

    r21423 r21916  
    1313echo £o('div.dm_box_inner'); 
    1414 
    15 if ($sitemap
     15if ($exists
    1616{ 
    1717  echo £('div.clearfix.mb10', 
    1818    definition_list(array( 
    19       'Position' => £link($sitemapWebPath), 
     19      'Position' => £link($webPath), 
    2020      'Urls' => $nbLinks, 
    2121      'Size' => $size, 
     
    2525  ); 
    2626   
    27   echo £('pre', array('style' => 'background: #fff; padding: 10px; border: 1px solid #ddd;'), htmlentities($sitemap)); 
     27  echo £('pre', array('style' => 'background: #fff; padding: 10px; border: 1px solid #ddd;'), htmlentities($xml)); 
    2828} 
    2929else 
  • plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmUserLog/actions/actions.class.php

    r21779 r21916  
    33class dmUserLogActions extends dmAdminBaseActions 
    44{ 
     5   
     6  public function preExecute() 
     7  { 
     8    $this->log = $this->getDmContext()->getUserLog(); 
     9  } 
    510   
    611  public function executeClear(dmWebRequest $request) 
    712  { 
    8     $log = new dmUserLog; 
    9     $log->clear(); 
     13    $this->log->clear(); 
    1014    $this->getUser()->logInfo(dm::getI18n()->__('User log cleared')); 
    1115    return $this->redirect('dmUserLog/index'); 
     
    1418  public function executeRefresh(dmWebRequest $request) 
    1519  { 
    16     $log = new dmUserLog; 
    17  
    18     $responseHash = md5(dmArray::first($log->getEntries(1))->toJson()); 
     20    $responseHash = md5(dmArray::first($this->log->getEntries(1))->toJson()); 
    1921     
    2022    if ($responseHash == $request->getParameter('hash')) 
     
    2527    $viewClass = 'dmUserLogView'.dmString::camelize($request->getParameter('view')); 
    2628     
    27     $view = new $viewClass($log, $this->getUser()->getCulture()); 
     29    $view = new $viewClass($this->log, $this->getUser()->getCulture()); 
    2830     
    2931    return $this->renderText( 
     
    3638  public function executeIndex(dmWebRequest $request) 
    3739  { 
    38     $log = new dmUserLog; 
    39     $this->view = new dmUserLogView($log, $this->getUser()->getCulture()); 
    40     $this->filesize = $log->getSize(); 
     40    $this->view = new dmUserLogView($this->log, $this->getUser()->getCulture()); 
     41    $this->filesize = $this->log->getSize(); 
    4142  } 
    4243   
  • plugins/diemPlugin/trunk/dmCorePlugin/config/dmCorePluginConfiguration.class.php

    r21833 r21916  
    2121    $this->enableHelpers(); 
    2222 
    23     $this->initCacheManager(); 
    24  
    2523    $this->connectEvents(); 
    2624     
     
    3331  } 
    3432 
    35   protected function initCacheManager() 
    36   { 
    37     dmCacheManager::createInstance($this->dispatcher); 
    38   } 
    3933 
    4034  protected function loadConfiguration() 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/cache/dmAPCCache.class.php

    r21631 r21916  
    6565    if (!is_null($val)) 
    6666    { 
     67      throw new dmException('No supported yet : need to reset all cache'); 
    6768      self::$enabled = (boolean) $val && self::isAvailable(); 
    68       dmCacheManager::getInstance()->reset(); 
    6969    } 
    7070 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/cache/dmCacheManager.php

    r21607 r21916  
    33class dmCacheManager 
    44{ 
    5   protected static 
    6     $instance; 
    7  
    85  protected 
    96    $dispatcher, 
    107    $caches; 
    118 
     9  public function __construct(sfEventDispatcher $dispatcher) 
     10  { 
     11    $this->dispatcher = $dispatcher; 
     12     
     13    $this->initialize(); 
     14  } 
     15     
    1216  public function initialize() 
    1317  { 
    1418    $this->reset(); 
    15     // event listeners 
    1619  } 
    1720 
    18   public function get($cacheName) 
     21  public function getCache($cacheName) 
    1922  { 
    2023    $cacheName = dmString::modulize($cacheName); 
     
    5659  } 
    5760 
    58   protected static function clearApc() 
     61  protected function clearApc() 
    5962  { 
    6063    apc_clear_cache('opcode'); 
     
    6265  } 
    6366 
    64   protected static function clearFile() 
     67  protected function clearFile() 
    6568  { 
    6669    sfToolkit::clearDirectory(sfConfig::get("sf_cache_dir")); 
    6770  } 
    6871 
    69   public function __construct(sfEventDispatcher $dispatcher) 
    70   { 
    71     $this->dispatcher = $dispatcher; 
    72   } 
    7372 
    74   /* 
    75    * Static methods 
    76    */ 
    77  
    78   public static function getCache($cacheName) 
    79   { 
    80     return self::getInstance()->get($cacheName); 
    81   } 
    82  
    83    
    84   /* 
    85    * @return dmCacheManager instance 
    86    */ 
    87   public static function getInstance() 
    88   { 
    89     if (is_null(self::$instance)) 
    90     { 
    91       throw new dmException('No instance of dmCacheManager were created'); 
    92     } 
    93  
    94     return self::$instance; 
    95   } 
    96  
    97   public static function createInstance(sfEventDispatcher $dispatcher, $class = __CLASS__) 
    98   { 
    99     $manager = new $class($dispatcher); 
    100     if (!$manager instanceof dmCacheManager) 
    101     { 
    102       throw new dmException('Cache manager must be an instance of dmCacheManager'); 
    103     } 
    104     $manager->initialize(); 
    105     self::$instance = $manager; 
    106   } 
    10773} 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/config/dmApplicationConfiguration.php

    r21423 r21916  
    1111abstract class dmApplicationConfiguration extends sfApplicationConfiguration 
    1212{ 
    13   /* 
    14    * Override this method in your application configuration class 
    15    * to change site for this request 
    16    */ 
    17   public function getCurrentSite() 
    18   { 
    19     return dmDb::table('DmSite')->getInstance(); 
    20   } 
    21    
    2213  /* 
    2314   * Wich dmPlugins are usefull for this application ? 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/config/dmProjectConfiguration.php

    r21423 r21916  
    2727  public function configureDoctrine(Doctrine_Manager $manager) 
    2828  { 
    29     include_once(dm::getDir().'/dmCorePlugin/lib/doctrine/config/dmDoctrineConfiguration.php'); 
    30      
    31     dmDoctrineConfiguration::createInstance($manager, $this->dispatcher)->initialize(); 
     29    Doctrine::debug(sfConfig::get("sf_debug")); 
     30 
     31    /* 
     32     * Set up doctrine extensions dir 
     33     */ 
     34    Doctrine::setExtensionsPath(sfConfig::get('dm_core_dir').'/lib/doctrine/extension'); 
     35 
     36    /* 
     37     * I want Doctrine to autoload table classes 
     38     */ 
     39    $manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true); 
     40 
     41    /* 
     42     * make $record->setSomething($value) override $record->_set('something', $value); 
     43     */ 
     44    $manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true); 
     45 
     46    /* 
     47     * Enable doctrine validators 
     48     */ 
     49    $manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL); 
     50 
     51    /* 
     52     * Configure inheritance 
     53     */ 
     54    $manager->setAttribute(Doctrine::ATTR_QUERY_CLASS, 'myDoctrineQuery'); 
     55    $manager->setAttribute(Doctrine::ATTR_COLLECTION_CLASS, 'myDoctrineCollection'); 
     56     
     57    /* 
     58     * Configure charset 
     59     */ 
     60    $manager->setCharset('utf8'); 
     61    $manager->setCollate('utf8_unicode_ci'); 
     62     
     63    /* 
     64     * Configure hydrators 
     65     */ 
     66    $manager->registerHydrator('dmFlat', 'Doctrine_Hydrator_dmFlat'); 
     67    $manager->registerHydrator('dmAssoc', 'Doctrine_Hydrator_dmAssoc'); 
     68     
     69    /* 
     70     * Configure builder 
     71     */ 
     72    sfConfig::set('doctrine_model_builder_options', array( 
     73      'generateTableClasses'  => true, 
     74      'baseClassName'         => 'myDoctrineRecord', 
     75      'baseTableClassName'    => 'myDoctrineTable', 
     76      'suffix'                => '.class.php' 
     77    )); 
    3278  } 
    3379 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/context/dmContext.php

    r21833 r21916  
    1111    $dmConfiguration, 
    1212    $helper, 
    13     $sfContext, 
    14     $pageTreeWatcher; 
     13    $sfContext; 
    1514 
    1615  abstract public function getModule(); 
     
    3130  { 
    3231    $this->loadServiceContainer(); 
    33   } 
    34    
    35   abstract public function loadServiceContainer(); 
    36    
    37   protected function doLoadServiceContainer($configFiles) 
     32     
     33    $this->getDoctrineConfig(); 
     34     
     35    $this->getPageTreeWatcher(); 
     36  } 
     37   
     38  /** 
     39   * Loads the diem services 
     40   */ 
     41  protected function loadServiceContainer() 
    3842  { 
    3943    $name = 'dm'.dmString::camelize(sfConfig::get('sf_app')).'ServiceContainer'; 
    4044     
    4145    $file = dmOs::join(sfConfig::get('dm_cache_dir'), 'services', $name.'.php'); 
    42      
     46   
     47    if (!is_dir(sfConfig::get('dm_cache_dir'))) 
     48    { 
     49      mkdir(sfConfig::get('dm_cache_dir'), 0777); 
     50    } 
    4351    if (!is_dir(dirname($file))) 
    4452    { 
     
    4654    } 
    4755      
    48     if (!sfConfig::get('sf_debug') && file_exists($file)) 
     56    if (/*!sfConfig::get('sf_debug') && */file_exists($file)) 
    4957    { 
    5058      require_once $file; 
     
    5462    { 
    5563      $sc = new sfServiceContainerBuilder; 
     64     
     65      $configFiles = $this->getSfContext()->getConfiguration()->getConfigPaths('config/dm/services.yml'); 
    5666       
    5767      $loader = new sfServiceContainerLoaderFileYaml($sc); 
    5868      $loader->load($configFiles); 
    5969      
    60       if (true || !sfConfig::get('sf_debug')
     70      if (true/* || !sfConfig::get('sf_debug')*/
    6171      { 
    6272        $dumper = new sfServiceContainerDumperPhp($sc); 
    6373        file_put_contents($file, $dumper->dump(array('class' => $name))); 
     74        chmod($file, 0777); 
    6475      } 
    6576       
     
    7081     
    7182    $this->serviceContainer->addParameters(array( 
    72       'dispatcher'  => $sfContext->getEventDispatcher(), 
    73       'user'        => $sfContext->getUser() 
     83      'dispatcher'        => $sfContext->getEventDispatcher(), 
     84      'user'              => $sfContext->getUser(), 
     85      'context'           => $sfContext, 
     86      'dm_context'        => $this, 
     87      'doctrine_manager'  => Doctrine_Manager::getInstance() 
    7488    )); 
    7589  } 
    7690   
    7791  /* 
     92   * @return dmSearchIndexGroup 
     93   */ 
     94  public function getSearchEngine() 
     95  { 
     96    return $this->serviceContainer->getService('search_engine'); 
     97  } 
     98   
     99  /* 
     100   * @return dmDoctrineConfiguration 
     101   */ 
     102  public function getDoctrineConfig() 
     103  { 
     104    return $this->serviceContainer->getService('doctrine_config'); 
     105  } 
     106   
     107  /* 
     108   * @return dmCacheManager 
     109   */ 
     110  public function getCacheManager() 
     111  { 
     112    return $this->serviceContainer->getService('cache_manager'); 
     113  } 
     114   
     115  /* 
    78116   * @return dmFilesystem 
    79117   */ 
     
    84122   
    85123  /* 
     124   * @return dmFileBackup 
     125   */ 
     126  public function getFileBackup() 
     127  { 
     128    return $this->serviceContainer->getService('file_backup'); 
     129  } 
     130   
     131  /* 
    86132   * @return dmUserLog 
    87133   */ 
     
    96142  public function getPageTreeWatcher() 
    97143  { 
    98     return $this->pageTreeWatcher
     144    return $this->serviceContainer->getService('page_tree_watcher')
    99145  } 
    100146   
     
    104150  public function getHelper() 
    105151  { 
    106     return $this->serviceContainer->getService('filesystem'); 
    107     if (is_null($this->helper)) 
    108     { 
    109       $this->helper = new dmOoHelper($this); 
    110     } 
    111  
    112     return $this->helper; 
     152    return $this->serviceContainer->getService('helper'); 
    113153  } 
    114154 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/dmFilter/dmInitFilter.php

    r21833 r21916  
    3939  protected function saveHtml() 
    4040  { 
    41     dmCacheManager::getCache("dm/view/html/validate")->set( 
     41    $this->dmContext->getCacheManager()->getCache("dm/view/html/validate")->set( 
    4242      session_id(), 
    4343      $this->context->getResponse()->getContent(), 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/doctrine/cache/Doctrine_Cache_Dm.php

    r21423 r21916  
    55class Doctrine_Cache_Dm extends Doctrine_Cache_Driver 
    66{ 
    7   protected 
    8   $cache; 
     7  protected 
     8  $cache; 
     9 
     10  /** 
     11   * Configure cache driver with an array of options 
     12   * 
     13   * @param array $_options      an array of options 
     14   */ 
     15  public function __construct($options = array()) 
     16  { 
     17    $this->_options = $options; 
     18     
     19    if (!isset($options['cache_manager'])) 
     20    { 
     21      throw new dmException('Not supported yet'); 
     22    } 
     23  } 
    924 
    1025  public function getCache() 
    1126  { 
    12   if (is_null($this->cache)) 
    13  
    14       $this->cache = dmCacheManager::getCache('dm/doctrine'); 
    15  
     27    if (is_null($this->cache)) 
     28   
     29      $this->cache = $this->_options['cache_manager']->getCache('dm/doctrine'); 
     30   
    1631 
    17   return $this->cache; 
     32    return $this->cache; 
    1833  } 
    1934 
     
    2944    if ($results = $this->getCache()->_get($id)) 
    3045    { 
    31     return $results; 
     46      return $results; 
    3247    } 
    3348    else 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/doctrine/config/dmDoctrineConfiguration.php

    r21768 r21916  
    33class dmDoctrineConfiguration 
    44{ 
    5   protected static 
    6   $instance; 
    7  
    85  protected 
    96  $manager, 
    10   $dispatcher; 
     7  $dispatcher, 
     8  $cacheManager; 
    119 
    12   public static function getInstance(
     10  public function __construct(Doctrine_Manager $manager, sfEventDispatcher $dispatcher, dmCacheManager $cacheManager
    1311  { 
    14     if(is_null(self::$instance)) 
    15     { 
    16       throw new dmException('dmDoctrineConfiguration has no instance'); 
    17     } 
    18  
    19     return self::$instance; 
    20   } 
    21  
    22   public static function createInstance(Doctrine_Manager $manager, sfEventDispatcher $dispatcher) 
    23   { 
    24     return self::$instance = new self($manager, $dispatcher); 
    25   } 
    26  
    27   public function __construct(Doctrine_Manager $manager, sfEventDispatcher $dispatcher) 
    28   { 
    29     $this->manager = $manager; 
    30     $this->dispatcher = $dispatcher; 
     12    $this->manager = $manager; 
     13    $this->dispatcher = $dispatcher; 
     14    $this->cacheManager = $cacheManager; 
     15     
     16    $this->initialize(); 
    3117  } 
    3218 
    3319  public function initialize() 
    3420  { 
    35     Doctrine::debug(sfConfig::get("sf_debug")); 
    36  
    37     /* 
    38      * I want Doctrine to autoload table classes 
    39      */ 
    40     $this->manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true); 
    41  
    42     /* 
    43      * make $record->setSomething($value) override $record->_set('something', $value); 
    44      */ 
    45     $this->manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true); 
    46  
    47     /* 
    48      * Enable doctrine validators 
    49      */ 
    50     $this->manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL); 
    51  
    52     /* 
    53      * Set up doctrine extensions dir 
    54      */ 
    55     Doctrine::setExtensionsPath(sfConfig::get('sf_root_dir').'/plugins/dmCorePlugin/lib/doctrine/extension'); 
    56  
    57     $this 
    58     ->configureInheritance() 
    59     ->configureCharset() 
    60     ->configureBuilder() 
    61     ->configureHydrator(); 
    62      
    63     $this->dispatcher->connect('context.load_factories', array($this, 'configureCache')); 
    64    
    65     return $this; 
     21    $this->configureCache(); 
    6622  } 
    6723 
    68   protected function configureInheritance() 
    69   { 
    70     $this->manager->setAttribute(Doctrine::ATTR_QUERY_CLASS, 'myDoctrineQuery'); 
    71     $this->manager->setAttribute(Doctrine::ATTR_COLLECTION_CLASS, 'MyDoctrineCollection'); 
    72  
    73     return $this; 
    74   } 
    75  
    76   protected function configureCharset() 
    77   { 
    78     $this->manager->setCharset('utf8'); 
    79     $this->manager->setCollate('utf8_unicode_ci'); 
    80  
    81     return $this; 
    82   } 
    83  
    84   protected function configureBuilder() 
    85   { 
    86     sfConfig::set('doctrine_model_builder_options', array( 
    87       'generateTableClasses'  => true, 
    88       'baseClassName'         => 'myDoctrineRecord', 
    89       'baseTableClassName'    => 'myDoctrineTable', 
    90       'suffix'                => '.class.php' 
    91     )); 
    92  
    93     return $this; 
    94   } 
    95  
    96   protected function configureHydrator() 
    97   { 
    98     $this->manager->registerHydrator('dmFlat', 'Doctrine_Hydrator_dmFlat'); 
    99     $this->manager->registerHydrator('dmAssoc', 'Doctrine_Hydrator_dmAssoc'); 
    100  
    101     return $this; 
    102   } 
    103  
    104   /* 
    105    * Needs diem project config to be loaded 
    106    */ 
    107   public function configureCache() 
     24  protected function configureCache() 
    10825  { 
    10926    if (!sfConfig::get('dm_orm_cache_enabled', true)) 
     
    13653  public function desactivateCache() 
    13754  { 
    138     self::activateCache(false); 
     55    $this->activateCache(false); 
    13956  } 
    14057 
    14158  protected function getCacheDriver() 
    14259  { 
    143     return new Doctrine_Cache_Dm(); 
     60    return new Doctrine_Cache_Dm(array( 
     61      'cache_manager' => $this->cacheManager 
     62    )); 
    14463  } 
    14564} 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/doctrine/database/dmDb.php

    r21423 r21916  
    5656  public static function cache($val) 
    5757  { 
    58     dmDoctrineConfiguration::getInstance()->activateCache((bool) $val); 
     58    dmContext::getInstance()->getDoctrineConfig()->activateCache((bool) $val); 
    5959  } 
    6060} 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/log/user/dmUserLog.php

    r21833 r21916  
    66  $dispatcher, 
    77  $filesystem, 
    8   $dir, 
    98  $file; 
    109   
    11   public function __construct(sfEventDispatcher $dispatcher, dmFileSystem $filesystem
     10  public function __construct(sfEventDispatcher $dispatcher, dmFileSystem $filesystem, array $options = array()
    1211  { 
    1312    $this->dispatcher = $dispatcher; 
    1413    $this->filesystem = $filesystem; 
    1514     
    16     $this->initialize(); 
     15    $this->initialize($options); 
    1716  } 
    1817   
    19   public function initialize(
     18  public function initialize(array $options = array()
    2019  { 
    21     $this->dir  = dmOs::join(sfConfig::get('dm_data_dir'), 'log'); 
    22     $this->file = dmOs::join($this->dir, 'user.log'); 
     20    $this->file = dmProject::rootify(dmArray::get($options, 'file', 'data/dm/log/user.log')); 
    2321  } 
    2422   
     
    6159  protected function checkFile() 
    6260  { 
    63     if (!$this->filesystem->mkdir($this->dir)) 
     61    if (!$this->filesystem->mkdir(dirname($this->file))) 
    6462    { 
    65       throw new dmException(sprintf('User log dir %s can not be created', $this->dir)); 
     63      throw new dmException(sprintf('User log dir %s can not be created', dirname($this->file))); 
    6664    } 
    6765     
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/model/doctrine/media/PluginDmMedia.class.php

    r21648 r21916  
    280280    { 
    281281//      dmDebug::kill('unlink '.$this->fullPath, $this); 
    282       dmFilesystem::get()->unlink($this->fullPath); 
     282      dmContext::getInstance()->getFilesystem()->unlink($this->fullPath); 
    283283    } 
    284284 
     
    299299    ->in(dmOs::join($this->Folder->getFullPath(), '.thumbs')); 
    300300 
    301     return dmFilesystem::get()->unlink($thumbs); 
     301    return dmContext::getInstance()->getFilesystem()->unlink($thumbs); 
    302302  } 
    303303 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/model/doctrine/media/PluginDmMediaFolder.class.php

    r21423 r21916  
    171171  public function create() 
    172172  { 
    173     return dmFilesystem::get()->mkdir($this->getFullPath()); 
     173    return dmContext::getInstance()->getFilesystem()->mkdir($this->getFullPath()); 
    174174  } 
    175175 
     
    193193      $oldName = $this->name; 
    194194 
    195       $fs = dmFilesystem::get(); 
     195      $fs = dmContext::getInstance()->getFilesystem(); 
    196196 
    197197      if(!$fs->exec(sprintf('cd %s && mv %s %s', 
     
    403403    if(!$this->getNode()->isRoot() && $this->dirExists()) 
    404404    { 
    405       dmFilesystem::get()->deleteDir($this->fullPath); 
     405      dmContext::getInstance()->getFilesystem()->deleteDir($this->fullPath); 
    406406    } 
    407407 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/model/doctrine/page/PluginDmPage.class.php

    r21593 r21916  
    300300    $command = sprintf('dmFront:page-indexable-content %d %s', $this->get('id'), self::getDefaultCulture()); 
    301301     
    302     $filesystem = dmFilesystem::get(); 
     302    $filesystem = dmContext::getInstance()->getFilesystem(); 
    303303     
    304304    $filesystem->sf($command); 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/page/dmPageTreeWatcher.php

    r21633 r21916  
    44{ 
    55  protected 
    6   $dmContext
     6  $dispatcher
    77  $modifiedTables; 
    88 
    9   public function __construct(dmContext $dmContext
     9  public function __construct(sfEventDispatcher $dispatcher
    1010  { 
    11     $this->dmContext = $dmContext; 
    12  
    13     $this->dmContext->getSfContext()->getEventDispatcher()->connect('dm.controller.redirect', array($this, 'listenRedirection')); 
    14  
    15     $this->initialize(); 
     11    $this->dispatcher = $dispatcher; 
     12     
     13    $this->initialize(); 
    1614  } 
    1715 
     
    1917  { 
    2018    $this->modifiedTables = array(); 
     19     
     20    $this->dispatcher->connect('dm.controller.redirect', array($this, 'listenRedirection')); 
    2121  } 
    22  
    2322   
    2423  public function addModifiedTable(myDoctrineTable $table) 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/project/dmFileBackup.php

    r21823 r21916  
    11<?php 
    22 
    3 class dmBackup 
     3class dmFileBackup 
    44{ 
    55  protected 
    6   $dir, 
    7   $filesystem; 
     6  $dispatcher, 
     7  $filesystem, 
     8  $dir; 
    89   
    9   public function __construct($dir
     10  public function __construct(sfEventDispatcher $dispatcher, dmFilesystem $filesystem, array $options = array()
    1011  { 
    11     $this->dir = is_null($dir) 
    12     ? dmOs::join(sfConfig::get('dm_data_dir'), 'backup/fs') 
    13     : $dir; 
     12    $this->dispatcher = $dispatcher; 
     13    $this->filesystem = $filesystem; 
    1414     
    15     $this->filesystem = new dmFilesystem; 
     15    $this->initialize($options); 
     16  } 
     17   
     18  public function initialize(array $options = array()) 
     19  { 
     20    $this->dir = dmProject::rootify(dmArra::get($options, 'dir', 'data/dm/backup/filesystem')); 
    1621     
    1722    $this->checkDirIsWritable(); 
     
    7580    if (!$this->filesystem->mkdir($this->getDir())) 
    7681    { 
    77       throw new dmException('dmBackup dir is not writable : '.$this->getDir()); 
     82      throw new dmException('dmFileBackup dir is not writable : '.$this->getDir()); 
    7883    } 
    7984  } 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/project/dmProject.php

    r21833 r21916  
    4545      sfConfig::get('sf_cache_dir'), 
    4646      sfConfig::get('dm_cache_dir'), 
     47      dmOs::join(sfConfig::get('dm_cache_dir'), 'services'), 
    4748      sfConfig::get('sf_log_dir'), 
    48       sfConfig::get('dm_data_dir'), 
    49       dmOs::join(sfConfig::get('dm_data_dir'), 'backup'), 
    50       dmOs::join(sfConfig::get('dm_data_dir'), 'index'), 
    51       dmOs::join(sfConfig::get('dm_data_dir'), 'log'), 
     49//      sfConfig::get('dm_data_dir'), 
     50//      dmOs::join(sfConfig::get('dm_data_dir'), 'backup'), 
     51//      dmOs::join(sfConfig::get('dm_data_dir'), 'index'), 
     52//      dmOs::join(sfConfig::get('dm_data_dir'), 'log'), 
    5253      sfConfig::get('sf_upload_dir'), 
    53       dmOs::join(sfConfig::get('sf_lib_dir'), 'migration/doctrine'), 
    54       dmOs::join(sfConfig::get('dm_cache_dir'), 'services') 
     54      dmOs::join(sfConfig::get('sf_lib_dir'), 'migration/doctrine') 
    5555    ); 
    56      
    57     $fs = dmFilesystem::get(); 
    5856 
    5957    $messages = array(); 
     
    6159    foreach($requiredWritableDirs as $requiredWritableDir) 
    6260    { 
    63       if(!$fs->mkdir($requiredWritableDir)) 
     61      if (!is_dir($requiredWritableDir)) 
     62      { 
     63        $oldUmask = umask(0); 
     64        mkdir($requiredWritableDir, 0777, true); 
     65        umask($oldUmask); 
     66      } 
     67     
     68      if(!is_writable($requiredWritableDir)) 
    6469      { 
    6570        $messages[] = sprintf( 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/search/dmSearchIndex.php

    r21823 r21916  
    33require_once('Zend/Search/Lucene.php'); 
    44 
    5 abstract class dmSearchIndex extends dmSearchIndexCommon 
     5class dmSearchIndex extends dmSearchIndexCommon 
    66{ 
    77  protected 
     
    9696    { 
    9797      $this->getLogger()->log($page->get('slug'), 'Indexing page'); 
    98       $this->index->addDocument(new mySearchPageDocument($page)); 
     98      $this->index->addDocument(new dmSearchPageDocument($page)); 
    9999    } 
    100100 
     
    146146  protected function erase() 
    147147  { 
    148     dmFilesystem::get()->deleteDirContent($this->location); 
     148    $this->filesystem->deleteDirContent($this->location); 
    149149    $this->index = Zend_Search_Lucene::create($this->location); 
    150150  } 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/search/dmSearchIndexGroup.php

    r21423 r21916  
    11<?php 
    22 
    3 abstract class dmSearchIndexGroup extends dmSearchIndexCommon 
     3class dmSearchIndexGroup extends dmSearchIndexCommon 
    44{ 
    55  /** 
     
    4848    foreach(sfConfig::get('dm_i18n_cultures') as $culture) 
    4949    { 
    50       $index = new mySearchIndex($culture); 
     50      $index = new dmSearchIndex($culture); 
    5151      $this->addIndex($index->getName(), $index); 
    5252    } 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/search/dmSearchPageDocument.php

    r21423 r21916  
    11<?php 
    22 
    3 abstract class dmSearchPageDocument extends Zend_Search_Lucene_Document 
     3class dmSearchPageDocument extends Zend_Search_Lucene_Document 
    44{ 
    55  protected static 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/service/dmAdminGenerateService.php

    r21423 r21916  
    5555          $moduleDir = sfConfig::get('sf_app_module_dir').'/'.$moduleKey; 
    5656 
    57           dmFilesystem::get()->unlink(dmOs::join($moduleDir, 'generator.yml')); 
     57          dmContext::getInstance()->getFilesystem()->unlink(dmOs::join($moduleDir, 'generator.yml')); 
    5858        } 
    5959      } 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/service/dmClearCacheService.php

    r21607 r21916  
    88    $this->log("clear cache"); 
    99     
    10     dmCacheManager::getInstance()->clearAll(); 
     10    dmContext::getInstance()->getCacheManager()->clearAll(); 
    1111 
    1212    if(count($survivors = $this->filesystem->find()->maxdepth(0)->in(sfConfig::get("sf_cache_dir")))) 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/task/dmFrontPageIndexableContentTask.class.php

    r21516 r21916  
    7070          if (!in_array($widget['module'].'.'.$widget['action'], self::$skipWidgets)) 
    7171          { 
    72             $widgetViewClass = dmWidgetTypeManager::getWidgetType($widget['module'], $widget['action'])->getViewClass(); 
     72            $widgetViewClass = $dmContext->getWidgetTypeManager()->getWidgetType($widget['module'], $widget['action'])->getViewClass(); 
    7373   
    7474            $widgetView = new $widgetViewClass($widget); 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/task/dmSearchUpdateTask.class.php

    r21423 r21916  
    3434    $this->log('Search engine index update'); 
    3535     
    36     $index = new mySearchIndexGroup
     36    $index = dmContext::getInstance()->getSearchEngine()
    3737    $index->setLogger(new dmLoggerTask($this->dispatcher, $this->formatter)); 
    3838     
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/view/css/dmSpriteGenerator.php

    r21423 r21916  
    1010  public function __construct(sfEventDispatcher $dispatcher) 
    1111  { 
    12     $this->filesystem = dmFilesystem::get(); 
     12    $this->filesystem = dmContext::getInstance()->getFilesystem(); 
    1313  } 
    1414 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/view/dmOoHelper.php

    r21423 r21916  
    33class dmOoHelper 
    44{ 
     5  protected 
     6  $context; 
    57 
    6   protected 
    7   $dmContext; 
    8  
    9   public function __construct(dmContext $dmContext) 
     8  public function __construct(sfContext $context) 
    109  { 
    11     $this->dmContext = $dmContext; 
     10    $this->context = $context; 
    1211  } 
    1312 
     
    2423 
    2524    $class = sfConfig::get('mod_'.strtolower($moduleName).'_partial_view_class', 'sf').'PartialView'; 
    26     $view = new $class($this->dmContext->getSfContext(), $moduleName, $actionName, ''); 
     25    $view = new $class($this->context, $moduleName, $actionName, ''); 
    2726    $view->setPartialVars($vars); 
    2827 
     
    3231  public function renderComponent($moduleName, $componentName, $vars = array()) 
    3332  { 
    34     sfContext::getInstance()->getConfiguration()->loadHelpers('Partial'); 
     33    $this->context->getConfiguration()->loadHelpers('Partial'); 
    3534    return get_component($moduleName, $componentName, $vars); 
    3635  } 
  • plugins/diemPlugin/trunk/dmCorePlugin/lib/view/html/media/dmMediaImageTag.php

    r21833 r21916  
    129129    } 
    130130 
    131     if(!dmFilesystem::get()->mkdir($thumbDir = dmOs::join($media->Folder->fullPath, '.thumbs'))) 
     131    if(!dmContext::getInstance()->getFilesystem()->mkdir($thumbDir = dmOs::join($media->Folder->fullPath, '.thumbs'))) 
    132132    { 
    133133      dm::getUser()->logAlert(dm::getI18n()->__('Thumbnails can not be created in %1%', array('%1%' => $media->Folder->relPath)), false); 
  • plugins/diemPlugin/trunk/dmCorePlugin/modules/dmCore/actions/actions.class.php

    r21423 r21916  
    1818    $this->doctype = sfConfig::get('dm_w3c_doctype', 'XHTML'); 
    1919 
    20     $this->validator = new dmHtmlValidator(dmCacheManager::getCache("dm/view/html/validate")->get(session_id())); 
     20    $this->validator = new dmHtmlValidator($this->dmContext->getCache("dm/view/html/validate")->get(session_id())); 
    2121  } 
    2222 
  • plugins/diemPlugin/trunk/dmCorePlugin/test/unit/dmCacheTest.php

    r21423 r21916  
    55$t = new lime_test(7, new lime_output_color()); 
    66 
    7 $cache = dmCacheManager::getInstance("dm/test"); 
     7$cache = dmContext::getInstance()->getCacheManager()->getCache("dm/test"); 
    88 
    99$t->ok( 
  • plugins/diemPlugin/trunk/dmFrontPlugin/config/dm/services.yml

    r21833 r21916  
    11parameters: 
    2   filesystem.class:       dmFilesystem 
    3   user_log.class:         dmUserLog 
    4   page_helper.class:      dmFrontPageHelper 
     2  page_helper.class:          dmFrontPageHelper 
     3  widget_type_manager.class:  dmWidgetTypeManager 
     4  widget_type_manager.options: 
     5    config_files:             'config/dm/widget_types.yml'         
    56  
    67services: 
    78 
    8   filesystem
    9     class:                %filesystem.class% 
    10     shared:               true 
     9  page_helper
     10    class:                    %page_helper.class% 
     11    shared:                   true 
    1112    arguments: 
    12       dispatcher:         %dispatcher% 
    13        
    14   user_log: 
    15     class:                %user_log.class% 
    16     shared:               true 
     13      dispatcher:             %dispatcher% 
     14      dm_context:             %dm_context% 
     15      filesystem:             @filesystem 
     16 
     17  widget_type_manager: 
     18    class:                    %widget_type_manager.class% 
     19    shared:                   true 
    1720    arguments: 
    18       dispatcher:         %dispatcher% 
    19       filesystem:         @filesystem 
    20  
    21   page_helper: 
    22     class:                %page_helper.class% 
    23     shared:               true 
    24     arguments: 
    25       dispatcher:         %dispatcher% 
    26       page:               %page% 
    27       filesystem:         @filesystem 
     21      dispatcher:             %dispatcher% 
     22      cache_manager:          @cache_manager 
     23      context:                %context% 
     24      options:                %widget_type_manager.options% 
  • plugins/diemPlugin/trunk/dmFrontPlugin/lib/context/dmFrontContext.php

    r21833 r21916  
    77  protected 
    88    $page; 
    9  
    10   /** 
    11    * Loads the diem services 
    12    */ 
    13   public function loadServiceContainer() 
    14   { 
    15     $configFiles = dmOs::join(sfConfig::get('dm_front_dir'), 'config/dm/services.yml'); 
    16      
    17     parent::doLoadServiceContainer($configFiles); 
    18   } 
    199   
    2010  public function getPage() 
    2111  { 
    22     return $this->serviceContainer->getParameter('page')
     12    return $this->page
    2313  } 
    2414 
    2515  public function getPageHelper() 
    2616  { 
    27     return $this->serviceContainer->getService('page_helper'); 
     17    return $this->serviceContainer->getService('page_helper'); 
     18  } 
     19 
     20  public function getWidgetTypeManager() 
     21  { 
     22    return $this->serviceContainer->getService('widget_type_manager'); 
    2823  } 
    2924   
     
    4237  public function setPage(DmPage $page = null) 
    4338  { 
    44     $this->serviceContainer->addParameters(array( 
    45       'page' => $page 
    46     )); 
     39    $this->page = $page; 
    4740     
    48     $this->getPageHelper()->setPage($page); 
     41    $this->getPageHelper()->initialize(); 
    4942  } 
    5043 
  • plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/base/dmWidgetBaseView.php

    r21516 r21916  
    55 
    66  protected 
     7  $dmContext, 
    78  $widget, 
    89  $widgetType, 
    910  $requiredVars = array(); 
    1011 
    11   public function __construct(array $widget
     12  public function __construct(array $widget, dmContext $dmContext
    1213  { 
     14    $this->dmContext = $dmContext; 
    1315    $this->widget = $widget; 
    14     $this->widgetType = dmWidgetTypeManager::getWidgetType($widget['module'], $widget['action']); 
     16    $this->widgetType = $dmContext->getWidgetTypeManager()->getWidgetType($widget['module'], $widget['action']); 
    1517 
    1618    $this->configure(); 
  • plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/search/dmWidgetAdvancedSearchResultsView.php

    r21489 r21916  
    2626  protected function getResultsPager(array $vars) 
    2727  { 
    28     $this->index = new mySearchIndexGroup
     28    $this->index = $this->dmContext->getSearchEngine()
    2929     
    3030    if(count($results = $this->index->search($vars['query']))) 
  • plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidgetType/dmWidgetTypeManager.php

    r21516 r21916  
    44{ 
    55 
    6   protected static 
    7   $configFile = 'config/dm/widget_types.yml', 
     6  protected 
     7  $dispatcher, 
     8  $cacheManager, 
     9  $context, 
     10  $configFile, 
    811  $widgetTypes; 
    912 
    10   public static function getWidgetTypes() 
     13  public function construct(sfEventDispatcher $dispatcher, dmCacheManager $cacheManager, sfContext $context, array $options = array()) 
     14  { 
     15    $this->dispatcher   = $dispatcher; 
     16    $this->cacheManager = $cacheManager; 
     17    $this->context      = $context; 
     18     
     19    $this->initialize($options); 
     20  } 
     21   
     22  public function initialize(array $options = array()) 
     23  { 
     24    $this->configFile = dmArray::get($options, 'config_files', 'config/dm/widget_types.yml'); 
     25     
     26    $this->widgetTypes = null; 
     27  } 
     28   
     29  public function getWidgetTypes() 
    1130  { 
    1231    $timer = dmDebug::timer('dmWidgetTypeManager::getWidgetTypes'); 
    13     if (is_null(self::$widgetTypes)) 
     32     
     33    if (is_null($this->widgetTypes)) 
    1434    { 
    15       if (!self::$widgetTypes = dmCacheManager::getCache('dm/widget')->get('types')) 
     35      if (!$this->widgetTypes = $this->cacheManager->getCache('dm/widget')->get('types')) 
    1636      { 
    17         $internalConfig = include(sfContext::getInstance()->getConfigCache()->checkConfig(self::$configFile)); 
     37        $internalConfig = include($this->context->getConfigCache()->checkConfig($this->configFile)); 
    1838 
    19         $sfController = sfContext::getInstance()->getController(); 
     39        $sfController = $this->context->getController(); 
    2040 
    21         self::$widgetTypes = array(); 
     41        $this->widgetTypes = array(); 
    2242 
    2343        foreach($internalConfig as $moduleKey => $actions) 
    2444        { 
    25           self::$widgetTypes[$moduleKey] = array(); 
     45          $this->widgetTypes[$moduleKey] = array(); 
    2646 
    2747          foreach($actions as $actionKey => $action) 
     
    3656            ); 
    3757 
    38             self::$widgetTypes[$moduleKey][$actionKey] = new dmWidgetType($moduleKey, $actionKey, $widgetTypeConfig); 
     58            $this->widgetTypes[$moduleKey][$actionKey] = new dmWidgetType($moduleKey, $actionKey, $widgetTypeConfig); 
    3959          } 
    4060        } 
     
    4464          $moduleName = $module->getName(); 
    4565 
    46           self::$widgetTypes[$moduleKey] = array(); 
     66          $this->widgetTypes[$moduleKey] = array(); 
    4767 
    4868          foreach($module->getActions() as $actionKey => $action) 
     
    5777            ); 
    5878 
    59             self::$widgetTypes[$moduleKey][$actionKey] = new dmWidgetType($moduleKey, $actionKey, $widgetTypeConfig); 
     79            $this->widgetTypes[$moduleKey][$actionKey] = new dmWidgetType($moduleKey, $actionKey, $widgetTypeConfig); 
    6080          } 
    6181        } 
    6282      } 
    63       dmCacheManager::getCache('dm/widget')->set('types', self::$widgetTypes); 
     83      $dmContext->getCacheManager()->getCache('dm/widget')->set('types', $this->widgetTypes); 
    6484    } 
    6585 
    6686    $timer->addTime(); 
    67     return self::$widgetTypes; 
     87    return $this->widgetTypes; 
    6888  } 
    6989 
    70   public static function getWidgetType($moduleOrWidget, $action = null, $orNull = false) 
     90  public function getWidgetType($moduleOrWidget, $action = null, $orNull = false) 
    7191  { 
    7292    if ($moduleOrWidget instanceof DmWidget) 
     
    7999    } 
    80100 
    81     $widgetType = dmArray::get(dmArray::get(self::getWidgetTypes(), dmString::modulize($module), array()), dmString::modulize($action)); 
     101    $widgetType = dmArray::get(dmArray::get($this->getWidgetTypes(), dmString::modulize($module), array()), dmString::modulize($action)); 
    82102 
    83103    if (!$widgetType) 
     
    88108      } 
    89109//      dmDebug::stack(); 
    90 //      dmDebug::kill(self::getWidgetTypes()); 
     110//      dmDebug::kill($this->getWidgetTypes()); 
    91111      throw new dmException(sprintf("The %s.%s module does not exist", $module, $action)); 
    92112    } 
     
    95115  } 
    96116 
    97   public static function getWidgetTypeOrNull($moduleOrWidget, $action = null) 
     117  public function getWidgetTypeOrNull($moduleOrWidget, $action = null) 
    98118  { 
    99     return self::getWidgetType($moduleOrWidget, $action, true); 
     119    return $this->getWidgetType($moduleOrWidget, $action, true); 
    100120  } 
    101121 
  • plugins/diemPlugin/trunk/dmFrontPlugin/lib/generator/dmFrontModuleGenerator.php

    r21665 r21916  
    1313    $this->module = $module; 
    1414    $this->dispatcher = $dispatcher; 
    15     $this->filesystem = new dmFilesystem
     15    $this->filesystem = dmContext::getInstance()->getFilesystem()
    1616  } 
    1717 
  • plugins/diemPlugin/trunk/dmFrontPlugin/lib/view/html/page/dmFrontPageHelper.php

    r21833 r21916  
    55  protected 
    66    $dispatcher, 
    7     $page
     7    $dmContext
    88    $areas; 
    99 
    10   public function __construct(sfEventDispatcher $dispatcher, DmPage $page
     10  public function __construct(sfEventDispatcher $dispatcher, dmContext $dmContext
    1111  { 
    1212    $this->dispatcher = $dispatcher; 
    13     $this->page       = $page; 
    14   } 
    15    
    16   public function setPage(DmPage $page) 
    17   { 
    18     $this->page = $page; 
     13    $this->dmContext  = $dmContext; 
     14     
     15    $this->initialize(); 
     16  } 
     17   
     18  public function initialize() 
     19  { 
     20    $this->areas = null; 
     21  } 
     22   
     23  public function getPage() 
     24  { 
     25    return $this->dmContext->getPage(); 
    1926  } 
    2027   
     
    2532      $this->areas = dmDb::query('DmArea a INDEXBY a.type, a.Zones z, z.Widgets w') 
    2633      ->select('a.type, z.width, z.css_class, w.module, w.action, w.value, w.css_class') 
    27       ->where('a.dm_layout_id = ? OR a.dm_page_view_id = ?', array($this->page->getPageView()->get('Layout')->get('id'), $this->page->getPageView()->get('id'))) 
     34      ->where('a.dm_layout_id = ? OR a.dm_page_view_id = ?', array($this->getPage()->getPageView()->get('Layout')->get('id'), $this->getPage()->getPageView()->get('id'))) 
    2835      ->orderBy('z.position asc, w.position asc') 
    2936      ->fetchArray(); 
     
    3946    if (!isset($this->areas[$type])) 
    4047    { 
    41       throw new dmException(sprintf('Page %s with layout %s has no area for type %s', $this->page, $this->page->Layout, $type)); 
     48      throw new dmException(sprintf('Page %s with layout %s has no area for type %s', $this->getPage(), $this->getPage()->Layout, $type)); 
    4249      return null; 
    4350    } 
     
    196203      if (is_null($widgetType)) 
    197204      { 
    198         $widgetType = dmWidgetTypeManager::getWidgetType($widget['module'], $widget['action']); 
     205        $widgetType = $dmContext->getWidgetTypeManager()->getWidgetType($widget['module'], $widget['action']); 
    199206      } 
    200207   
    201208      $widgetViewClass = $widgetType->getViewClass(); 
    202209   
    203       $widgetView = new $widgetViewClass($widget); 
     210      $widgetView = new $widgetViewClass($widget, $this->dmContext); 
    204211       
    205212      $html = $widgetView->render(); 
  • plugins/diemPlugin/trunk/dmFrontPlugin/modules/dmCodeEditor/actions/actions.class.php

    r21423 r21916  
    5757    try 
    5858    { 
    59       $backup = new dmBackup(); 
    60       $backup->save($file); 
     59      $this->getDmContext()->getFileBackup()->save($file); 
    6160    } 
    6261    catch(dmException $e) 
  • plugins/diemPlugin/trunk/dmFrontPlugin/modules/dmInterface/actions/components.class.php

    r21768 r21916  
    3737      ); 
    3838    } 
    39  
    40     foreach(dmWidgetTypeManager::getWidgetTypes() as $space => $widgetTypes) 
     39     
     40    foreach($this->getDmContext()->getWidgetTypeManager()->getWidgetTypes() as $space => $widgetTypes) 
    4141    { 
    4242      if (empty($widgetTypes)) 
  • plugins/diemPlugin/trunk/dmFrontPlugin/modules/dmWidget/actions/actions.class.php

    r21726 r21916  
    1414    ); 
    1515 
    16     if (!$widgetType = dmWidgetTypeManager::getWidgetTypeOrNull($widget)) 
     16    if (!$widgetType = $this->getDmContext()->getWidgetTypeManager()->getWidgetTypeOrNull($widget)) 
    1717    { 
    1818      return $this->renderText(sprintf('<p class="s16 s16_error">%s</p><div class="clearfix mt30"><a class="dm cancel close_dialog button mr10">%s</a><a class="dm delete button red" title="%s">%s</a></div>', 
     
    142142    ); 
    143143 
    144     $widgetType = dmWidgetTypeManager::getWidgetType($widgetModule, $widgetAction); 
     144    $widgetType = $this->getDmContext()->getWidgetTypeManager()->getWidgetType($widgetModule, $widgetAction); 
    145145 
    146146    $formClass = $widgetType->getFormClass();