get_contents() static public method

static public get_contents ( string $filepath ) : boolean
$filepath string
return boolean
Ejemplo n.º 1
0
 /**
  * Update the RECENT_COMMIT constant for WPLib or the App Class.
  *
  * The update does not affect the current value for RECENT_COMMIT until next page load.
  *
  * @param string $class_name
  */
 private static function _maybe_update_class($class_name)
 {
     $recent_commit = self::get_recent_commit($class_name, $defined);
     $not_exists = !$defined || is_null($recent_commit);
     $loaded_commit = self::load_recent_commit($class_name);
     if ($not_exists || !is_null($loaded_commit) && $recent_commit !== $loaded_commit) {
         $reflector = new ReflectionClass($class_name);
         $source_file = $reflector->getFileName();
         $source_code = WPLib::get_contents($source_file);
         $source_size = strlen($source_code);
         if (preg_match("#const\\s+RECENT_COMMIT#", $source_code)) {
             $marker = "const\\s+RECENT_COMMIT\\s*=\\s*'[^']*'\\s*;\\s*(//.*)?\\s*\n";
             $replacer = "const RECENT_COMMIT = '{$loaded_commit}'; \$1\n\n";
         } else {
             $marker = "class\\s+{$class_name}\\s+(extends\\s+\\w+)?\\s*\\{\\s*\n";
             $replacer = "\$0\tconst RECENT_COMMIT = '{$loaded_commit}';\n\n";
         }
         $new_code = preg_replace("#{$marker}#", $replacer, $source_code);
         if ($new_code && strlen($new_code) >= $source_size) {
             WPLib::put_contents($source_file, $new_code);
         }
     }
 }