Ejemplo n.º 1
0
 /**
  * Helper function which transforms a raw schema database (either already parsed or
  * based on a URL to a schemadb) into a list of schema class instances.
  *
  * @param mixed $raw_db Either an already created raw schema array, or a midcom_helper_misc::get_snippet_content
  *     compatible URL to a snippet / file from which the db should be loaded or schemadb contents as a string.
  * @return Array An array of midcom_helper_datamanager2_schema class instances.
  * @see midcom_helper_misc::get_snippet_content()
  */
 public static function load_database($raw_db)
 {
     static $loaded_dbs = array();
     $path = null;
     if (is_string($raw_db)) {
         // Determine if the given string is a path - assume that a path
         // doesn't have line breaks
         if (preg_match('/\\n/', $raw_db)) {
             $raw_db = midcom_helper_misc::parse_config($raw_db);
         } else {
             $path = $raw_db;
             if (!array_key_exists($path, $loaded_dbs)) {
                 $data = midcom_helper_misc::get_snippet_content($raw_db);
                 $loaded_dbs[$path] = midcom_helper_misc::parse_config($data);
             }
             $raw_db = $loaded_dbs[$path];
         }
     }
     if (!is_array($raw_db)) {
         throw new midcom_error("Provided DM2 schema is not in Array format.");
     }
     $schemadb = array();
     foreach ($raw_db as $name => $raw_schema) {
         $schemadb[$name] = new midcom_helper_datamanager2_schema($raw_db, $name, $path);
     }
     return $schemadb;
 }
Ejemplo n.º 2
0
 public function import()
 {
     // Generate a safe name for the structure
     $structure_name = midcom_helper_misc::generate_urlname_from_string(midcom::get()->get_page_prefix());
     $path = "{$this->root_dir}{$structure_name}.inc";
     if (!file_exists($path)) {
         throw new midcom_error("Structure file {$path} not found");
     }
     $structuredata = file_get_contents($path);
     $structure = midcom_helper_misc::parse_config($structuredata);
     if (!is_array($structure) || !isset($structure[$structure_name]) || !isset($structure[$structure_name]['root'])) {
         throw new midcom_error("Invalid structure file {$path}");
     }
     $this->read_structure($structure[$structure_name]['root']);
 }
Ejemplo n.º 3
0
 /**
  * This helper function reads a snippet and evaluates its content as array.
  * This is essentially a simple Array($data\n) eval construct.
  *
  * If the snippet does not exist, false is returned.
  *
  * This function may be called statically.
  *
  * @param string $snippetpath The full path to the snippet that should be returned.
  * @return Array The read data or false on failure.
  * @see read_array_from_file()
  */
 public static function read_array_from_snippet($snippetpath)
 {
     $code = midcom_helper_misc::get_snippet_content_graceful($snippetpath);
     return midcom_helper_misc::parse_config($code);
 }