コード例 #1
0
 /**
  * @param string $path original source file path
  * @return resource
  * @throws LogicException
  */
 public static function patch($path)
 {
     if (!is_readable($path)) {
         throw new LogicException("Can't read '{$path}'");
     }
     // Check cache file
     if ($cache_file = Cache::getValidSrcCachePath($path)) {
         self::log('cache_hit: ' . $path);
         return fopen($cache_file, 'r');
     }
     self::log('cache_miss: ' . $path);
     $source = file_get_contents($path);
     list($new_source, $patched) = self::execPatchers($source);
     // Write to cache file
     self::log('write_cache: ' . $path);
     Cache::writeSrcCacheFile($path, $new_source);
     $resource = fopen('php://memory', 'rb+');
     fwrite($resource, $new_source);
     rewind($resource);
     return $resource;
 }