Esempio n. 1
0
 /**
  * Initializes library with JSON file at $path.
  */
 public static function init($path)
 {
     // ensure library is not already initialized
     if (isset(self::$config)) {
         trigger_error("CS50 Library is already initialized", E_USER_ERROR);
     }
     // ensure configuration file exists
     if (!is_file($path)) {
         trigger_error("Could not find {$path}", E_USER_ERROR);
     }
     // read contents of configuration file
     $contents = file_get_contents($path);
     if ($contents === false) {
         trigger_error("Could not read {$path}", E_USER_ERROR);
     }
     // decode contents of configuration file
     $config = json_decode($contents, true);
     if (is_null($config)) {
         trigger_error("Could not decode {$path}", E_USER_ERROR);
     }
     // store configuration
     self::$config = $config;
 }