/**
  * @param string $path original source file path
  * @return resource
  * @throws LogicException
  */
 public static function patch($path)
 {
     if (Cache::getCacheDir() === null) {
         throw new LogicException("You have to set 'cache_dir'");
     }
     if (!is_readable($path)) {
         throw new LogicException("Can't read '{$path}'");
     }
     // Check cache file
     if (Cache::hasValidSrcCache($path)) {
         self::log('cache_hit: ' . $path);
         return fopen(Cache::getSrcCacheFilePath($path), '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;
 }