Esempio n. 1
0
 /**
  * Initialize the extension manager by loading extensions in EXTENSIONS_PATH.
  *
  * A valid extension is a directory containing metadata.json and
  * extension.php files.
  * metadata.json is a JSON structure where the only required fields are
  * `name` and `entry_point`.
  * extension.php should contain at least a class named <name>Extension where
  * <name> must match with the entry point in metadata.json. This class must
  * inherit from Minz_Extension class.
  */
 public static function init()
 {
     $list_potential_extensions = array_values(array_diff(scandir(EXTENSIONS_PATH), array('..', '.')));
     $system_conf = Minz_Configuration::get('system');
     self::$ext_auto_enabled = $system_conf->extensions_enabled;
     foreach ($list_potential_extensions as $ext_dir) {
         $ext_pathname = EXTENSIONS_PATH . '/' . $ext_dir;
         if (!is_dir($ext_pathname)) {
             continue;
         }
         $metadata_filename = $ext_pathname . '/' . self::$ext_metaname;
         // Try to load metadata file.
         if (!file_exists($metadata_filename)) {
             // No metadata file? Invalid!
             continue;
         }
         $meta_raw_content = file_get_contents($metadata_filename);
         $meta_json = json_decode($meta_raw_content, true);
         if (!$meta_json || !self::isValidMetadata($meta_json)) {
             // metadata.json is not a json file? Invalid!
             // or metadata.json is invalid (no required information), invalid!
             Minz_Log::warning('`' . $metadata_filename . '` is not a valid metadata file');
             continue;
         }
         $meta_json['path'] = $ext_pathname;
         // Try to load extension itself
         $extension = self::load($meta_json);
         if (!is_null($extension)) {
             self::register($extension);
         }
     }
 }