Ignore:
Timestamp:
Apr 14, 2015, 10:20:16 PM (9 years ago)
Author:
chronos
Message:
  • Removed: Spaces on end of line.
  • Modified: Tabs converted to spaces.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/AppModule.php

    r731 r738  
    11<?php
    22
    3 /* This implementation will not support installation from remote source. Just 
     3/* This implementation will not support installation from remote source. Just
    44 * installation of already presented modules mainly to persistence preparation.
    55 */
     
    77class ModuleType
    88{
    9         const System = 0;
    10         const Normal = 1;
    11         const Application = 2;
     9  const System = 0;
     10  const Normal = 1;
     11  const Application = 2;
    1212}
    1313
     
    4040  var $Title;
    4141  var $Version;
    42   var $License; 
     42  var $License;
    4343  var $Creator;
    4444  var $HomePage;
     
    5858  var $Manager;
    5959  var $OnChange;
    60  
     60
    6161  function __construct(System $System)
    6262  {
     
    7474    $this->Type = ModuleType::Normal;
    7575  }
    76  
     76
    7777  function Install()
    7878  {
     
    8282    $this->Manager->Perform($List, array(ModuleAction::Install), array(ModuleCondition::NotInstalled));
    8383    $this->DoInstall();
    84         $this->Installed = true;
    85         $this->InstalledVersion = $this->Version;
    86         $this->Manager->Modules[$this->Name] = $this;
    87   }
    88  
     84    $this->Installed = true;
     85    $this->InstalledVersion = $this->Version;
     86    $this->Manager->Modules[$this->Name] = $this;
     87  }
     88
    8989  function Uninstall()
    9090  {
     
    9797    $this->DoUninstall();
    9898  }
    99  
     99
    100100  function Upgrade()
    101101  {
     
    106106    $this->DoUpgrade();
    107107  }
    108  
     108
    109109  function Reinstall()
    110110  {
     
    113113    $this->Install();
    114114  }
    115  
     115
    116116  function Start()
    117117  {
    118118    if($this->Running) return;
    119     if(!$this->Installed) return; 
     119    if(!$this->Installed) return;
    120120    $List = array();
    121121    $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotRunning));
    122122    $this->Manager->Perform($List, array(ModuleAction::Start), array(ModuleCondition::NotRunning));
    123123    $this->DoStart();
    124         $this->Running = true;
    125   }
    126  
     124    $this->Running = true;
     125  }
     126
    127127  function Stop()
    128128  {
    129         if(!$this->Running) return;
     129    if(!$this->Running) return;
    130130    $this->Running = false;
    131         $List = array();
    132         $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Running));
     131    $List = array();
     132    $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Running));
    133133    $this->Manager->Perform($List, array(ModuleAction::Stop), array(ModuleCondition::Running));
    134         $this->DoStop(); 
    135   }   
    136  
     134    $this->DoStop();
     135  }
     136
    137137  function Restart()
    138138  {
     
    140140    $this->Start();
    141141  }
    142  
     142
    143143  function Enable()
    144144  {
     
    150150    $this->Enabled = true;
    151151  }
    152  
     152
    153153  function Disable()
    154154  {
     
    160160    $this->Manager->Perform($List, array(ModuleAction::Disable), array(ModuleCondition::Enabled));
    161161  }
    162  
     162
    163163  protected function DoStart()
    164164  {
    165165  }
    166  
     166
    167167  protected function DoStop()
    168   {   
     168  {
    169169  }
    170170
     
    172172  {
    173173  }
    174  
     174
    175175  protected function DoUninstall()
    176176  {
     
    179179
    180180/* Manage installed modules */
    181 class AppModuleManager 
     181class AppModuleManager
    182182{
    183183  var $Modules;
     
    185185  var $FileName;
    186186  var $OnLoadModules;
    187  
     187
    188188  function __construct(System $System)
    189189  {
    190190    $this->Modules = array();
    191191    $this->System = &$System;
    192     $this->FileName = 'Config/Modules.php';     
    193   }
    194  
     192    $this->FileName = 'Config/Modules.php';
     193  }
     194
    195195  function Perform($List, $Actions, $Conditions = array(ModuleCondition::All))
    196196  {
     
    217217    }
    218218  }
    219  
     219
    220220  function EnumDependenciesCascade($Module, &$List, $Conditions = array(ModuleCondition::All))
    221221  {
     
    236236    }
    237237  }
    238  
     238
    239239  function EnumSuperiorDependenciesCascade($Module, &$List, $Conditions = array(ModuleCondition::All))
    240240  {
    241241    foreach($this->Modules as $RefModule)
    242242    {
    243       if(in_array($Module->Name, $RefModule->Dependencies) and 
     243      if(in_array($Module->Name, $RefModule->Dependencies) and
    244244          (in_array(ModuleCondition::All, $Conditions) or
    245245          ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or
     
    255255    }
    256256  }
    257  
     257
    258258  function Start()
    259259  {
     
    262262    $this->StartEnabled();
    263263  }
    264  
     264
    265265  function StartAll()
    266266  {
    267267    $this->Perform($this->Modules, array(ModuleAction::Start));
    268268  }
    269  
     269
    270270  function StartEnabled()
    271271  {
     
    277277    $this->Perform($this->Modules, array(ModuleAction::Stop));
    278278  }
    279  
     279
    280280  function UninstallAll()
    281281  {
     
    283283    $this->SaveState();
    284284  }
    285  
     285
    286286  function ModulePresent($Name)
    287287  {
    288288    return(array_key_exists($Name, $this->Modules));
    289289  }
    290  
     290
    291291  /* @return Module */
    292292  function SearchModuleById($Id)
     
    299299    return('');
    300300  }
    301  
     301
    302302  function LoadState()
    303303  {
    304         $ConfigModules = array();
     304    $ConfigModules = array();
    305305    include($this->FileName);
    306306    foreach($ConfigModules as $Mod)
     
    312312        $this->Modules[$Mod['Name']]->Installed = $Mod['Installed'];
    313313        $this->Modules[$Mod['Name']]->InstalledVersion = $Mod['Version'];
    314       } 
    315     }
    316   }
    317  
     314      }
     315    }
     316  }
     317
    318318  function SaveState()
    319319  {
     
    321321    foreach($this->Modules as $Module)
    322322    {
    323       $Data[] = array('Name' => $Module->Name, 'Enabled' => $Module->Enabled, 
     323      $Data[] = array('Name' => $Module->Name, 'Enabled' => $Module->Enabled,
    324324        'Version' => $Module->Version, 'Installed' => $Module->Installed);
    325325    }
    326326    file_put_contents($this->FileName, "<?php \n\n\$ConfigModules = ".var_export($Data, true).";\n");
    327327  }
    328  
     328
    329329  function RegisterModule(AppModule $Module)
    330330  {
     
    333333    $Module->OnChange = &$this->OnModuleChange;
    334334  }
    335  
     335
    336336  function UnregisterModule(AppModule $Module)
    337337  {
    338338    unset($this->Modules[array_search($Module, $this->Modules)]);
    339339  }
    340  
     340
    341341  function LoadModulesFromDir($Directory)
    342342  {
    343         $List = scandir($Directory);     
     343    $List = scandir($Directory);
    344344    foreach($List as $Item)
    345345    {
     
    352352    }
    353353  }
    354  
     354
    355355  function LoadModules()
    356356  {
    357         if(method_exists($this->OnLoadModules[0], $this->OnLoadModules[1]))
     357    if(method_exists($this->OnLoadModules[0], $this->OnLoadModules[1]))
    358358      $this->OnLoadModules();
    359359    else $this->LoadModulesFromDir(dirname(__FILE__).'/../Modules');
Note: See TracChangeset for help on using the changeset viewer.