ecom
E-commerce cms
 All Data Structures Namespaces Files Functions Variables
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
ModuleManager Class Reference

Public Member Functions

 __construct (&$context)
 
 install ($modulename)
 
 listAvailableModules ()
 
 getModuleFromId ($id)
 
 __get ($key)
 

Static Public Member Functions

static isInstalling ()
 

Private Member Functions

 loadModuleFile ($path)
 
 loadModule ($path, $module)
 

Private Attributes

 $context
 
 $modules = array()
 

Static Private Attributes

static $installing = false
 

Detailed Description

Container all modules. Allow module managment

Definition at line 9 of file ModuleManager.php.

Constructor & Destructor Documentation

__construct ( $context)
Parameters
\Tool\Context$contextLoad all active modules from database. Enable hooks for these modules Disable them if the module cannot be loaded

Definition at line 43 of file ModuleManager.php.

44  {
45  $this->context = $context;
46  $modulesRoot = $context->router->modulesPath;
48  $ids = array();
49  foreach ($modules as $i)
50  {
51  $modulePath = "{$modulesRoot}{$i->directory}/main.php";
52  if (file_exists($modulePath) && $this->loadModule($modulePath, $i))
53  {
54  $ids[] = $i->id;
55  }
56  else
57  {
58  $i->active = false;
59  $i->save();
60  }
61  }
62  $context->hookManager->loadHooks(\Entity\ModuleHook::getModules($ids));
63  }
static getActivated()
Definition: Module.php:22
loadModule($path, $module)

Member Function Documentation

__get (   $key)

Getter

Definition at line 173 of file ModuleManager.php.

174  {
175  switch ($key)
176  {
177  case "modules":
178  return $this->modules; break;
179  }
180  if (substr($key, 0, 4) == "_id_")
181  return $this->getModuleFromId((int) substr($key, 4));
182  throw new \Exception("Cannot access attribute {$key}");
183  }
getModuleFromId (   $id)
Parameters
int$id
Returns
AModule on success, FALSE on failure (no such ID / module not loaded) Get the module identified with id ID

Definition at line 154 of file ModuleManager.php.

155  {
156  foreach ($this->modules as $i)
157  {
158  if ($i->entity->id == $id)
159  return $i;
160  }
161  return FALSE;
162  }
install (   $modulename)
Parameters
string$modulename
Returns
|false on failure Install the module located in {modulePath}/modulename/modulename.php

Definition at line 103 of file ModuleManager.php.

104  {
105  $entity = new \Entity\Module();
106  $entity->name = $modulename;
107  $entity->directory = $modulename;
108  $entity->active = true;
109  $module = $this->loadModuleFile($this->context->router->modulesPath.$modulename.'/main.php');
110  if ($module === false)
111  return false;
112  $module->setEntity($entity);
113  $entity->name = $module->getName();
114  $entity->description = $module->getDescription();
115  $entity->save();
116  self::$installing = true;
117  if ($module->install() == false)
118  {
119  self::$installing = false;
120  $hooks = \Entity\ModuleHook::getModules($entity->id);
121  foreach ($hooks as $i)
122  $i->delete();
123  $entity->delete();
124  return false;
125  }
126  self::$installing = false;
127  return $module;
128  }
static getModules($moduleIds)
Definition: ModuleHook.php:23
static isInstalling ( )
static
Returns
true if a module is currently installing

Definition at line 167 of file ModuleManager.php.

168  { return self::$installing; }
listAvailableModules ( )

Definition at line 135 of file ModuleManager.php.

136  {
137  $modulesRoot = $context->router->modulesPath;
138  $result = array();
139  $modules = scandir($modulesRoot, SCANDIR_SORT_NONE);
140  foreach ($modules as $i)
141  {
142  $path = $modulesRoot.$i;
143  if ($i == '.' || $i == '..' || !is_dir($path))
144  continue;
145  $this->loadModule($path);
146  }
147  }
loadModule($path, $module)
loadModule (   $path,
  $module 
)
private
Parameters
string$pathpath to module's main file
\Entity\Module$modulemodule's database object to load /core/models/Module.php
Returns
TRUE on success Will try to load module located at $path. This function will include the main.php file located in the module's directory The file MUST return an AModule object to be considered as successfull /core/tools/AModule.php

Definition at line 88 of file ModuleManager.php.

89  {
90  $mod = $this->loadModuleFile($path);
91  if ($mod === false)
92  return false;
93  $mod->setEntity($module);
94  $this->modules[] = $mod;
95  return true;
96  }
loadModuleFile (   $path)
private
Parameters
string$path
Returns
loaded module (or false on error)

Definition at line 69 of file ModuleManager.php.

70  {
71  $mod = include_once($path);
72  if (!$mod || !($mod instanceof \Tools\AModule))
73  return false;
74  $mod->setContext($this->context);
75  return $mod;
76  }

Field Documentation

Tools Context $context
private

/core/tools/Context.php Contains website's informations

Definition at line 16 of file ModuleManager.php.

$installing = false
staticprivate

Definition at line 29 of file ModuleManager.php.

$modules = array()
private

Definition at line 24 of file ModuleManager.php.


The documentation for this class was generated from the following file: