Exemplo n.º 1
0
 /**
  * Given a disk path to the modules, instantiate all installed modules and keep track of all uninstalled (installable) modules. 
  *
  * @param string $path 
  *
  */
 protected function load($path)
 {
     static $installed = array();
     $database = $this->wire('database');
     if (!count($installed)) {
         $query = $database->prepare("SELECT id, class, flags, data FROM modules ORDER BY class");
         // QA
         $query->execute();
         while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
             if ($row['flags'] & self::flagsAutoload) {
                 // preload config data for autoload modules since we'll need it again very soon
                 $this->configData[$row['id']] = wireDecodeJSON($row['data']);
             }
             unset($row['data']);
             $installed[$row['class']] = $row;
         }
         $query->closeCursor();
     }
     $files = $this->findModuleFiles($path, true);
     foreach ($files as $pathname) {
         $pathname = $path . $pathname;
         $dirname = dirname($pathname);
         $filename = basename($pathname);
         $basename = basename($filename, '.php');
         $basename = basename($basename, '.module');
         // if the filename doesn't end with .module, then stop and move onto the next
         if (!strpos($filename, '.module') || substr($filename, -7) !== '.module' && substr($filename, -11) !== '.module.php') {
             continue;
         }
         //  if the filename doesn't start with the requested path, then continue
         if (strpos($pathname, $path) !== 0) {
             continue;
         }
         // if the file isn't there, it was probably uninstalled, so ignore it
         if (!is_file($pathname)) {
             continue;
         }
         // if the module isn't installed, then stop and move on to next
         if (!array_key_exists($basename, $installed)) {
             $this->installable[$basename] = $pathname;
             continue;
         }
         $info = $installed[$basename];
         $this->setConfigPaths($basename, $dirname);
         if ($info['flags'] & self::flagsAutoload) {
             // this is an Autoload mdoule.
             // include the module and instantiate it but don't init() it,
             // because it will be done by Modules::init()
             include_once $pathname;
             $moduleInfo = call_user_func(array($basename, 'getModuleInfo'));
             // if not defined in getModuleInfo, then we'll accept the database flag as enough proof
             // since the module may have defined it via an isAutoload() function
             if (!isset($moduleInfo['autoload'])) {
                 $moduleInfo['autoload'] = true;
             }
             $autoload = $moduleInfo['autoload'];
             // check for conditional autoload
             if (!is_bool($autoload) && (is_string($autoload) || is_callable($autoload))) {
                 // anonymous function or selector string
                 $this->conditionalAutoloadModules[$basename] = $autoload;
                 $this->moduleIDs[$basename] = $info['id'];
                 continue;
             } else {
                 if ($autoload) {
                     $module = new $basename();
                 } else {
                     continue;
                 }
             }
         } else {
             // placeholder for a module, which is not yet included and instantiated
             $module = new ModulePlaceholder();
             $module->setClass($basename);
             $module->singular = $info['flags'] & self::flagsSingular;
             $module->file = $pathname;
         }
         $this->moduleIDs[$basename] = $info['id'];
         $this->set($basename, $module);
     }
 }
Exemplo n.º 2
0
 /**
  * Given a disk path to the modules, instantiate all installed modules and keep track of all uninstalled (installable) modules. 
  *
  * @param string $path 
  *
  */
 protected function load($path)
 {
     static $installed = array();
     if (!count($installed)) {
         $result = $this->fuel('db')->query("SELECT id, class, flags FROM modules ORDER BY class");
         while ($row = $result->fetch_assoc()) {
             $installed[$row['class']] = $row;
         }
         $result->free();
     }
     $files = $this->findModuleFiles($path, true);
     foreach ($files as $pathname) {
         $pathname = $path . $pathname;
         $dirname = dirname($pathname);
         $filename = basename($pathname);
         $basename = basename($filename, '.module');
         // if the filename doesn't end with .module, then stop and move onto the next
         if (!strpos($filename, '.module') || substr($filename, -7) !== '.module') {
             continue;
         }
         //  if the filename doesn't start with the requested path, then continue
         if (strpos($pathname, $path) !== 0) {
             continue;
         }
         // if the file isn't there, it was probably uninstalled, so ignore it
         if (!is_file($pathname)) {
             continue;
         }
         // if the module isn't installed, then stop and move on to next
         if (!array_key_exists($basename, $installed)) {
             $this->installable[$basename] = $pathname;
             continue;
         }
         $info = $installed[$basename];
         $this->setConfigPaths($basename, $dirname);
         if ($info['flags'] & self::flagsAutoload) {
             // this is an Autoload mdoule.
             // include the module and instantiate it but don't init() it,
             // because it will be done by Modules::init()
             include_once $pathname;
             $module = new $basename();
         } else {
             // placeholder for a module, which is not yet included and instantiated
             $module = new ModulePlaceholder();
             $module->setClass($basename);
             $module->singular = $info['flags'] & self::flagsSingular;
             $module->file = $pathname;
         }
         $this->moduleIDs[$basename] = $info['id'];
         $this->set($basename, $module);
     }
 }
Exemplo n.º 3
0
 /**
  * Return a new ModulePlaceholder for the given className
  * 
  * @param string $className Module class this placeholder will stand in for
  * @param string $file Full path and filename of $className
  * @param bool $singular Is the module a singular module?
  * @param bool $autoload Is the module an autoload module?
  * @return ModulePlaceholder
  *
  */
 protected function newModulePlaceholder($className, $file, $singular, $autoload)
 {
     $module = new ModulePlaceholder();
     $module->setClass($className);
     $module->singular = $singular;
     $module->autoload = $autoload;
     $module->file = $file;
     return $module;
 }