Example #1
0
File: Router.php Project: fem/spof
 /**
  * This function generates the htaccess ruleset based on the preset and the generated routes defined in the source
  * file. Generation is only done if relevant files got changed.
  *
  * @internal
  */
 public static function updateHtaccess()
 {
     $target = self::getTargetFile();
     $preset = self::getPresetFile();
     // check if rulesset is outdated, before updating it
     if (file_exists($target)) {
         $target_time = filemtime($target);
         if (filemtime($preset) < $target_time && filemtime(__FILE__) < $target_time) {
             return;
         }
     }
     try {
         $rules = fopen($target, 'w+');
     } catch (\ErrorException $e) {
         Application::death(_("Failed to generic access rules. Missing directory permissions?"));
     }
     ob_start();
     /** @noinspection PhpIncludeInspection */
     require $preset;
     fwrite($rules, ob_get_clean());
     fclose($rules);
     error_log('@@' . Config::getDetail('router', 'file_perms', self::$defaultConfig));
     chmod($target, Config::getDetail('router', 'file_perms', self::$defaultConfig));
 }