All Data Structures Namespaces Files Functions Variables
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 | $context | Load 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.

{
$this->context = $context;
$modulesRoot = $context->router->modulesPath;
$modules = \Entity\Module::getActivated();
$ids = array();
foreach ($modules as $i)
{
$modulePath = "{$modulesRoot}{$i->directory}/main.php";
if (file_exists($modulePath) && $this->loadModule($modulePath, $i))
{
$ids[] = $i->id;
}
else
{
$i->active = false;
$i->save();
}
}
$context->hookManager->loadHooks(\Entity\ModuleHook::getModules($ids));
}
Tools\ModuleManager\$context
$context
Definition: ModuleManager.php:16
Entity\Module\getActivated
static getActivated()
Definition: Module.php:22
Entity
Definition: Address.php:3
Tools\ModuleManager\loadModule
loadModule($path, $module)
Definition: ModuleManager.php:88
Tools\ModuleManager\$modules
$modules
Definition: ModuleManager.php:24

## Member Function Documentation

__get | ( |  | $key | ) |

Getter

Definition at line 173 of file ModuleManager.php.

{
switch ($key)
{
case "modules":
return $this->modules; break;
}
if (substr($key, 0, 4) == "_id_")
return $this->getModuleFromId((int) substr($key, 4));
throw new \Exception("Cannot access attribute {$key}");
}
Tools\ModuleManager\getModuleFromId
getModuleFromId($id)
Definition: ModuleManager.php:154
Tools\ModuleManager\$modules
$modules
Definition: ModuleManager.php:24

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.

{
foreach ($this->modules as $i)
{
if ($i->entity->id == $id)
return $i;
}
return FALSE;
}

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.

{
$entity = new \Entity\Module();
$entity->name = $modulename;
$entity->directory = $modulename;
$entity->active = true;
$module = $this->loadModuleFile($this->context->router->modulesPath.$modulename.'/main.php');
if ($module === false)
return false;
$module->setEntity($entity);
$entity->name = $module->getName();
$entity->description = $module->getDescription();
$entity->save();
self::$installing = true;
if ($module->install() == false)
{
self::$installing = false;
$hooks = \Entity\ModuleHook::getModules($entity->id);
foreach ($hooks as $i)
$i->delete();
$entity->delete();
return false;
}
self::$installing = false;
return $module;
}
Entity\ModuleHook\getModules
static getModules($moduleIds)
Definition: ModuleHook.php:23
Tools\ModuleManager\loadModuleFile
loadModuleFile($path)
Definition: ModuleManager.php:69

static isInstalling | ( |  | ) |

static

Returns
  true if a module is currently installing

Definition at line 167 of file ModuleManager.php.

{ return self::$installing; }

listAvailableModules | ( |  | ) |

Definition at line 135 of file ModuleManager.php.

{
$modulesRoot = $context->router->modulesPath;
$result = array();
$modules = scandir($modulesRoot, SCANDIR_SORT_NONE);
foreach ($modules as $i)
{
$path = $modulesRoot.$i;
if ($i == '.' || $i == '..' || !is_dir($path))
continue;
$this->loadModule($path);
}
}
Tools\ModuleManager\$context
$context
Definition: ModuleManager.php:16
Tools\ModuleManager\loadModule
loadModule($path, $module)
Definition: ModuleManager.php:88
Tools\ModuleManager\$modules
$modules
Definition: ModuleManager.php:24

loadModule | ( |  | $path,
|  |  | $module
| ) |  |

private

Parameters

  string | $path | path to module's main file
  \Entity\Module | $module | module'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.

{
$mod = $this->loadModuleFile($path);
if ($mod === false)
return false;
$mod->setEntity($module);
$this->modules[] = $mod;
return true;
}
Tools\ModuleManager\loadModuleFile
loadModuleFile($path)
Definition: ModuleManager.php:69

loadModuleFile | ( |  | $path | ) |

private

Parameters

  string | $path |

Returns
  loaded module (or false on error)

Definition at line 69 of file ModuleManager.php.

{
$mod = include_once($path);
if (!$mod || !($mod instanceof \Tools\AModule))
return false;
$mod->setContext($this->context);
return $mod;
}
Tools
Definition: AController.php:3

## 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:

- core/tools/ModuleManager.php