Beispiel #1
0
    function copyFile($source, $dest, $hash=false, $mode=0644) {
        $contents = $this->getEditedContents($source);
        if ($contents === false)
            // Regular file
            return parent::copyFile($source, $dest, $hash, $mode);

        if (!file_put_contents($dest, $contents))
            $this->fail($dest.": Unable to apply rewrite rules");

        $this->updateManifest($source, $hash);
        return chmod($dest, $mode);
    }
Beispiel #2
0
 function copyFile($src, $dest)
 {
     static $short = false;
     static $version = false;
     if (substr($src, -4) != '.php') {
         return parent::copyFile($src, $dest);
     }
     if (!$short) {
         $hash = exec('git rev-parse HEAD');
         $short = substr($hash, 0, 7);
     }
     if (!$version) {
         $version = exec('git describe');
     }
     if (!$short || !$version) {
         return parent::copyFile($src, $dest);
     }
     $source = file_get_contents($src);
     $source = preg_replace(':<script(.*) src="([^"]+)\\.js"></script>:', '<script$1 src="$2.js?' . $short . '"></script>', $source);
     $source = preg_replace(':<link(.*) href="([^"]+)\\.css"([^/>]*)/?>:', '<link$1 href="$2.css?' . $short . '"$3/>', $source);
     // Set THIS_VERSION
     $source = preg_replace("/^(\\s*)define\\s*\\(\\s*'THIS_VERSION'.*\$/m", "\$1define('THIS_VERSION', '" . $version . "'); // Set by installer", $source);
     // Set GIT_VERSION
     $source = preg_replace("/^(\\s*)define\\s*\\(\\s*'GIT_VERSION'.*\$/m", "\$1define('GIT_VERSION', '" . $short . "'); // Set by installer", $source);
     // Disable error display
     $source = preg_replace("/^(\\s*)ini_set\\s*\\(\\s*'(display_errors|display_startup_errors)'.*\$/m", "\$1ini_set('\$2', '0'); // Set by installer", $source);
     if (!file_put_contents($dest, $source)) {
         die("Unable to apply rewrite rules to " . $dest);
     }
     return true;
 }